|
|
View previous topic :: View next topic |
Author |
Message |
jdasari Guest
|
Voltage Display |
Posted: Wed Apr 09, 2003 9:37 am |
|
|
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 |
Posted: Wed Apr 09, 2003 10:00 am |
|
|
:=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 |
Posted: Fri Apr 11, 2003 6:24 pm |
|
|
Thanks Sherpa....that worked
___________________________
This message was ported from CCS's old forum
Original Post ID: 13623 |
|
|
|
|
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
|