nirajd
Junior Member level 1
- Joined
- Jul 12, 2013
- Messages
- 16
- Helped
- 3
- Reputation
- 6
- Reaction score
- 3
- Trophy points
- 3
- Activity points
- 154
hello everybody!! i need ur help!!! i want to take two analog inputs for ADC in pic16f877A!! out of them, one input ( lets say to AN1) acts as reference and the other input (lets say to AN0) is to be compared with that input reference value!! i have used the PWM technique through which if the ADC value from AN0 is less than the ADC value from AN1, then output pulse width increases!!! THe increase in output pulse width will be fed back to increase the same input until the two inputs become the same!! The problem is i am not getting the required pulse!! I guess i have got a problem with the ADC conversion.... i found a code in C language compiled by hitech compiler!! i made certain changes to the code and converted to hex file!! please help me!!
1. will pic16f877a do for me?
2.do i need to simulataneously convert the two analog inputs via ADC???
A part of my code is pasted herewith...please help!!
1. will pic16f877a do for me?
2.do i need to simulataneously convert the two analog inputs via ADC???
A part of my code is pasted herewith...please help!!
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 int err_0=0; int err_1=0; int err_2=0; unsigned int ADCRead(unsigned char channel) { unsigned int ADR; ADCON0 = 0x81|(channel << 3); //Change channel delay(1); //Acquisition Delay ADGO = 1; //Set GO_DONE bit to start conversion while (ADGO==1); //Wait for bit to be cleared ADR = (ADRESH<<8)|ADRESL; return ADR; }; void main(void) { unsigned int Ch0, Ch1; init_PWM(); // this is a call to the initialization of pwm fuction which i have already made! TRISC2 = 0; ADCON0 = 0x81; ADCON1 = 0x04; while (1){ Ch0 = ADCRead(0); //Gets reading from channel 0 Ch1 = ADCRead(1); //Gets reading from channel 1 err_0=err_1; err_1=err_2; err_2=Ch1-Ch0; //PLEASE FOCUS THIS LINE, I DOUBT HERE!! PWM(); } };
Last edited by a moderator: