News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

VAL function does not work anymore

Started by Amateurtje, Jul 14, 2023, 11:55 AM

Previous topic - Next topic

Amateurtje

Hello, I recomplied existing an existing script and it does not work anymore. Waht I found out, I use the VAL function a lot of times by decoding a GPS string.. What always worked, does not work annymore.. Even this VAL function is not reached in the script, when it is somewhere, the programm crashes and restarts the processor...

When commenting all the VAL commands, the problem was gone but I need these commands ofcourse......

I spent now a complete day to find out where the problem is but to find a solution is a big thing.
Anybody an idea?
I really need to recompile this script. Anybody any ideas?

PS, I downloaded the latest revsision of the compiler, but the problem is not gone.. Probably that is how the problem started while I do that occasionally...

Could that be les?

top204

We will need a few more details. For example:

What device?
What variable types?

Without the above details, I cannot even start to answer your question, because I know the Val function works in programs that I am now using, and I even used it in a post recently about decoding 2 Hex characters into an integer value, and it worked perfectly with the most recent compiler version.

top204

I've just ran a series of tests using the program listing below, adapted for the standard 14-bit core devices, enhanced 14-bit core devices, and 18F devices, and the Val function is working as it should on all the device architectures:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Val function tests
'
' Written by Les Johnson for the Positron BASIC compiler.
'
    Device = 18F25K20                           ' Tell the compiler what device to compile for
    Declare Xtal = 8                            ' Tell the compiler what frequency the device is operating at (in MHz)

    Declare Hserial_Baud = 9600                 ' Tell the compiler what Baud rate for USART1
    Declare HRSOut1_Pin = PORTC.6               ' Tell the compiler what pin to use for USART1 TX

    Dim MyByteOut  As Byte
    Dim MyWordOut  As Word
    Dim MyLongOut  As Long
    Dim MyDwordOut As Dword
    Dim MyFloatOut As Float

    Dim SourceArray[32] As Byte
    Dim SourceString As String * 32

'--------------------------------------------------------------------------------------------------
'
Main:
    Strn SourceArray = "123"
    MyByteOut = Val(SourceArray, Dec)
    HRsoutLn "Array: ", Str SourceArray, " is converted to Byte: ", Dec MyByteOut

    Strn SourceArray = "1234"
    MyWordOut = Val(SourceArray, Dec)
    MyLongOut = Val(SourceArray, Dec)
    MyDwordOut = Val(SourceArray, Dec)
    MyFloatOut = Val(SourceArray, Dec)

    HRsoutLn "Array: ", Str SourceArray, " is converted to Word: ", Dec MyWordOut
    HRsoutLn "Array: ", Str SourceArray, " is converted to Long: ", Dec MyLongOut
    HRsoutLn "Array: ", Str SourceArray, " is converted to Dword: ", Dec MyDwordOut
    HRsoutLn "Array: ", Str SourceArray, " is converted to Float: ", Dec0 MyFloatOut
'
' Convert an ASCII Hex value in an array
'
    Strn SourceArray = "0D"
    MyByteOut = Val(SourceArray, Hex)
    HRsoutLn "Array: $", Str SourceArray, " is converted to Hex Byte: ", IHex2 MyByteOut

    Strn SourceArray = "1234"
    MyWordOut = Val(SourceArray, Hex)
    MyLongOut = Val(SourceArray, Hex)
    MyDwordOut = Val(SourceArray, Hex)
    MyFloatOut = Val(SourceArray, Hex)

    HRsoutLn "Array: $", Str SourceArray, " is converted to Hex Word: ", IHex4 MyWordOut
    HRsoutLn "Array: $", Str SourceArray, " is converted to Hex Long: ", IHex4 MyLongOut
    HRsoutLn "Array: $", Str SourceArray, " is converted to Hex Dword: ", IHex4 MyDwordOut
'
' Convert a String containng ASCII digits to an integer
'
    SourceString = "123"
    MyByteOut = Val(SourceString, Dec)
    HRsoutLn "String: ", SourceString, " is converted to Byte: ", Dec MyByteOut

    SourceString = "54321"
    MyWordOut = Val(SourceString, Dec)
    MyLongOut = Val(SourceString, Dec)
    MyDwordOut = Val(SourceString, Dec)
    MyFloatOut = Val(SourceString, Dec)

    HRsoutLn "String: ", SourceString, " is converted to Word: ", Dec MyWordOut
    HRsoutLn "String: ", SourceString, " is converted to Long: ", Dec MyLongOut
    HRsoutLn "String: ", SourceString, " is converted to Dword: ", Dec MyDwordOut
    HRsoutLn "String: ", SourceString, " is converted to Float: ", Dec0 MyFloatOut
