Hab die gleiche Frage schon ins MSC BASCOM Forum gepostet, drum ist der Post ausnahmsweise auf Englisch:
i'm currently working on a project based on interrupts, powersave mode and softclock and i experienced a very odd bug of some sort.
I'm using an ATmega88PA-PU running on it's internal 8Mhz RC-Oscillator, an EA-DOG-LCD and a 32kHz crystal connected to TOSC1 and TOSC2.
This is my initialisation:
And this is the code snippet in question:
Code: Alles auswählen
'init lcd Config Lcd = 16 * 2 , Chipset = Dogm162v5 , Contrast = &H74 Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portc.1 , Rs = Portd.0 Initlcd Cursor Off Cls 'init timer Config Clock = Soft , Gosub = Sectic Enable Interrupts Dim Secs As Byte Dim Test As Byte
So what this should do: refresh the LCD every two seconds, the upper value (Test) should be half the value of _sec, displayed on bottom of the LCD.
Code: Alles auswählen
'main loop Do If Secs = 2 Then Secs = 0 Incr Test Cls Upperline Lcd Test Lowerline Lcd _sec End If Powersave Loop End 'timer2 isr Sectic: Incr Secs Return
But what it does: nothing. nothing at all. nothing is ever displayed.
BUT - and that is weird - it works perfectly well in the simulation, and it also works on an ATmega8!
And a more elegant implementation 'temp = secs MOD 2 : if temp = 0 then ..' works as well.
I also found a few workarounds for the M88 which i don't understand:
If i insert 'waitms 200' before the 'do' of the main loop it displays the correct numbers but it runs at double speed!
So the LCD is updated every second and the _secs value is two times higher than it should be!
If the waiting time is 'too short' (~100ms) it does not work..
If i then insert another "waitms 1" in the timer2 ISR everything works just as it should and it runs at correct speed, displaying the correct numbers!
And it also works fine without the waiting but by removing the 'Powersave' instruction from the loop!
Can anyone explain what's happening there? I already replaced the M88 and the crystal so the problem doesn't seem to be limited to my hardware.
Am i missing something? Is this a bug in the BASCOM software or is the M88 not as backwards compatible to the M8 as it should be?
I would be very happy about any help because i need this to work in this hard- and software configuration!
Furthermore this bug already made worthless the code i already wrote and i don't need any further surprises of this kind!