Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : More interrupt fun...
Author | Message | ||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Hi all. My latest interrupt madness, is trying to setup periodic interrupts via the SetTick command, to update the on-screen clock and pulse the external WDT. SetTick 1000,DAT SetTick 2000,WDT SetPin A1,8 Do:Loop WDT: Pulse A1,100 IReturn DAT: Print @(25,205) Time$;" - ";Date$ IReturn ...but nothing is happening. According to the manual, page 32, under SETTICK command, and with respect to the DAT routine, 1000 should mean that this interrupt will take effect every second, and that it should loop to the DAT(Date And Time) routine, which should print the date and time, then it should return from the interrupt. The problem is, that the looping never happens. Unlike my other thread about DO/LOOP, this time I DO have something getting printed inside the interrupt loop, so I should be seeing the time and date updating every second on the screen, I would have thought. Can anyone throw any light on what I am doing wrong? Thanks. Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
The current version of MMBasic only has one SETTICK available In your code, the second line cancels the first line. This should give you what you are after. The WDT sub is called every secont time DAT is run SetTick 1000,DAT
SetPin A1,8 Do:Loop WDT: Pulse A1,100 Return DAT: Print @(25,205) Time$;" - ";Date$ W=1-W if W=0 then gosub WDT IReturn Jim VK7JH MMedit MMBasic Help |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Depending on your firmware level you may only be allowed one SETTICK in a program so it will do the WDT routine because it was last defined. I think some of the BETAs floating around have more than one settick but given they are beta and you are serious then you should stay away until they are release level. |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Ah, what is happening here is that with version 4.3a you can only have one tick timer running at a time (in 4.4 when it comes out you will be able to specify up to four). You should set up only one tick timer and count within the interrupt to tell if you should print the time out. For example: SetTick 1000,DAT SetPin A1,8 Do:Loop WDT: Pulse A1,100 TickCouunt = TickCouunt + 1 if TickCouunt >= 2 Then TickCouunt = 0 if TickCouunt = 0 then Print @(25,205) Time$;" - ";Date$ IReturn TickCouunt is used to count the number of calls to the WDT function and is reset to zero when the required number of calls has occurred (in this case 2 calls). This means that the time will only print on alternative calls to WDT (ie, every two seconds). Changing the comparison to this: if TickCouunt >= 5 Then ... means that the time will then print every five seconds. Geoff EDIT: In the time that it took me to write this others also provided a good answer. Geoff Graham - http://geoffg.net |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Ahhhhhhhhhh! Great, thanks a bunch guys. I will play with the sample routines. Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Here is my revised test code, which IS WORKING. SetTick 1000,DAT SetPin A1,8 Cls Mode 4 Print "READY." Do:Loop 'Simulation of other things going on in the code End DAT: Print @(25,100) Time$;" - ";Date$ WDTC=WDTC+1 'Increment WDT counter If WDTC=5 Then Pulse A1,150 'Pulse WDT every five seconds Print "Pulse." 'Only for testing - this line will be removed WDTC=0 'Once WDT has been pulsed, reset the counter Else EndIf IReturn Smoke makes things work. When the smoke gets out, it stops! |
||||
greybeard Senior Member Joined: 04/01/2010 Location: AustraliaPosts: 161 |
Your watchdog reset routine should be called from your main code loop rather than from an interrupt routine. Reason being that your main code loop could crash and/or stall but the interrupt routine is still being called ( in this case by the main MM code that is interpreting your Basic code ) and would be resetting your watchdog. Which pretty much defeats the purpose of having a watchdog routine |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Yes, I wanted to put the WDT there in the first place, but the way I have written the code does not allow it. The main loop, is just a main menu screen. - Draw screen - Gosub WFK(wait for key) which waits for a keypress - Act on keypress I tried putting the WDT pulse in the main loop, but it only pulses once someone has pressed a key - I would expect that, as the WFK does not return until someone HAS pressed a key. Next, I tried putting the WDT pulse inside the WFK routine, but MMBASIC complained about their being too many concurrent pulse commands, and the program stops. I could understand that too, as WFK just loops around and around, waiting for a keypress - ANY keypress. The main loop decides what that keypress is, once WFK returns with the value of the keypress in KEY$. I will still take your advise though, and see if I can move it somehow. As I developed the code, WFK ended up with the keypress detection routine, and also the code to draw the clock and date on the screen. The date and time code has now been separated from this loop, and linked to a SetTick interrupt, as mentioned above. I thought I might as well pulse the WDT at the same time as updating the clock(or thereabouts). But you are right - I need to move this somewhere else and FIND a way to make it work in the main loop, cos one of things I was going to have happen, was for the WDT to reset the system, if someone goes into a sub-menu on the screen, but then(for whatever reason), does not come back to the main menu. The WDT will time-out in these cases, reset the PIC32, and restart the program at the main menu without Human intervention. Currently, this won't happen in the above example for precisely the reason you mentioned. I will work on it. Above code was example only, to teach me how to make it work - now I will have a serious go at porting the date and time part to the main code. Smoke makes things work. When the smoke gets out, it stops! |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
I think the ON KEY interrupt would be a perfect command for what you want to do. Combine it with a FSM (Finite-State Machine) to make it simple and easy to maintain and test. Google gives you lots of hits for FSM's. Microblocks. Build with logic. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Cool, thanks. Never heard of an FSM - will read some links... Smoke makes things work. When the smoke gets out, it stops! |
||||
Print this page |