'
' Convert an ASCII Hex value in a String
'
    SourceString = "0D"
    MyByteOut = Val(SourceString, Hex)
    HRsoutLn "String: $", SourceString, " is converted to Hex Byte: ", IHex2 MyByteOut

    SourceString = "1234"
    MyWordOut = Val(SourceString, Hex)
    MyLongOut = Val(SourceString, Hex)
    MyDwordOut = Val(SourceString, Hex)
    MyFloatOut = Val(SourceString, Hex)

    HRsoutLn "String: $", SourceString, " is converted to Hex Word: ", IHex4 MyWordOut
    HRsoutLn "String: $", SourceString, " is converted to Hex Long: ", IHex4 MyLongOut
    HRsoutLn "String: $", SourceString, " is converted to Hex Dword: ", IHex4 MyDwordOut

It displays on a serial terminal:

Array: 123 is converted to Byte: 123
Array: 1234 is converted to Word: 1234
Array: 1234 is converted to Long: 1234
Array: 1234 is converted to Dword: 1234
Array: 1234 is converted to Float: 1234
Array: $0D is converted to Hex Byte: $0D
Array: $1234 is converted to Hex Word: $1234
Array: $1234 is converted to Hex Long: $1234
Array: $1234 is converted to Hex Dword: $1234
String: 123 is converted to Byte: 123
String: 54321 is converted to Word: 54321
String: 54321 is converted to Long: 54321
String: 54321 is converted to Dword: 54321
String: 54321 is converted to Float: 54321
String: $0D is converted to Hex Byte: $0D
String: $1234 is converted to Hex Word: $1234
String: $1234 is converted to Hex Long: $1234
String: $1234 is converted to Hex Dword: $1234


Amateurtje

Hi Les, Thats weird.

It is with different variable types, the device is a 18f46k22.

It compiles etc beautifully. Only, when running the device, It hangs the device and the device is restarted (after a while due to the watchdogtimer.)


It will make a kind of basic program  and then integrated this val Function... Like I wrote, the strange thing is, that it is in a script that was not even hit by the software...I will investigate some more..

Amateurtje

In the menatime it got stuck and I have too much open to restart my pc. I found out that It has something to do with several items, EREAD's, GIE and VAL.. (and I assume Watchdogtimer). Very strange.. Maybe it has something to do in the adressing, timing (wdt) or EEPROM.. I have no clue but will during the weekend investigate further...

top204

When the watchdog is enabled, make sure you have plenty of Clrwdt mnemonics in your code, because the compiler's library routines do not reset the watchdog very much, otherwise, it would have no purpose, because the compiler would keep it cleared all the time. Delays clear the watchdog within them, if the Watchdog Declare is used, but standard statements such as If-Then, Do-Loop, While-Wend, For-Next etc, do not clear the watchdog at all.

Whenever your program has a loop or a command that may take a bit longer than the watchdog's period, place a Clrwdt mnemonic before it. Or better still, alter the watchdog period in the config fuse settings to a longer period when possible on the device you are using, then the watchdog needs fewer resets, but will still trigger a reset if the program hangs.


Amateurtje

#6
Quote from: top204 on Jul 14, 2023, 02:33 PMWhen the watchdog is enabled, make sure you have plenty of Clrwdt mnemonics in your code, because the compiler's library routines do not reset the watchdog very much, otherwise, it would have no purpose, because the compiler would keep it cleared all the time. Delays clear the watchdog within them, if the Watchdog Declare is used, but standard statements such as If-Then, Do-Loop, While-Wend, For-Next etc, do not clear the watchdog at all.

Whenever your program has a loop or a command that may take a bit longer than the watchdog's period, place a Clrwdt mnemonic before it. Or better still, alter the watchdog period in the config fuse settings to a longer period when possible on the device you are using, then the watchdog needs fewer resets, but will still trigger a reset if the program hangs.



Hi Les, Thanks for the reply.. I was checking for that but they seem to be plenty... Made a small delay routine with clrwdt inside So that should no be the problem... Secondly, what I do not understand that this timing would be infuenced, eventhough there is at a later stage a VAL command.. or even at a place where it is not hit at all... Thatis strange that it would be because of the wdt timing is reached...

It can not be that if there is anywhere a VAL command in the script, that it does something or reserve something during the startup or reservation in the addressing/adresses.... Anyway, I think I can get it out probably but it does fright me a little bit...

I have also a little bit the idea that it keeps hanging in the interrupt script... Just because it kind of "Hangs" before the restart... With the wdt, it restarts directly... So it seems to be stuck in the interrupt... So that is also a direction I need to look into...