Shift decimal in variable?

jonphenry

New Member
Im reading voltage from a small solar panel. VOC is 25.6V. Im using a voltage divider to get it down to 5v. With a 10K on top and 2.4K on bottom, I get 4.95xxxV(close enough for my purposes). Because of my highest voltage being 25.6 my adc values are exact multiples of the actual voltages by 10. Therefore dividing the adc value by 10 would give me the actual voltage. With the picaxe my answer would be truncated.

I believe Ive read something about shifting decimals over before but am not quite sure what to search for. Id like to be able to take an ADC value of lets say 125 and make it 12.5. Is this possible or am I confusing what I remembered with something else?

The project is a datalogger measuring voltage and current from a small solar panel throughout the day. It takes a reading every 10 minutes and stores the data in eeprom.

BeanieBots

Moderator
Yes, you can do that.
123/10=12
123//10=3 ie remainder of 123/10

hence,
b0=123/10
b1=123//10
sertxd (#b0,".",#b1) will display "12.3"

jonphenry

New Member
Thanks for the quick response Beaniebots.

Im using that to display the value on an lcd.
What im looking for though is wether or not its possible to do that in one variable.

IE b1=12.3

I need to send it out to Selmadaq as one value to make the charting work for me.

BeanieBots

Moderator
No. Sorry, only integers inside a PICAXE.
I no nothing about Selmadaq but can't it interpret "12.3" as 12.3 ?
Assuming the PICAXE could have a floating point number, how would you send it to Selmadaq?
Try terminating the send with carriage return & line feed.

jonphenry

New Member
My apologies Beaniebots. That does work for me now that I look at it.

I didnt think it would work due to the way I had to format the data set to Selmadaq, but it does.

Selmadaq is simply an excel spreadsheet with a macro setup for importing data from a basic stamp. Works equally well for the picaxe.
Each variable sent to selmadaq is placed into its own column. Thats why I thought I needed it to be in one variable.

sertxd("DATA,",#b7,".",#b8,",",#b5,CR)

I was mistaking the decimal for the comma. To tell selmadaq 'hey this is a new variable and requires a new column' you put "," between the variables. I thought the "." between the number and remainder would throw that off but it doesnt. It puts the b7.b8 in one column just the way I need it.

This project is meant to get a good idea of how many hours a day I could get productive sunlight in my area.

Rbeech

New Member
Yes, you can do that.
123/10=12
123//10=3 ie remainder of 123/10
Awesome, this just resolved a problem I was having. I had found the DIG command, but that's not supported in the 18X.

Lliam20789

New Member
I just got the same concept converting NTC thermistor value to degrees C! not the greatest resolution (.3 C) but I'm happy...

Gets a bit tricky with large equations, avoiding negatives while keeping the number wholeish and remembering what to divide by...

hippy

Technical Support
Staff member
Watch out if going to two or more digits after the decimal point ...

- w0 = value / 1000
- w1 = value // 1000
- SerTxd( #w0, ".", #w1, CR, LF ) ' Display X.YYY

Leading zeroes get dropped in #w1 so a value of 1001 will end up incorrectly reported as "1.1", not as "1.001".

To get round that it becomes necessary to force those leading zeroes to be reported separately ...

- w0 = value / 1000
- w1 = value // 1000
- SerTxd( #w0, "." )
- If w1 < 100 Then : SerTxd( "0" ) : End If
- If w1 < 10 Then : SerTxd( "0 ") : End If
- SerTxd( #w1, CR, LF )

An arguably more elegant version ( but probably with slightly larger code size ) would be -

- w0 = value / 1000
- w1 = value // 1000
- SerTxd( #w0, "." )
- Select Case w1
--- Case < 100 : SerTxd( "00" )
--- Case < 10 : SerTxd("0")
- End Select
- SerTxd( #w1, CR, LF )

The best way to save code space if you have a number of decimal numbers to display is to put that code in a subroutine and call it as needed.