Require a FIX for -ve decimal logging
I am trying to use Autudatalogger Object(Auther-SRLM) - The object works as it is suppose to but It will not log -ve numbers.
SRLM suggested a fix but it does not work.
Fix suggested to dec_to_ASCII :
The -ve decimal numbers are logged as "95,96,98" etc. instead of " -1.-2,-3" etc.
Thank you for youe help.
Siri
PS: Attached is the Autilogger Object by SRLM
SRLM suggested a fix but it does not work.
Fix suggested to dec_to_ASCII :
dec_to_ASCII 'Converts an unsigned number in a register to an ASCII value
't1 - The decimal number
't2 - The current count of the digits (ie, how many 100's are in 843)
't3 - The current number of digit (1000(4), 10(2), 1(1))
't4 - (parameter) the number to convert
't5 - (parameter) the number of digits in the number (modified)
' ---too few will result in tuncation of upper digits
'ASCII_num - (result) will contain the number, optional negative (-, counts as digit)
dec_to_ASCII
movs :main_loop, #decimal
cmp t1, #0 wc 'Test if less than 0
if_c neg t1, t1 'make the number +ve
if_c add t3, #1 'increment the digit counter
if_c mov ASCII_num, "-" 'Save -ve sign
if_c movd :write, #ASCII_num + 1
if_nc movd :write, #ASCII_num
mov t3, #10
:main_loop mov t1, 0-0 'Copy the decimal number (1, 1000, 10000, etc) into the variable
mov t2, #0 'Clear the counter
:multiply cmp t4, t1 wc 'Is the number less than the decimal number?
if_nc sub t4, t1 'The decimal number is <= than the value
if_nc add t2, #1 'increment the digit count
if_nc jmp #:multiply
add t2, #48 'Increase to ASCII 0
:write mov 0-0, t2
cmp t5, t3 wc 'Should I write move on to the next digit?
if_nc add :write, destination_mask'Move on to the next digit in ASCII_num
add :main_loop, #1 'Move on to the next digit in decimal
djnz t3, #:main_loop
dec_to_ASCII_ret ret
I tried replacing "neg" with "abs" - stiill does not work.The -ve decimal numbers are logged as "95,96,98" etc. instead of " -1.-2,-3" etc.
Thank you for youe help.
Siri
PS: Attached is the Autilogger Object by SRLM


Comments
dec_to_ASCII 'Converts a signed number in a register to an ASCII value 't2 - The current count of the digits (ie, how many 100's are in 843) 't3 - The current number of digit (1000(4), 10(2), 1(1)) '[COLOR="#FFA500"]t4 - (parameter) the number to convert[/COLOR] '[COLOR="#FFA500"]t5 - (parameter) the number of digits in the number (modified)[/COLOR] 'ASCII_num - (result) will contain the number, optional negative (-, counts as digit) movs :multiply, #decimal '| movd :write, #ASCII_num 'reset {signed} cmps t4, #0 wc 'Test if less than 0 {signed} if_c neg t4, t4 'make the number +ve {signed} if_c mov ASCII_num, #"-" 'Save -ve sign {signed} if_c addx :write, #$1FF{+1} 'skip sign mov t3, #10 'max digits :main_loop mov t2, #0 wz 'Reset counter :multiply cmpsub t4, 0-0 wc 'Is the number less than the decimal number? addx t2, #0 wz 'increment the digit count if_c jmp #:multiply {!field} cmp t5, #1 wc '0, 1..10 {!field} if_c_and_z jmp #:skip 'ignore leading zeros {!field} if_c mov t5, t3 'sync field width add t2, #"0" 'dec -> ASCII :write mov 0-0, t2 'store converted character cmpsub t5, t3 wc,nr 'Should I write move on to the next digit? if_c addx :write, #$1FF{+1} 'Move on to the next digit in ASCII_num :skip add :multiply, #1 'Move on to the next digit in decimal djnz t3, #:main_loop {signed} cmp ASCII_num, #"-" wz '| {signed} if_e add t5, #1 'adjust length (for sign) dec_to_ASCII_ret retNote that for -ve numbers the digit count is updated by 1 which means that when the function is called:loop mov t4, 0-0 :loop_a mov t5, 0-0 call #dec_to_ASCII [COLOR="#FF0000"]mov t6, t5 'copy number of digits of the number[/COLOR] add :loop, #1 add :loop_a, #1t6 should read t5 after the fact. Furthermore, having leading 0s and a sign looks silly IMO. I therefore added the option of suppressing this feature by passing 0 as the digit count. This is currently blocked by the SPIN frontend but is easily changed.I tried your fix - All I got was the fields(Varible field name) but no data logged.
The issue at hand most likely is that The file was never closed.In my project I have it to logg for 1.0 min.and then stop.It did not stop after 1.0 min.- so turned off the Prop ?---> corrupt file,no data
The led was blinking ? indicating receiving data (as it use to do)
The attached file shows the Object with the suggested changes.
This is the code I have in my project which logg 3 variables -"Pressure,Pressure1 and RPM" for 1.0 min
This code runs in its own COG- :
Pub DataLogger 'DATA LOGGER CODE filenameaddr := string("Pressure.txt") num1 := num2 := num3 := 0 waitcnt(clkfreq*6 + cnt) waitcnt(clkfreq*2 + cnt) USB.init(rxpin, txpin, ctspin, filenameaddr, 10_000) ' (address, digits, title) USB.addfield(@pressure, 2, string("Raw")) USB.addfield(@RPM, 4, string("RPM")) USB.addfield(@Pressure1, 2, string("corrected")) ' USB.start repeat num0 from 1 to 3 num0[num0] := 3_999_999_999 num0 := cnt repeat 1 repeat 60 '1 Minute waitcnt(num0 += clkfreq) 'Seconds USB.stop repeatThank you very much for your help.
Siri
To post code, use:
The indentation an formatting of Spin code gets lost if you just cut and paste into a post.
I copied some code I missed and I ran it.Now I am getting -ve numbers but they are not in the same column.
Hear is the modified code as you suggested.Attached to this post and also the print out of the Data output.
If you look at the pressure.txt file the formatting really gets muddled up- I think that is where the system clock goes -Ve.
Thanks again for your help.
Regards,
Siri
log.addfield( @num0, 10, string("fixed width unsigned")) log.addfield(NEGX|@num1, 10, string("fixed width signed")) log.addfield( @num2, 0, string("auto width unsigned")) log.addfield(NEGX|@num3, 0, string("auto width signed"))Currently a fixed width value doesn't include the sign, i.e. it's specified width +1 when -ve. If this is an issue let me know. The system counter display (1st column) will be fixed at 10 digits unsigned.I really don't care about cnt - I use it get an avarage time between two readings - but I like the pressure readings to be signed values(-ve and +ve).
The new version fixes the length issue system counter is ok for my project but no -ve pressure values like the previous version.
Attached is the txt file with tne new version.
Thanks again for tremendous help
Regards,
Siri
P.S :In the "Raw" column are the raw pressure readings-(the pressure sensor reads 31 at atmospheric pressure) so the "Corrected" column
represents pressure reading(Raw-31) - the -ve values are now shown as 95,96 ...85 etc.
Thank you very much,now it works well.
Last time in my haste I forgot to change the new addfield format.
Thanks again
Regards
Siri
P.S:Attached is the NEW Datalogger text file.