Technical discussions about Freescale Microcontrollers: M68HC11. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Hi, Could someone explain how to create a software interupt. I have set up a timer to (eventually) log the A/D every 15 minutes. I have used the TCNT to do this. I am unsure how to use the SWI to interupt the program every 15 minutes. Many thanks Bal |
|
|
|
I have used the TCNT to do this. I am unsure how to use the SWI to interupt the program every 15 minutes. ========================== I'd do this 1 of 2 ways: set up a 1 ms interrupt and count 1000 of them, , ten count secinds for 15 minutes. OR... use the TOF interrupt and count how many of those in a second. The SWI instruction is usually used to call a 'system call' as if a hw interrupt hit. It has a vector just like a hw interrupt. [Non-text portions of this message have been removed] |
|
----- Original Message ----- From: "bal_gill21" <> To: <> > Could someone explain how to create a software interupt. I have set > up a timer to (eventually) log the A/D every 15 minutes. I have used > the TCNT to do this. I am unsure how to use the SWI to interupt the > program every 15 minutes. You can't use the SWI instruction for anything other than invoking the SWI interrupt. There are no instructions to invoke the remaining interrupts. (There is the CFORC bit for forcing a premature Output Compare but that's a different story, forget I even mentioned it.) To setup a timer you can choose from: 1. Enable the Real Time Interrupt and keep a counter to know how much time elapsed. 2. Use an Output Compare and appropriate values to have it tell you when your predefined time has passed (you will know either by polling on a bit or by receiving an interrupt). 3. ... Timer Overflow, External clock chip, etc.... Since 15 minutes is a really long time (in the MCU world), there will be no single byte value that will get you a delay that big. You will have to use counters along with multiple interrupts until the time adds up to what you need. Here's a basic skeleton of what your code (related to the timer) should look like (not tested so it could contain some errors) using the RTI: ONE_SECOND equ 122 ;approx 1 second @ 2MHz bus ... RTIF. equ %01000000 ;RTI in TFLG2/TMSK2 ... basetimer rmb 2 ;put these in RAM area minutes rmb 1 ... ; Initialize the timer for the first event lda #15 sta minutes ldd #ONE_SECOND*60 std basetimer ... ; Enable the RTI for interrupts every 8.2ms (@ 2MHz bus) ldx #REGS lda [PACTL,x anda #%11111100 ;mask off RTR0:1 bits ora #%01 sta [PACTL,x bset [TMSK2,x,RTIF. ;Enable RTI subsystem ... ; This routine gets called every 15 minutes QuarterlyEvent ... rts ; Your RTI handler should look something like this: RTI_Handler lda #RTIF. sta TFLG2 ;Reset the RTI interrupt ldx basetimer dex stx basetimer bne RTI_Handler_Exit ;not yet a minute ldd #ONE_SECOND*60 ;for next minute timeout std basetimer dec minutes bne RTI_Handler_Exit ;not yet a quarter bsr QuarterlyEvent ;to be called every 15 minutes lda #15 sta minutes ;prepare for next quarter RTI_Handler_Exit rti org $FFF0 ; Vector for RTI dw RTI_Handler *** Ignore my own assembler's special syntax (e.g., the "[") if you use another assembler. The symbols REGS, PACTL, and TMSK2 should be defined with EQU somewhere before this code segment. This is NOT a complete program, you'll have to add code to make it work. *** Hope this helps. > Bal |