View previous topic :: View next topic |
Author |
Message |
altra22
Joined: 14 May 2007 Posts: 11
|
two a/d channels reading problem |
Posted: Mon May 14, 2007 1:35 pm |
|
|
Hi my problem to display two a/d values to lcd the 2nd channel update ok (Temp) but the first one (Volt) does not update until reset the PIC board
Here's my code
Code: | #include <16F876a.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include <lcd.c>
#use fast_io(B)
float y,i,x,value;
void main()
{
lcd_init();
output_b(0x00);
set_tris_b(0x00);
// Setup A/D
setup_adc_ports(RA0_RA1_RA3_ANALOG);
setup_adc(ADC_CLOCK_DIV_32); // Divide clock by 32
while(1)
{
set_adc_channel(0);
delay_ms(100);
i = read_adc();
x= (i*5/1023)-5 ;
// secound channel //
set_adc_channel(1);
delay_ms(100);
value = read_adc();
y = 5*value*100/1023;
printf(lcd_putc,"Volt is %f \nTemp is %f ",x,y);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 14, 2007 2:09 pm |
|
|
1. What do you see on the LCD ? Post the exact text that you
see on the two lines of the LCD, the first time the program runs.
2. Post the text displayed on the LCD after you press the reset button.
3. Post your compiler version.
4. Are you running this program on a hardware board, or in Proteus ?
5. What is connected to Port B. Is it the LCD ? |
|
|
Guest
|
|
Posted: Thu May 17, 2007 5:33 am |
|
|
i got this
Volt is 3.28 (No refresh)
Temp is 28.22 (refreshing OK)
when pushing the reset button i see the same but when i change volt
the first line change when pushing reset
the temperature 2nd line keep refreshing normally
i ran this test in Hardware Board not Proteus
yes iam using port b for LCD
my Compiler version is 4 |
|
|
altra22
Joined: 14 May 2007 Posts: 11
|
|
Posted: Thu May 17, 2007 5:34 am |
|
|
Sorry Guest was me
forget to login |
|
|
Ttelmah Guest
|
|
Posted: Thu May 17, 2007 9:00 am |
|
|
Compiler version?.
Try two things:
[code]
while(1) {
set_adc_channel(0);
delay_ms(100);
i = read_adc();
x= (i*5.0/1024.0)-5.0 ;
// secound channel //
set_adc_channel(1);
delay_ms(100);
value = read_adc();
y = 5*value*100/1024;
printf(lcd_putc,"Volt is %7f \nTemp is %7f ",x,y);
}
[code]
The two things are, forcing floating point arithmetic to be used in the prescaler, and putting a maximum width on the floating point output. Historically, several CCS versions, have problems when using the 'unlimited' %f format. It causes an internal error, with a temporary variable getting damaged, especially when multiple numbers are output in one printf.
Using the floating point arithmetic, should not apply in this case, but is another area that sometimes causes problems.
As an aside, look at my post in the thread 'what will happen if the ADC channel exceeds Vref', for why I use 1024 as the divider on a PIC ADC, not 1023.
Best Wishes |
|
|
altra22
Joined: 14 May 2007 Posts: 11
|
|
Posted: Thu May 17, 2007 1:51 pm |
|
|
no it doesn't work and i used double the result is the same i think the problem with while loop when i use for loop it's works but when i use while(true) or while(1) here's the problem
for loop give me undesired output on the lcd . |
|
|
Ttelmah Guest
|
|
Posted: Thu May 17, 2007 2:53 pm |
|
|
'Using double', does nothing. CCS, does not support the 'double' data type...
You still have not answered which compiler?.
Best Wishes |
|
|
altra22
Joined: 14 May 2007 Posts: 11
|
|
Posted: Sat May 19, 2007 3:11 am |
|
|
my compiler is PCWH 4.033 |
|
|
|