Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

mcp3202

Status
Not open for further replies.

miral

New Member
hi,
this is the my first message in forum.i want to measure 12-bit analog value using the mcp3202.it will communicate with 16f877a.how should be the configuration of 16f877a.it runs at 20 Mhz
best regards...
 
Hi,
First off, welcome! You haven't given too much to go on, unless you just need some pointers where to look.
You need to be more specific. Since you have a half decent subject line, I'll get you going in the direction you need to go to get started. However, there has been a rather good link provided as a response to the less detailed help requests, which I believe, will increase the quality of this forum, so I will provide that first. Be aware that it is directed at those with school projects, but I think it is real good info for anyone getting help:
http://www.geocities.com/pcbs4less/schoolprojecthelp.htm

Now the first thing you need to get, if you don't have them, are the data sheets for your micro, and your ADC.
In the 3202 data sheet, look at chapter 7, starting on page 22. 7.2 -That is what you need your PIC to do. If you don't know how to make your 877A do this, you can find that info in the 877A data sheet - 9.3, starting on page 71.

If you are running into difficulties when you try to do this, then be sure to give the relevant info on your development tools and hardware.

Best wishes
 
Last edited:
hi,
first excuse me for inefficient data.i use mikropascal ,i want to use 12 bit analog value and display it on 7segment 4 digit display.i use mcp3202 to measure analog value.
i use 16f877 at 20 Mhz.i use in master mode fosc/16,data sample end,serial clock idle high,transmit edge high to low.first i have configured this way.then 16f877 sent B00000001 for starting bit and then transmit 10100000 to configure mcp 3202 end at the end of this sequence 16f877 has read 2 byte.one is LSB the other one is MSB.although i have written my code with this way,16f877 has not read a value from the mcp 3202.
here is the my pascal code.
best regards.....


Code:
program sensor_analog;

var temp_res : word;
    buffer:byte;
    sayici:byte;
    hane1:byte;
    hane2:byte;
    analog_deger:array[0..1] of byte;
    deger_ptr:^word;


    digit_1   : longint;
    digit_2   : longint;
    digit_3   : longint;
    digit_4   : longint;
    yardimci1,yardimci2:longint;
    yardimci3,yardimci4,yardimci5,yardimci6:longint;
    basinc: longint;


begin

  deger_ptr:=@analog_deger;
  temp_res:=0;
  basinc:=0;
  adcon0 :=0 ;
  cmcon:=0x07;
  ADCON1:=0x0f;
  pie1.adie:=0;
  intcon:=0;
  trisa:=0;
  analog_deger[1]:=5;
  analog_deger[0]:=36;
  TRISB  := 0;
  TRISD  := 0;
  setbit(porta,0);
 Spi_Init_Advanced(master_osc_div4,DATA_SAMPLE_end,CLK_IDLE_low,high_2_low);

  while TRUE do
  begin
    clearbit(porta,0);

    spi_write(1);
    spi_write(%10100000);

    hane1:=spi_read(buffer);
    hane2:=spi_read(buffer);
     analog_deger[1]:=hane1;
     analog_deger[0]:=hane1;
     temp_res:=deger_ptr^;
     sspstat.bf:=0;
    setbit(porta,0);
    
    basinc:=(1600*temp_res)/4095;


    digit_1:=basinc/1000;
    yardimci1:=digit_1*1000;

    yardimci2:=basinc-yardimci1;
    digit_2:=yardimci2/100;

     yardimci3:=digit_2*100;
     yardimci4:=yardimci2-yardimci3;
     digit_3:=yardimci4/10;
     yardimci5:=digit_3*10;
     yardimci6:=yardimci1+yardimci3+yardimci5;
      digit_4:=basinc-yardimci6;






    portd:=%00001000;
    case digit_1 of
    0: portb:=0;
    1: portb:=0x06;
    2: portb:=0x5b;
    3: portb:=0x4f;
    4: portb:=0x66;
    5: portb:=0x6d;
    6: portb:=0x7d;
    7: portb:=0x07;
    8: portb:=0x7f;
    9: portb:=0x6f;
    end;
    delay_ms(1);
    portd:=0;
    portb:=0;

    delay_ms(1);


    portd:=%00000100;
    case digit_2 of
    0: portb:=191;
    1: portb:=134;
    2: portb:=219;
    3: portb:=207;
    4: portb:=230;
    5: portb:=237;
    6: portb:=253;
    7: portb:=135;
    8: portb:=255;
    9: portb:=239;
    end;
    delay_ms(1);
    portd:=0;
    portb:=0;

    delay_ms(1);

    portd:=%00000010;
    case digit_3 of
    0: portb:=0x3f;
    1: portb:=0x06;
    2: portb:=0x5b;
    3: portb:=0x4f;
    4: portb:=0x66;
    5: portb:=0x6d;
    6: portb:=0x7d;
    7: portb:=0x07;
    8: portb:=0x7f;
    9: portb:=0x6f;
    end;
    delay_ms(1);
    portb:=0;
    portd:=0;

    delay_ms(1);


    portd:=%00000001;
    case digit_4 of
    0: portb:=0x3f;
    1: portb:=0x06;
    2: portb:=0x5b;
    3: portb:=0x4f;
    4: portb:=0x66;
    5: portb:=0x6d;
    6: portb:=0x7d;
    7: portb:=0x07;
    8: portb:=0x7f;
    9: portb:=0x6f;
    end;
    delay_ms(1);
    portb:=0;
    portd:=0;

    delay_ms(10);
  end;
end.
 
Sorry if I made you feel badly, just that the info you have now given was necessary to get anything done.

First off, I haven't used PASCAL in many years, so it is taking me forever to read your source. Hopefully others will jump in here as well.

It looks as though you are using the PIC as an analog reference, is that the case? You are using hardware SPI, and multiplexing your digits on port D, right?

Can you just make your pic cycle through displaying the numbers on your 7-segments, without reading from the 3202? Or is there some other way you can read the contents of analog_deger[] like sending it to a pc by serial? The reason I'm asking is because it looks to me like there is a problem with the way you are displaying, rather than reading. Like I say, though, I'm not a PASCAL expert! My question comes from the following:
I wonder why you do this:
Code:
   digit_1:=basinc/1000;
    yardimci1:=digit_1*1000;
rather than just
Code:
   digit_1:=basinc/1000;
    yardimci1:=basinc;
You are dividing basinc by 1000 and assigning it to digit_1, then multiplying digit_1 by 1000 and assigning it to yardimci1, so why not just assign yardimci1 the value basinc?
Then you do this:
Code:
    yardimci2:=basinc-yardimci1;
    digit_2:=yardimci2/100;

It seems to me that yardimci2 will contain 0, so digit_2 gets 0 divided by 100?

Also, I wonder if you have made a request on the forums at Mikro:
https://www.mikroe.com/forum/viewforum.php?f=9&sid=bec034fb441f249809f7605167c75b8c

Best wishes
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top