CrazyEngineers
  • A/D Conversion PIC 16F

    agamb

    agamb

    @agamb-Cg0lI9
    Updated: Oct 25, 2024
    Views: 1.1K
    😕 Hi guys,
    For a project I am trying to implement the A/D converter on a PIC 16F877A by using it to read in 4 voltage values and convert them to their digital values but am having difficulties in understanding the operation of the A/D converter, I have been reading through the datasheet and also the reference manual. If anybody has any information or links to tutorials that would help it would be greatly appreciated.

    Thanks.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • shahrul

    MemberJan 26, 2010

    For program ADC, you need to setup ADCON0 and ADCON1 address. For read the channel, just use function
    int read_a2d(unsigned char channel)
    {ADCON0=0b00000001; //Turn on A/D module
    ADCON1=0b10000000; //configures analog and voltage reference pins
    ADCON0=(ADCON0&0xC7)|(channel<<3); //select analog input channel
    __delay_ms(2);
    ADGO=1; //initiate conversion on the selected channel
    while(ADGO==1) continue; //wait until conversion done
    return(256*ADRESH+ADRESL);}
    Full program, you can see here, #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
  • tejasgadaria

    MemberFeb 3, 2010

    sbit start_stop at ADCON0.B2;

    void Init_Adc()
    {
    ADCON0 = 0x81;
    ADCON1 = 0x80;
    TRISA = 0x01;
    }
    void delay()
    {
    int i;
    for(i=0;i<40000;i++) ;
    }
    void lcdcmd(unsigned char c)
    {
    PORTD =c;
    PORTB=0x10;
    delay();
    PORTB=0x00;
    }
    void lcddata(unsigned char c)
    {
    PORTD=c;
    PORTB=0x14;
    delay();
    PORTB=0x04;
    }

    void Lcd_Init()
    {
    lcdcmd(0x38);
    delay();
    lcdcmd(0x0C);
    delay();
    lcdcmd(0x06);
    delay();
    lcdcmd(0x01);
    delay();
    }

    void read_disp_adc()
    {
    int x,x2,x3,x4,x1;
    float b,a;
    int d1,d2,d3,d4,d5;

    unsigned char arr[20]="0123456789";

    x = ADRESL ;
    x2 = ADRESH;

    x1 = x;
    x3=(x2>>8);
    x4=x3|x;


    b=x4*5;
    a = b/255;

    d1 = (long)a;
    d1+=0x30;

    d2= a*10;
    d2%=10;
    d2+=0x30;

    d3= a*100;
    d3%=10;
    d3+=0x30;

    d4= a*1000;
    d4%=10;
    d4+=0x30;

    lcdcmd(0x80);
    lcddata(d1);
    delay();
    lcddata('.');
    delay();
    lcddata(d2);
    delay();
    lcddata(d3);
    delay();
    lcddata(d4);
    delay();
    }

    void main()
    {
    TRISB = 0x00;
    TRISD = 0x00;

    Init_Adc();
    Lcd_Init();

    while (1)
    {
    start_stop = 1;
    while (start_stop == 1);
    read_disp_adc();
    }
    }
    ;-) Enjoy.......!!
    Are you sure? This action cannot be undone.
    Cancel
  • sanks85

    MemberFeb 4, 2010

    hey gr8 work ....
    Are you sure? This action cannot be undone.
    Cancel
  • HEMSHAH

    MemberJun 8, 2011

    Hi,

    i am interested in a/d converter programming ,
    want 5 channel i/p (0-5v)
    and want o/p 30 channels.
    1 i/p channel converts to 6 digital o/p (0-5v => 6 channel )

    pls suggest which microcontroller to use and how
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register