This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Entering IDLE mode within Timer0

To keep very accurate timing during ACTIVE and IDLE modes I would like to push the core into IDLE mode and pull it out within Timer0. When I try to do this the system hangs. If I simply set a flag and have the main loop set PCON.IDLE it works fine. It is written in assembler and I am checking the push/pop stuff. I think the problem is in RETI. What happens to the hardware with RETI? Any help or pointers would be great.

Parents
  • Hi Michael,

    There are some problems with the code you have posted, your routine ?enter_idle does things in the wrong order, the POP PSW and POP ACC will NEVER be executed because the processor is in idle mode so obviously? the stack will eventually overflow and may cause problems in other parts of your program. You also need to remove the Timer0 ISR return address off the stack so if you modify your code from where timer is reloaded to be as follows it should work better for you.

    	MOV  	TH0,#TIMER0_ACTIVE_H	; set Timer0 counters
    	MOV  	TL0,#TIMER0_ACTIVE_L
    
    	POP		AR7
    	POP		AR6
    ; Put return address to code on stack
    	MOV     A, #LOW(?enter_idle)
    	PUSH    ACC
    	MOV     A, #HIGH(?enter_idle)
    	PUSH    ACC
    	RETI
    
    ?enter_idle:
    	POP  	PSW
    	POP  	ACC
    	DEC		SP				;remove original 'return from interrupt' address
    	DEC		SP
    
    
    	ORL  	X32CON,#01H		; switch to 32kHz clock
    
    ; wait 3 clock periods (3/4 of a instruction cycle) for glitch
    ; free operation, Datasheet p33
    	NOP
    	MOV  	RFMAIN,#03EH	; power down the RF and main osc
    	ORL     PCON, #0x01                     ; Enter idle mode
    	NOP                                     ; For safety
    ;	RET										; Can never be executed!
    	END
    

    Mark :-)

Reply
  • Hi Michael,

    There are some problems with the code you have posted, your routine ?enter_idle does things in the wrong order, the POP PSW and POP ACC will NEVER be executed because the processor is in idle mode so obviously? the stack will eventually overflow and may cause problems in other parts of your program. You also need to remove the Timer0 ISR return address off the stack so if you modify your code from where timer is reloaded to be as follows it should work better for you.

    	MOV  	TH0,#TIMER0_ACTIVE_H	; set Timer0 counters
    	MOV  	TL0,#TIMER0_ACTIVE_L
    
    	POP		AR7
    	POP		AR6
    ; Put return address to code on stack
    	MOV     A, #LOW(?enter_idle)
    	PUSH    ACC
    	MOV     A, #HIGH(?enter_idle)
    	PUSH    ACC
    	RETI
    
    ?enter_idle:
    	POP  	PSW
    	POP  	ACC
    	DEC		SP				;remove original 'return from interrupt' address
    	DEC		SP
    
    
    	ORL  	X32CON,#01H		; switch to 32kHz clock
    
    ; wait 3 clock periods (3/4 of a instruction cycle) for glitch
    ; free operation, Datasheet p33
    	NOP
    	MOV  	RFMAIN,#03EH	; power down the RF and main osc
    	ORL     PCON, #0x01                     ; Enter idle mode
    	NOP                                     ; For safety
    ;	RET										; Can never be executed!
    	END
    

    Mark :-)

Children
No data