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 CCS Technical Support

two a/d channels reading problem

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



Joined: 14 May 2007
Posts: 11

View user's profile Send private message

two a/d channels reading problem
PostPosted: Mon May 14, 2007 1:35 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon May 14, 2007 2:09 pm     Reply with quote

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








PostPosted: Thu May 17, 2007 5:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 17, 2007 5:34 am     Reply with quote

Sorry Guest was me Smile
forget to login
Ttelmah
Guest







PostPosted: Thu May 17, 2007 9:00 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 17, 2007 1:51 pm     Reply with quote

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







PostPosted: Thu May 17, 2007 2:53 pm     Reply with quote

'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

View user's profile Send private message

PostPosted: Sat May 19, 2007 3:11 am     Reply with quote

my compiler is PCWH 4.033
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