View previous topic :: View next topic |
Author |
Message |
mbyes
Joined: 14 Aug 2006 Posts: 4
|
problem with ADC in PIC18LF4620 |
Posted: Mon Dec 18, 2006 10:24 pm |
|
|
Hi friends.
Below source is me coding.
At every read_adc(), value incorrect.
This source is definitely correct?
Thank you.
#include <18F4620.h>
#device adc=10
#fuses H4, NOWDT, NOPROTECT, NOBROWNOUT, PUT, NOLVP
#use delay(clock=40000000)
void main()
{
int16 value;
set_tris_A(0x03);
setup_adc_ports(AN0_TO_AN1 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_4);
output_bit(pin_a2,1);
output_bit(pin_a3,1);
output_bit(pin_a5,1);
while(1){
set_adc_channel(4);
delay_us(10);
value = read_adc();
delay_us(10);
}
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 18, 2006 10:35 pm |
|
|
Quote: | At every read_adc(), value incorrect. |
Look at the two statements shown in bold below. Do you see
anything that's not correct ?
Quote: |
void main()
{
int16 value;
set_tris_A(0x03);
setup_adc_ports(AN0_TO_AN1 | VSS_VDD);
setup_adc(ADC_CLOCK_DIV_64 | ADC_TAD_MUL_4);
output_bit(pin_a2,1);
output_bit(pin_a3,1);
output_bit(pin_a5,1);
while(1){
set_adc_channel(4);
delay_us(10);
value = read_adc();
delay_us(10);
}
} |
|
|
|
vi_ni_ta
Joined: 11 Dec 2006 Posts: 7
|
|
Posted: Tue Dec 19, 2006 5:13 am |
|
|
why do people use int16 and int32 for ADC conversion instead of just int.
my adc part is compiling but the function is not done when i simulate it because i use just int.
if i use int16 i am unable to print it.
kindly help me ASAP pls |
|
|
davekelly
Joined: 04 Oct 2006 Posts: 53 Location: Berkshire, England
|
|
Posted: Tue Dec 19, 2006 6:03 am |
|
|
vi_ni_ta wrote: | why do people use int16 and int32 for ADC conversion instead of just int. |
A lot of the devices have 10 bit or more resolution.
If you only want to use 8 bits, use
Look in the manual for the function read_adc()
You can easily print a 16 bit value using the correct printf specifier, eg Code: | sprintf (str, "%Lu", value16); |
|
|
|
vi_ni_ta
Joined: 11 Dec 2006 Posts: 7
|
|
Posted: Tue Dec 19, 2006 8:49 pm |
|
|
Thanks dave. I figured tat out rightaway as soon as i posted my query. but there still is one big bug. i've coded it right. my complier says no error. but when i simulate it my ADC conversion does not do a good job. will pass on the code and hopefully in a short while post a solution too.. |
|
|
|