View previous topic :: View next topic |
Author |
Message |
feitanx
Joined: 21 Mar 2010 Posts: 37
|
NO OUTPUT |
Posted: Wed May 26, 2010 9:47 pm |
|
|
When I use a voltage reference for the PIC16F877A adc, there is no output. what's wrong? where's the problem. I use a 100 ms delay. |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Wed May 26, 2010 10:30 pm |
|
|
More info needed.
What exactly do you mean by 'no output'? Is there no ADC conversion? Does the processor hang? And how have you come to the conclusion that there is a problem (ie, how are you tracing the problem)?
Rohit |
|
|
feitanx
Joined: 21 Mar 2010 Posts: 37
|
|
Posted: Thu May 27, 2010 12:32 am |
|
|
I mean I try to output the result on portd through LED but there is no output |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Thu May 27, 2010 12:35 am |
|
|
Do you get an output without using the reference (ie, if you do a simple ADC conversion and dump out an 8bit value to PORTD)?
Post your code.
Rohit |
|
|
feitanx
Joined: 21 Mar 2010 Posts: 37
|
|
Posted: Thu May 27, 2010 1:41 am |
|
|
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOCPD,NOBROWNOUT
#device *=16 ADC=8
#use delay(clock=4000000)
#use rs232(uart1,baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N,BITS=8,STOP=1)
#use STANDARD_IO(D)
#use STANDARD_IO(A)
#use STANDARD_IO(C)
#bit ADFM_BIT = 0x9F.7
void main(void){
int8 V,V1;
V=0;
setup_adc_ports(A_ANALOG_RA3_REF);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
for(V=1;V<=20;V++)
{
V+=read_adc();
delay_ms(500);
}
V1=V/20;
output_d(V1);
} |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19505
|
|
Posted: Thu May 27, 2010 1:57 am |
|
|
You do realise that you need to have a reference voltage fed 'in' to RA3?.
You then have 'V', which is your loop counter, and you add the value from the ADC to this. If the ADC value is over 20, you will drop out on the very first loop...
Then there is a problem with the addition. The adc, returns a value from 0 to 255. If this was being summed correctly, you woulod be adding these 20 values (0 to 5100 for the total), in a variable than can store 255 _max_....
You need something like:
Code: |
void main(void){ //Note the use of the 'code' buttons....
int8 ctr,V1;
int16 total; //variable big enough to hold the total
setup_adc_ports(A_ANALOG_RA3_REF);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel(0);
while (TRUE) {
total=0;
for(ctr=1;ctr<=20;ctr++) {//use variable names that reflect use...
total+=read_adc();
delay_ms(500);
}
V1=total/20;
output_d(V1);
} //Loop otherwise the code will only run once
}
|
Best Wishes |
|
|
|