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 support@ccsinfo.com

Voltage Display

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







Voltage Display
PostPosted: Wed Apr 09, 2003 9:37 am     Reply with quote

Please bear with my beginners ignorance here.
Once I get the voltage reading using the read_adc( ) how can I convert that into the actual decimal voltage. i.e For e.x if I read 153 how can display that as 3 volts on the LCD? I have my code pasted below. Thanks much in advance.



void main()
{

int choice=1; int flag=0;
int8 bat_voltage;
float dig_voltage= 0;
lcd_init();
set_tris_a(0xFF);
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);


while (flag == 0)
{
set_adc_channel(1);
delay_us(100);
bat_voltage=read_adc();
printf(lcd_putc,"\f bat_voltage=\%u", bat_voltage);
if(bat_voltage >= 255)
{
lcd_putc (" \f Full Charge \n");
flag=1;
}
dig_voltage = (bat_voltage*5)/255;
printf(lcd_putc,"\n \%f", dig_voltage);
delay_ms(1000);
}

lcd_putc("\f Exiting \n");
while(1);

}
___________________________
This message was ported from CCS's old forum
Original Post ID: 13543
Sherpa Doug
Guest







Re: Voltage Display
PostPosted: Wed Apr 09, 2003 10:00 am     Reply with quote

:=Please bear with my beginners ignorance here.
:=Once I get the voltage reading using the read_adc( ) how can I convert that into the actual decimal voltage. i.e For e.x if I read 153 how can display that as 3 volts on the LCD? I have my code pasted below. Thanks much in advance.
:=
:=
:=
:=void main()
:={
:=
:=int choice=1; int flag=0;
:=int8 bat_voltage;
:=float dig_voltage= 0;
:=lcd_init();
:=set_tris_a(0xFF);
:=setup_adc_ports(ALL_ANALOG);
:=setup_adc(ADC_CLOCK_DIV_32);
:=
:=
:=while (flag == 0)
:={
:=set_adc_channel(1);
:=delay_us(100);
:=bat_voltage=read_adc();
:=printf(lcd_putc,"\f bat_voltage=\%u", bat_voltage);
:=if(bat_voltage >= 255)
:={
:=lcd_putc (" \f Full Charge \n");
:=flag=1;
:=}
:=dig_voltage = (bat_voltage*5)/255;
:=printf(lcd_putc,"\n \%f", dig_voltage);
:=delay_ms(1000);
:=}
:=
:=lcd_putc("\f Exiting \n");
:=while(1);
:=
:=}

Try:

dig_voltage = ((float)bat_voltage*5)/255;

Bat_voltage * 5 may not fit in an int8.
If that is not the problem could you tell us what results you do get?

___________________________
This message was ported from CCS's old forum
Original Post ID: 13547
jdasari
Guest







Re: Voltage Display
PostPosted: Fri Apr 11, 2003 6:24 pm     Reply with quote

Thanks Sherpa....that worked
___________________________
This message was ported from CCS's old forum
Original Post ID: 13623
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