|
|
View previous topic :: View next topic |
Author |
Message |
simat
Joined: 05 Feb 2008 Posts: 7
|
|
Posted: Thu Aug 07, 2008 1:20 pm |
|
|
I've just trimmed my code to the minimum as suggested by PCM Programmer and the WDT sleep function now works, I need to investigate this further.
Thanks. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Aug 08, 2008 2:19 am |
|
|
OK, so you didn't show the code where it is reset !
Also, you are correct it will go from 255 to 0 but your buffer size is 64 so if it ever reached 65 it will overrun the buffer and corrupt ram.
Assuming it never overruns and radiostatus is set to 2 at an appropriate place so it enters the if statement, what happens ? Your original post said it displays "POL" twice and then stops. As this is also commented out can we have an update, first all the relevant code without missing bits and a comment on what the problem with the shown code is.
Cheers. |
|
|
simat
Joined: 05 Feb 2008 Posts: 7
|
|
Posted: Wed Aug 27, 2008 5:40 am |
|
|
Thanks for the replies,
The problem turns out to be a possible problem with the STATUS register not being set correctly when returning from sleep. If I declare cycle and radiostatus as global variables instead of in MAIN they are moved closer to the top of memory and the problem is fixed.
I noticed that BSF 03.6 - bank select in status register isn't set correctly after sleeping maybe ??
ASM Code below before and after fixed.
Code: | .................... if(cycle > 2 && radiostatus >= 2) // FYI - cycle incremented below.
0C37: BSF 03.6
0C38: MOVF 6B,W
0C39: SUBLW 02
0C3A: BTFSC 03.0
0C3B: GOTO 476
0C3C: MOVF 6A,W
0C3D: SUBLW 01
0C3E: BTFSC 03.0
0C3F: GOTO 476
.................... delay_ms(10); // Enought time for xmit of 5 bytes at 19200 BPS // Trim this right down to the essential minimum
0C40: MOVLW 0A
0C41: BSF 03.5
0C42: MOVWF 2C
0C43: BCF 0A.3
0C44: BCF 03.5
0C45: BCF 03.6
0C46: CALL 768
0C47: BSF 0A.3
....................
.................... cycle = 2; // for some weird reason we need this.
0C48: MOVLW 02
0C49: BSF 03.6
0C4A: MOVWF 6B
....................
.................... while (cycle > 0) { // need to wait for transmit buffer to finish before we sleep...
0C4B: MOVF 6B,F
0C4C: BTFSC 03.2
0C4D: GOTO 452
.................... sleep();
0C4E: SLEEP
.................... delay_cycles(1);
0C4F: NOP
.................... cycle--;
0C50: DECF 6B,F
.................... }
0C51: GOTO 44B |
Cycle at 0x16B and Radiostatus at 0x16A
and now with variables declared as global
Cycle at 0x2D and Radiostatus at 0x2C - note BSF 03.6 is not needed..
Code: | .................... if(cycle > 2 && radiostatus >= 2) // FYI - cycle incremented below.
0C35: MOVF 2D,W
0C36: SUBLW 02
0C37: BTFSC 03.0
0C38: GOTO 471
0C39: MOVF 2C,W
0C3A: SUBLW 01
0C3B: BTFSC 03.0
0C3C: GOTO 471
.................... delay_ms(10); // Enought time for xmit of 5 bytes at 19200 BPS // Trim this right down to the essential minimum
0C3D: MOVLW 0A
0C3E: BSF 03.5
0C3F: BSF 03.6
0C40: MOVWF 2C
0C41: BCF 0A.3
0C42: BCF 03.5
0C43: BCF 03.6
0C44: CALL 768
0C45: BSF 0A.3
....................
.................... cycle = 2; // for some weird reason we need this.
0C46: MOVLW 02
0C47: MOVWF 2D
....................
.................... while (cycle > 0) { // need to wait for transmit buffer to finish before we sleep...
0C48: MOVF 2D,F
0C49: BTFSC 03.2
0C4A: GOTO 44F
.................... sleep();
0C4B: SLEEP
.................... delay_cycles(1);
0C4C: NOP
.................... cycle--;
0C4D: DECF 2D,F
.................... }
0C4E: GOTO 448 |
Could this be a compiler bug ? I'm on 4.057.. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|