View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 07, 2007 2:38 pm |
|
|
Your complaint is that you believe the ADC is not working.
One method to trouble-shoot this problem is to make a simple test
program that only tests the ADC.
I made the test program shown below and kept the settings the same
as in your program, such as an 8-bit ADC result and 4 MHz internal osc.
I tested it on a PicDem2-Plus board with PCM vs. 4.040. That board
is setup for a serial port on pins C6 and C7, so I jumpered over the
connections to pins B5 and B2 so it would work with a 16F88. As I
turned the trimpot on pin A0 from one side to the other, I got this
output, which is correct:
Quote: | 00 00 00 00 22 48 72 A1 FD FF FF FF FF |
Code: |
#include <16F88.h>
#device adc=8
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B5, rcv=PIN_B2, ERRORS)
//=================================
void main()
{
int8 result;
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
while(1)
{
result = read_adc();
printf("%X ", result);
delay_ms(500);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Thu Jun 07, 2007 3:13 pm |
|
|
your code won't compile with this extra brace.
Code: |
void main()
{
setup_adc_ports(sAN0|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_adc_channel( 0 );
set_tris_a(0b00000001);
set_tris_b(0b00000000);
Delay_ms(3000);
Init();
} <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
while(true){
Delay_ms(5000);
rssi_value[0] = adc_conversion(value);
RSSI_tenth = rssi_value[0]/10;
for (dX=0; dX<RSSI_tenth; dX++){
Beep();
Delay_ms(500);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
|
Posted: Thu Jun 07, 2007 4:22 pm |
|
|
Thank you. I stripped out the unnecessary routines from the code I posted, that's how the extra brace by mistake remained there.
I did not assume that the ADC is not working, I merely speculated over the response I've got.
If I feed the ADC with Vdd, than I should get a maximum value - I guess as a response - in case of an 8 bit = 256 or I believe this is 10 bit = 1024. Now 254 divided by 10 is 25.4, I should have heard 25 beeps - or 102 beeps...
I will try your simple program, since I do not have any debugging tools yet I have to use the beeper to count the values.
Thanks and I will report back later on the progress.
Ox. |
|
![](templates/subSilver/images/spacer.gif) |
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Fri Jun 08, 2007 6:58 am |
|
|
You might be able to send some messages out a software UART to hyperterminal as way of debugging, or if you are just trying to debug the ADC you can use the hardware UART. |
|
![](templates/subSilver/images/spacer.gif) |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
|
Posted: Fri Jun 08, 2007 11:03 pm |
|
|
Thank you, I resolved the problem. Today I received my sample shipment from Microchip containing a 16F688 - with this I built an serial LCD display and finally got around to resolve the problem.
It is much easier to troubleshoot if one can see the values of the variables. Anyway with all this, I was going nuts tonight because I thought I may be the only one the ADC is not working for... After several hours finally I decided to change ADC channels and try on a different channel - when I suddenly realized that all this time I had A0 set to analog, but I connected A1 in the test circuit.
Of course after I rewired the thing, it started working exactly as it suppose to.
Thanks for all the help.
Ox. |
|
![](templates/subSilver/images/spacer.gif) |
|