Menu

A very strange error ...

2020-08-03
2020-08-06
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-03

    I attach a program, I tested it with the same issue both on AT90S8515 and ATMega162. It should send commands to a sample player (ADAFruit Sound FX board) via serial. Everything is fine since I use the buttons related with bits 0 to 6 on port D ; I saved the values of variables to EEProm for debugging : if I use button for bit 7, i.e. if numero_annonce_local = 1, the variables "numero message_local" and "numero_mot", which should only by decimal 1, 2, 11 or 12 (marche_avant = 1 or 0, gare = 10 or 0) show always the value ... 0x57 ! I tested my board ("old" STK200) with an infinite loop : PortB = PinD, no problem, no short circuit. What is happening ?
    Thanks for any answer ...

     

    Last edit: Bertrand BAROTH 2020-08-04
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    Now I modified the program to have one level less in subroutines calling : still the same error. It seems that line 54 is executed as :
    numero_message_local = 87 + gare
    And I deinstalled and reinstalled GCBasic (Minimal installation 98.06) : I thought that the compiler had been corrupted, and tested even with 98.05 version. But still the same. And I downloaded again the compiler, put the instructions on a new line after the "Case" statement : am I cursed ?
    ????

     

    Last edit: Bertrand BAROTH 2020-08-04
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    Problem solved : it was related with AVRISP-U ; the program runs without any issues when I unplug the ISP connector on STK200 ... So I will "ghost" again my computer (I have an image without AVRISP) and reinstall the faulty program. Wait and see ... in about 1 hour !

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    I was happy too early : if the ISP is plugged in, the button does not work at all ; if it unplugged, it works only once, and only if it is the first button pressed. I unplugged the ADA device, I thought it was taking too much current and crash the processor : nothing better ... I compiled the program without any references to Serial : same issues, the problem is not related with those routines. So please take a glance at the generated code, I am unfortunately not very familiar with AVR assembler.

     

    Last edit: Bertrand BAROTH 2020-08-04
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    Now I modified my code to Test3, declaring the local variables in Dire_phrase as global. If I run the prog without line 83, I get for numero_message_local 1 (it should be 2, Marche_avant is discarded) ; if I activate line 83, I get 0x57 again. Sorry, I think that the code generated at line 76 is pure fantasy ...

     

    Last edit: Bertrand BAROTH 2020-08-04
  • Anobium

    Anobium - 2020-08-04

    Hi.

    I can see nothing in the code (yet).

    Change line 57 from chaine_locale = Mid (Tampon_ADAF, compteur_local, 1) to chaine_locale = Tampon_ADAF(compteur_local) This will rule out any issues in the MID() function. Test.

    Change line 58 from Ser1Print to Ser1Send. This will rule out any issues with in Ser1Print.

    You could simply use Ser1Print Tampon_ADAF(compteur_local)


    Annonces_train first parameter can 1 to 4 and this sets numero_annonce_local. So the case statement should work.

    But, you have Marche_avant and gare changing. Where Marche_avant is 1 or 0, and gare is 0 or 10.

    So, truth table yields interest state where your logic generates non unique states and I cannot yet understand where 0x57 comes from.

    numero_annonce_local Marche_avant gare Yields Commnt
    1 1 0 2
    1 0 0 1
    1 0 10 11
    1 1 10 12 Non unique state
    2 1 0 3
    2 0 0 2
    2 0 10 12 Non unique state
    2 1 10 13
    3 1 0 4
    3 0 0 3
    3 0 10 13 Non unique state
    3 1 10 14 Non unique state
    4 1 0 5
    4 0 0 4
    4 0 10 14 Non unique state
    4 1 10 15

    So, no answer to your issue yet - as the truth table looks odd and I do not understand where '0x57' comes from.

    EDITED: And, I may have the table values incorrect. Please correct.

     

    Last edit: Anobium 2020-08-04
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    Memory allocation of variables ? You can test the prog, it runs without the hardware connected ...

     
    • Anobium

      Anobium - 2020-08-04

      No, I do not think that memory allocation is the issue as we have no proof.

      Change Travail = PinD to a repeat loop, where you set each bit of Travail to 0 sequencially. This will give you a static test condition of Travail. What results do you get? This test removes the state check of PinD.

      What are that values for numero_message_local ? Create a table as shown above to show the resulting calculation of numero_message_local. I think this value is not correct.

       
  • Anobium

    Anobium - 2020-08-04

    I had to port to a MEGA329p. I am on vacation.

    This works as expected. Does this work for you? Is the serial the same as below?

    Test3
    Travail: 0b11111110 0d254
    Travail: 0b11111101 0d253
    Travail: 0b11111011 0d251
    Travail: 0b11110111 0d247
    Travail: 0b11101111 0d239   4   1   16PMESSAG16WAV
    Travail: 0b11011111 0d223   3   1   15PMESSAG15WAV
    Travail: 0b10111111 0d191   2   1   14PMESSAG14WAV
    Travail: 0b01111111 0d127   1   1   11PMESSAG11WAV
    

    If you get different values then we need to dig deeper. If this test works this prooves the logic you have is correct.

    But, I think PORTD is not what you think is it. As the this test will ensure for one bit being zero the string created is correct. But, if another bit is also zero it is ignored. there is no debounce check.

    Evan

    'Program Test3
    
    ' ----- Configuration
     #chip mega328p, 16
     #include <uno_mega328p.h>
    
     #Option Explicit
    
    ' Constantes et variables
    
     #Include <SoftSerial.h>
     #Define SER1_TXPORT PortD
     #Define SER1_TXPIN 1
     #Define SER1_RXPORT PortC
     #Define SER1_RXPIN 0
     #Define SER1_BAUD 9600
     #Define SER1_DATABITS 8
     #Define SER1_STOPBITS 1
     #Define SER1_INVERT Off
     #Define Gare_haut 10
     #Define Gare_bas 0
    
     Dim Annoncer_trains As Byte
     Dim Gare As Byte
     Dim Marche_avant As Byte
     Dim Tampon_leds As Byte
     Dim Test AS Byte
     Dim Travail As Byte
    
     Dim chaine_locale As String * 5
     Dim compteur_local As Byte
     Dim tampon_ADAF As String * 20
     Dim numero_mot As Byte
     Dim Attente As Byte
    
    ' --------------------------------------------------------------------
    
    Sub Attente_ADAF ()
    
     ' Attente handshake ADAF
     Do
      Test = Ser1Receive
     Loop Until (Test = 100)
    
    End Sub
    
    ' --------------------------------------------------------------------
    
    Sub Dire_phrase ()
    
     ' Dit le mot numéro "numero_mot"
    
     EPWrite 2, numero_mot
     chaine_locale = right("0" + Trim (Str (numero_mot)), 2)
     Tampon_ADAF = "PMESSAG" + chaine_locale + "WAV" + chr (10)
    
     For compteur_local = 1 to Len (Tampon_ADAF)
      Ser1Send Tampon_ADAF( compteur_local )
     Next
    
     ' If (attente <> 0) Then Attente_ADAF ()
    
    End Sub
    
    ' --------------------------------------------------------------------
    
    Sub Annonces_train (In numero_annonce_local As Byte, In attente_locale As Byte)
    
         ' Annonce du train en gare
    
      Ser1Send 9
      Ser1Print numero_annonce_local
      Ser1Send 9
      Ser1Print attente_locale
    
         Dim numero_message_local As Byte
    
         EPWrite 0, numero_annonce_local
         If (Annoncer_trains <> 0) Then
          Select Case numero_annonce_local
           Case 1      : numero_message_local = 1 + Marche_avant + gare
           Case 2      : numero_message_local = 3 + Marche_avant + gare
           Case 3 To 4 : numero_message_local = 2 + numero_annonce_local + gare
          End Select
    
      Ser1Send 9
      Ser1Print numero_message_local
    
          Numero_mot = numero_message_local
          Attente = attente_locale
          EPWrite 1, numero_message_local
          Dire_Phrase ()
         End If
    
    End Sub
    
    ' --------------------------------------------------------------------
    
    ' Programme principal
    
      wait 2 s
      Ser1Send 10
      Ser1Send 13
      Ser1Print "Test3"
      Ser1Send 10
      Ser1Send 13
      wait 100 ms
    
    ' ERV Commented out to debug
    ' PortD = 0b11111111
    ' DdrD = 0b00000000
     DdrB = 0b00001111
     PortB = 0b11110110
    
     Annoncer_trains = 1
     Gare = Gare_bas
     Marche_avant = 1
     Tampon_leds = 0b11110110
    
    
    
     Boucle:
    
    ' ERV Commented out to debug
    '  Dir PortD in
    '  Travail = PinD
    
      dim indexloop as Byte
    
      for indexloop = 0 to 7
          Travail = 255
          Travail.indexloop = 0
    
    
          Ser1Print "Travail: 0b"
          Ser1Print ByteToBin( Travail)
          Ser1Print " 0d"
          Ser1Print  Travail
    
    
          PortB = Tampon_leds
    
          If (Travail.7 = 0) Then
           Annonces_train (1, 1)
    '       GoTo Boucle
          End If
    
          If (Travail.6 = 0) Then
           Annonces_train (2, 1)
    '       GoTo Boucle
          End If
    
          If (Travail.5 = 0) Then
           Annonces_train (3, 1)
    '       GoTo Boucle
          End If
    
          If (Travail.4 = 0) Then
           Annonces_train (4, 1)
    '       GoTo Boucle
          End If
    
          If (Travail.3 = 0) Then
           Marche_avant = 1
           Tampon_leds.3 = 0
           Tampon_leds.2 = 1
    '       GoTo Boucle
          End If
    
          If (Travail.2 = 0) Then
           Marche_avant = 0
           Tampon_leds.3 = 1
           Tampon_leds.2 = 0
    '       GoTo Boucle
          End If
    
          If (Travail.1 = 0) Then
           Gare = Gare_haut
           Tampon_leds.1 = 0
           Tampon_leds.0 = 1
    '       GoTo Boucle
          End If
    
          If (Travail.0 = 0) Then
           Gare = Gare_bas
           Tampon_leds.1 = 1
           Tampon_leds.0 = 0
    '       GoTo Boucle
          End If
    
    
          Ser1Send 10
          Ser1Send 13
          wait 10 ms
      Next
    
     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    Thanks, but look at the attached : the issues were caused by Bytes in formulas ; so I modified the type for some variables from Byte to Integer, and now it works ! I removed the "EPWrite" operations, they were only for debugging purposes. GC Basic seems to have problems when Byte variables are used with mathematical operations ...
    So You see : life is hard, even for rairoad modellers ! :)

     

    Last edit: Bertrand BAROTH 2020-08-04
  • Anobium

    Anobium - 2020-08-04

    I do believe this is a byte or integer issue. I just ported your new Dire_phrase() to the test code I wrote. I get the same output for byte or integet definition for compteur_local.

    I still think this is not the correct root cause of the issue.

    Create a program with the Byte and one with Integer. Post the ASM from both programs. This will help understand the root cause.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    A least it works ... Here is the ASM with integer.

     

    Last edit: Bertrand BAROTH 2020-08-04
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-04

    And here with byte ...

     
    • Anobium

      Anobium - 2020-08-05

      There are more than just the one change to the variable type in these ASM's?

      GARE, MARCHE_AVANT, NUMERO_ANNONCE_LOCAL, NUMERO_MESSAGE_LOCAL all of a different variabletype - from BYTE to eiher word or integer.

      So, from the two ASMs I cannot figure out what the root cause is.

      Can you upload the GCB source file?

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-05

    Despite of the fact that I don't really understand Your question, here is the final source ... You can change the variables that You want to Byte.

     
  • Anobium

    Anobium - 2020-08-05

    I am surprised the code works.

    At line 72 your declare Dim numero_message_local As Integer then pass this integer variable to Dire_phrase() at line 80 as a byte - as in Sub Dire_phrase (In numero_expression As Byte, In attente As Byte)

    I still do not see how I can resolve the bug without a test case that is valid.

    Close the issue as all is working?My working assumption is: There this is an overflow issue that your changes resolved.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-05

    OK, I close the thread because it works now ; but I think that, since error occured already in Dire_phrase with numero_message_local declared as Byte (when I saved the calculated value in EEProm), one should avoid calculations involving Bytes ; now I declared numero_message_local as Word, and numero_expression as Word too in the header of Dire_phrase, and it works ...

     
    • Anobium

      Anobium - 2020-08-05

      I will close. But, I found no evidence of a byte handling issue. The code I produced did not reproduce the error - this is probably as your workaround with the use of different types of variables is masking the problem.

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-05

    The very first version of the prog used ONLY Bytes and Strings ... and made calculation errors INSIDE of the Sub Annonces_trains : the result was pure fantasy for Case 1 ...

     
  • Anobium

    Anobium - 2020-08-06

    BUG FOUND: At releases prior to release v0.98.07 always add CONSTANTS at the end of the numerical calculation.

    As follows: Where 1 is the constant.
    numero_message_local = Marche_avant + gare + 1

    This will fail to yield the correct result: Where the constant 1 is the first number in the maths calc.

    numero_message_local = 1 + Marche_avant + gare


    This issue is AVR only and does not impact the PIC.
    I will look to resolve in v0.98.07 meanwhile alway put CONSTANTS at the end of the line of numeric calculations.

    Anobium

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2020-08-06

    I am happy that I could contribute to resolve a bug ...

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.