|
|
View previous topic :: View next topic |
Author |
Message |
spilz
Joined: 30 Jan 2012 Posts: 219
|
ADC and 18F2550 |
Posted: Tue Oct 30, 2012 2:30 am |
|
|
Hi everybody !
I'm trying to use ADC on my 18F2550 with PCWHD 4.065.
the goal is to read ADC on pin A0, other pins A1 to A5 are used as logic output.
my code :
Code: | #include <18F2550.h>
#device adc=10
#fuses INTRC_IO,NOWDT,NOMCLR,NOPROTECT,NOLVP,NODEBUG,PLL1,CPUDIV1,NOBROWNOUT
#use delay(clock=8000000,restart_wdt)
#define PICKIT_UART
#define rs232_pickit2_rx PIN_B6
#define rs232_pickit2_tx PIN_B7
#use rs232(baud=9600,parity=N,xmit=rs232_pickit2_tx,rcv=rs232_pickit2_rx,bits=8,TIMEOUT=500,STREAM=rs232_pickit2)
void main()
{
int16 an=0;
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_oscillator(OSC_8MHZ);
while(true){
set_adc_channel(0);
delay_us(50);
an = read_adc(); // 0 à 1024
fprintf(rs232_pickit2,"AN %lu\r\n",an);
delay_ms(500);
}
} |
but I don't understand why it does not work :
I just receive "AN 16384".
do you have any idea about my problem?
thanks for your reply
Spilz |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Oct 30, 2012 2:43 am |
|
|
What does your code do?
What does it not do?
Can you do a LED flasher?
Are you working with real hardware and not simulation?
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Oct 30, 2012 2:49 am |
|
|
Er.....
What do you think:
setup_adc(ADC_OFF);
Does?.....
You are turning off the clock that operates the ADC. Saves power, but it can't then work....
setup_adc(ADC_CLOCK_DIV_8);
Is correct for your chip at 8MHz.
Best Wishes |
|
|
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Tue Oct 30, 2012 2:50 am |
|
|
Hi,
thanks for your interrest
I'm using a developing board (real one), with adj resistor connect on pin_a0.
My code do more stuff like read I2C EEPROM, print on LCD modul. These parts works well.
So now I try just to read ADC, and it does not work...
I check with oscilloscop, the tension change on the pin_A0 when I turn the Adj resistor.
Any idea?
I already used ADC on 12F675, and it worked well... |
|
|
spilz
Joined: 30 Jan 2012 Posts: 219
|
|
Posted: Tue Oct 30, 2012 2:58 am |
|
|
thank Ttelmah,
changing
Code: | setup_adc(ADC_OFF); |
by
Code: | setup_adc(ADC_CLOCK_DIV_8); |
seems to be the solution : it work well now
so, problem solved, the solution is :
don't forget to configure ADC clock |
|
|
|
|
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
|