View previous topic :: View next topic |
Author |
Message |
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
ADC is not working in PIC18F2431 |
Posted: Sat Sep 03, 2011 8:43 am |
|
|
hey guy ADC is not working in PIC18F2431 plzz help me
Code: |
#include<18F2431.h>
#device adc=10
#fuses NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=20MHz , crystal)
#define LED PIN_B7
unsigned int16 adc(void);
unsigned int16 adc_value;
void main()
{
set_tris_a (0xFF);
set_tris_b (0x00);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN0);
while(TRUE)
{
set_adc_channel(0);
delay_us(20);
adc_value = adc();
if(adc_value > 512)
output_high(LED);
else
output_low(LED);
delay_ms(100);
}
}
unsigned int16 adc()
{
read_adc(ADC_START_ONLY);
while(!adc_done());
return read_adc(ADC_READ_ONLY);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Sep 04, 2011 8:18 am |
|
|
Also, have you verified that the rest of the circuit is working. A simple one second delay, light the LED, one second delay, turn off the LED, and loop?. Things that could stop the code from apparently working include:
1) LED without a current limiting resistor - chip resets each time it is turned on, result it apparently doesn't work.
2) No pullup on MCLR.
3) Oscillator not actually working.
etc. etc..
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sun Sep 04, 2011 10:25 am |
|
|
Also is this a REAL circuit and NOT a Proteus 'simulation'?
Show the schematic of the real layout might help as well. |
|
|
|