Continue to Site

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.

Can 16f877a be used here??? Please help !!!

Status
Not open for further replies.

nirajd

Junior Member level 1
Junior Member level 1
Joined
Jul 12, 2013
Messages
16
Helped
3
Reputation
6
Reaction score
3
Trophy points
3
Visit site
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!!


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:

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!!

It is certainly possible to utilize two of the multiplexed inputs of the ADC module to achieve the required outcome, however you are essentially implementing what is known as an analog comparator of which the PIC16F877A already offers two modules.

So why reinvent the wheel?

Reference: PIC16F87XA Datasheet, Section: 12.2 Comparator Operation, Page: 137
12.2 Comparator Operation

A single comparator is shown in Figure 12-2 along with
the relationship between the analog input levels and
the digital output. When the analog input at Vin+ is less
than the analog input Vin-, the output of the comparator
is a digital low level. When the analog input at Vin+ is
greater than the analog input Vin, the output of the
comparator is a digital high level. The shaded areas of
the output of the comparator in Figure 12-2 represent
the uncertainty due to input offsets and response time.

12.3 Comparator Reference
An external or internal reference signal may be used
depending on the comparator operating mode. The
analog signal present at Vin- is compared to the signal
at Vin+ and the digital output of the comparator is
adjusted accordingly (Figure 12-2).





The problem is i am not getting the required pulse!! I guess i have got a problem with the ADC conversion....

Without the ability to examine your entire code, particularly the PWM() routine and how it utilizes the output from the ADC and the errx values, it is difficult to offer a possible solution to the issue.

Also without knowing the actual resulting time delay from:

Code:
delay(1); //Acquisition Delay

The required Acquisition Time (Tad) may not have passed before the conversion process begins.

1. will pic16f877a do for me?

Yes, however external signal conditioning may or may not be required depending on the voltage levels being compared, their rate of change and possible noise.

2.do i need to simulataneously convert the two analog inputs via ADC???

Mostly likely no, the PIC16F877A has only one ADC module which is multiplexed between eight inputs, therefore a finite amount of time exists between each ADC conversion.

For many applications this is not an issue as there is also latency involved from the required processing of the obtained values.

Once again, the answer to this question depends largely on the rate of change or frequency of the input signal.


I would strong suggest studying the PIC16F877A datasheet concerning the Analog Comparators and attempt to use them in your application.

If you have any additional questions, please elaborate on the signal being compared and the PWM being generated, frequency, duty cycle, etc.


One more issue I would like to point out is avoid terminating main() and other routines such as ADCRead() with a semicolon, which doesn't belong, not required and is sure to create issues.

Code:
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; 
}[COLOR="#FF0000"];     -- Remove Semicolon and Recompile[/COLOR]

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();
}
}[COLOR="#FF0000"];     --Remove Semicolon and Recompile[/COLOR]


BigDog
 
  • Like
Reactions: andre_luis

    andre_luis

    Points: 2
    Helpful Answer Positive Rating
    V

    Points: 2
    Helpful Answer Positive Rating
It is certainly possible to utilize two of the multiplexed inputs of the ADC module to achieve the required outcome, however you are essentially implementing what is known as an analog comparator of which the PIC16F877A already offers two modules.

So why reinvent the wheel?
HELLO SIR, first of all i am new to edaboard!! so i m not acquainted with all the tools to be used here!!
thank you for the reply!! let me give a brief introduction to my project!! we have a lab generator and our task is to synchronize it with the bus bar! for this, we should acheive the terminal voltage of the generator equal to that of the bus bar!! i studied the analog comparator in the pic16f877a as u suggested, what i found is that C2out (output) is 1 if Vin+>Vin- or C2out is 0 if Vin+<Vin- (for a certain CMCON) but i didnt see any provision to compare if the two analog inputs are equal!! my job is to generate a pulse which will increse/decrease the excitation system of the lab generator and make its terminal voltage equal to that of the bus bar automatically!!! The pulse is to be generated by compairing the error from the two input analog signals!!! during simulation what i should get is as follows:
WHEN I INCREASE /DECREASE VARIABLE RESISTANCE TO ONE INPUT, THE DUTY CYCLE OF THE OUTPUT PULSE SHOULD INCREASE/DECREASE! the duty cycle should be proportional to the error obtained by comparing the two inputs!!!!! i appreciate your help in this!!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top