Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ADC generation using PIC16f72 microcontroller.

Status
Not open for further replies.

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,547
Hi,
Here is the code for ADC using 16f72.
Code:
/****************************************************************
1) RA3 is selected as input channel
2) Knob is connected to RA3 pin on kit, by varying it we can have ADC result which is displayed on PORTB.
3) GO/DONE bit must be set before monitoring it for going low.
******************************************************************/




void main() {
     unsigned int temp,i;
     //TRISA = 0xff;      //Set port A direction as i/p
     TRISA = 0x00;        //Port A as output
     PORTA = 0X00;        //ALL BITS OFF
     ADCON0 = 0X18;       //CLOCK SELECTION AND ANALOG CHANNEL SELECTION channel RA3 as input
     TRISB = 0x00;        //Set port B as output
     TRISC = 0x00;
     ADCON1 = 0X01;       //ALL CHANNELS AS ANALOG INPUT Vref is RA3
     //ADCON1 = 0x00;     //Vref is VDD
     TRISA3_bit = 0;      //Port A 0th bit as input
     TRISA2_bit = 0;
     TRISA1_bit = 1;
     TRISA0_bit = 1;

                PORTB = 0xFF;
                Delay_ms(1000);
                PORTB = 0x00;
                Delay_ms(1000);
                PORTC = 0x00;
                               while(1)

                               {
                                       ADRES = 0x00;
                                       ADCON0.ADON = 0x01;                 //Turn on the ADC
                                       ADCON0.GO = 1;
                                       //ADCON0 = ADCON0 & 0x04;
                                       //while((ADCON0 & 0x04)==1);    // Wait till conversion is going on
                                       while (ADCON0 == 0x04);
                                       //while(ADCON0.GO == 1);
                                       ADCON0 = 0x00;          // Stop the ADC
                                       // ADIF = 0;
                                       //temp = ADRES;
                                       PORTB = ADRES;
                                       //PORTA = ADRES;
                                       //PORTC = ADRES;
                                       Delay_us(2);    //Call delay 2 microseconds;
                               }

}
 

AbdulMoeez

Newbie level 6
Joined
Dec 29, 2010
Messages
14
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Location
Lahore,Pakistan
Activity points
1,352
If you study datasheet of pic16F72, they mentioned that only following adc configuration you can use. use cannot make only AN3 for adc use have to use following group configuration.

1- NO_ANALOGS 7 // None
2- ALL_ANALOG 0 // A0 A1 A2 A3 A5
3- AN0_AN1_AN2_AN4_VSS_VREF 1 // A0 A1 A2 A5 VRefh=A3
4- AN0_AN1_AN3 4 // A0 A1 A3
5- AN0_AN1_VSS_VREF 5 // A0 A1 VRefh=A3

- - - Updated - - -

ccs compiler code // tested code
***************************************************************************************
1) RA3 is selected as input channel
2) Knob is connected to RA3 pin on kit, by varying it we can have ADC result which is displayed on PORTB.
***************************************************************************************

#include <pic16f72.h>

#device adc=8

#FUSES NOWDT,NOBROWNOUT,NOLVP,HS,PUT

#use delay(clock=20000000)

unsigned int8 adc_value;

void main(){

set_tris_b(0x00);
set_tris_a(0xff);

setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_AN1_AN3);
set_adc_channel(3);
delay_ms(10);
while(1){
adc_value = read_adc();
output_b(adc_value);
delay_ms(2);
}

}
 

djc

Advanced Member level 1
Joined
Jan 27, 2013
Messages
402
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
India
Activity points
4,547
Hi,

Thanx for the suggestions sir. The program has been modified for other application using ADC. Though we have to use group of channels as input but we will get input for ADC on certain specific channel right? Correct me if I am wrong.

Thanking You

- - - Updated - - -

Hi,

Thanx for the suggestions sir. The program has been modified for other application using ADC. Though we have to use group of channels as input but we will get input for ADC on certain specific channel right? Correct me if I am wrong.

Thanking You
 

AbdulMoeez

Newbie level 6
Joined
Dec 29, 2010
Messages
14
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Location
Lahore,Pakistan
Activity points
1,352
yes, you are correct..... Though we have to use group of channels as input but we will get input for ADC on certain specific channel.....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top