CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC on 16F88

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 07, 2007 2:38 pm     Reply with quote

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);
  }

}
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Thu Jun 07, 2007 3:13 pm     Reply with quote

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);

   }
}
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Thu Jun 07, 2007 4:22 pm     Reply with quote

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.
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Fri Jun 08, 2007 6:58 am     Reply with quote

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.
oxxyfx



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

PostPosted: Fri Jun 08, 2007 11:03 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group