hi....
i have problem in reading ADC ....i m using pic 16f877a and compiler HITECH ANSI C compiler..i m reading 10 bit adc and dividing it by a value so that it can be loaded into the CCPR1L register and corresponding pulses are generated for converter...any one who knw about it plz tell me what is wrong in my code..
this is my coding..PWM frequency is 10kHz, oscillator freq = 8MHZ and assigned left justification
#include<htc.h>
#include<stdio.h>
#include<math.h>
__CONFIG(0x3f72);
void PWM(unsigned int duty);
unsigned int ADCread(unsigned char);
unsigned int i;
void main()
{
unsigned int r,d;
TRISA =0x0F;
ADCON0=0X41;
//ADCON1=0X44;
r=ADCread(1);
d=r/0b1010101;
PWM(d);
}
unsigned int ADCread(unsigned char channel)
{
unsigned int lb,hb,adr;
CMCON=7;
ADCON0=0X41;
ADCON1=0X44;
for(i=0;i<200;i++);
GODONE=1;
while(GODONE==1);
hb=ADRESH;
lb=ADRESL;
adr=(hb<<2)|lb;
PORTB=ADRESL;
return adr;
}
void PWM(unsigned int duty)
{
TRISC1=0;
TRISC2=0;
PORTC=0X00;
CCP1CON=0X0C;
CCP2CON=0X0C;
PR2=12;
T2CON=0X03;
TMR2=0x00;
TMR2ON=1;
while(1)
{
for (i=1;i<200;i++);
CCPR1L=duty;
CCPR2L=duty;
for (i=1;i<200;i++);
}
}
i tried what all u mentioned ..... getting same problem..i m getting same output at the ccp1 pin even if i didnt give analog signal ....can anyone plz tell what is basic and simple adc code that working for 16f877a in HITECh ansi c complier???
s.... i also tried by replacing the r = ADCRead(0) with the r = 0b11111111...in that program i m getting pulses..hope there is no problem in PWM...Is there anything that have to corrected in basics..