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 ...
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 ?
????
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 !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ...
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
#chipmega328p, 16
#include<uno_mega328p.h>
#OptionExplicit' Constantes et variables
#Include<SoftSerial.h>
#DefineSER1_TXPORTPortD
#DefineSER1_TXPIN1
#DefineSER1_RXPORTPortC
#DefineSER1_RXPIN0
#DefineSER1_BAUD9600
#DefineSER1_DATABITS8
#DefineSER1_STOPBITS1
#DefineSER1_INVERTOff
#DefineGare_haut10
#DefineGare_bas0DimAnnoncer_trainsAsByteDimGareAsByteDimMarche_avantAsByteDimTampon_ledsAsByteDimTestASByteDimTravailAsByteDimchaine_localeAsString*5Dimcompteur_localAsByteDimtampon_ADAFAsString*20Dimnumero_motAsByteDimAttenteAsByte' --------------------------------------------------------------------SubAttente_ADAF()' Attente handshake ADAFDoTest=Ser1ReceiveLoopUntil(Test=100)EndSub' --------------------------------------------------------------------SubDire_phrase()' Dit le mot numéro "numero_mot"EPWrite2, numero_motchaine_locale=right("0"+Trim(Str(numero_mot)), 2)Tampon_ADAF="PMESSAG"+chaine_locale+"WAV"+chr(10)Forcompteur_local=1toLen(Tampon_ADAF)Ser1SendTampon_ADAF(compteur_local)Next' If (attente <> 0) Then Attente_ADAF ()EndSub' --------------------------------------------------------------------SubAnnonces_train(Innumero_annonce_localAsByte, Inattente_localeAsByte)' Annonce du train en gareSer1Send9Ser1Printnumero_annonce_localSer1Send9Ser1Printattente_localeDimnumero_message_localAsByteEPWrite0, numero_annonce_localIf(Annoncer_trains<>0)ThenSelectCasenumero_annonce_localCase1 : numero_message_local=1+Marche_avant+gareCase2 : numero_message_local=3+Marche_avant+gareCase3To4 : numero_message_local=2+numero_annonce_local+gareEndSelectSer1Send9Ser1Printnumero_message_localNumero_mot=numero_message_localAttente=attente_localeEPWrite1, numero_message_localDire_Phrase()EndIfEndSub' --------------------------------------------------------------------' Programme principalwait2sSer1Send10Ser1Send13Ser1Print"Test3"Ser1Send10Ser1Send13wait100ms' ERV Commented out to debug' PortD = 0b11111111' DdrD = 0b00000000DdrB=0b00001111PortB=0b11110110Annoncer_trains=1Gare=Gare_basMarche_avant=1Tampon_leds=0b11110110Boucle:
' ERV Commented out to debug' Dir PortD in' Travail = PinDdimindexloopasByteforindexloop=0to7Travail=255Travail.indexloop=0Ser1Print"Travail: 0b"Ser1PrintByteToBin(Travail)Ser1Print" 0d"Ser1PrintTravailPortB=Tampon_ledsIf(Travail.7=0)ThenAnnonces_train(1, 1)' GoTo BoucleEndIfIf(Travail.6=0)ThenAnnonces_train(2, 1)' GoTo BoucleEndIfIf(Travail.5=0)ThenAnnonces_train(3, 1)' GoTo BoucleEndIfIf(Travail.4=0)ThenAnnonces_train(4, 1)' GoTo BoucleEndIfIf(Travail.3=0)ThenMarche_avant=1Tampon_leds.3=0Tampon_leds.2=1' GoTo BoucleEndIfIf(Travail.2=0)ThenMarche_avant=0Tampon_leds.3=1Tampon_leds.2=0' GoTo BoucleEndIfIf(Travail.1=0)ThenGare=Gare_hautTampon_leds.1=0Tampon_leds.0=1' GoTo BoucleEndIfIf(Travail.0=0)ThenGare=Gare_basTampon_leds.1=1Tampon_leds.0=0' GoTo BoucleEndIfSer1Send10Ser1Send13wait10msNext
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ! :)
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.
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
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 !
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
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
Hi.
I can see nothing in the code (yet).
Change line 57 from
chaine_locale = Mid (Tampon_ADAF, compteur_local, 1)
tochaine_locale = Tampon_ADAF(compteur_local)
This will rule out any issues in the MID() function. Test.Change line 58 from
Ser1Print
toSer1Send
. This will rule out any issues with in Ser1Print.You could simply use
Ser1Print Tampon_ADAF(compteur_local)
Annonces_train
first parameter can1
to4
and this setsnumero_annonce_local
. So the case statement should work.But, you have
Marche_avant
andgare
changing. WhereMarche_avant
is 1 or 0, andgare
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.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
Memory allocation of variables ? You can test the prog, it runs without the hardware connected ...
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 ofnumero_message_local
. I think this value is not correct.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?
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
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
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.
A least it works ... Here is the ASM with integer.
Last edit: Bertrand BAROTH 2020-08-04
And here with byte ...
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?
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.
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 inSub 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.
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 ...
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.
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 ...
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
I am happy that I could contribute to resolve a bug ...