> Ok I see that I cannot use Boolean in that way Bit is better
Yes, a boolean can only be "true" or "false". A bit can only be "1" or "0". Either declare as a bit, or convert to a boolean (typecast)
- Code: Select all
PulseState = cbool(D12)
> I have a lot of my background operations running in an interrupt..
OK, write your interrupt as normal. Let's say you want to modify the Tick() module to count milliseconds and trigger every 10ms (100 times a second) - you would have something like this:
- Code: Select all
// interrupt handler...
Public Event OnTick()
private Interrupt OnTimer(ipLow)
_time += 1
' testing against nothing will remove all code inside the
' if statement if no event handler is assigned in the main code
' block - so is optional, but recommended...
if OnTick <> nothing then
if _time mod 10 = 0 then ' trigger every 10 ms
RaiseEvent OnTick() ' raise event
end if
end if
// reload _timer...
dim timer as ushort
timer.Byte0 = TMR3L
timer.Byte1 = TMR3H
timer = timer + _reloadTimerValue
TMR3H = timer.Byte1
TMR3L = timer.Byte0
// clear interrupt flag
PIR2.1 = 0
End Interrupt
Note the public declaration "Public Event OnTick()". This is a place holder that will be assigned a subroutine in the main program. Then you have the actual code that will call the external event "RaiseEvent OnTick() ". Now, in your main program :
- Code: Select all
imports myTick
sub OnTickEvent() handles Tick.OnTick
toggle(D13)
end sub
sub Main()
'loop forever...
while true
end while
End Sub
Pretty much as the code says - OnTickEvent() will
handle Tick.OnTick(). Put your code inside the event as though it's inside your interrupt (don't forget though, context save rules still apply - i.e. you need to make sure you do not damage registers used by the main program!). Using this technique separates module code, so you can make them generic. Specific code can be handled by the main program. You could add a variable to the module so the event triggers at different frequencies, making it more adaptable. I've attached the resultant waveform. Note that frequency is 50Hz, as the event is triggered 100 times a second. Change the ISR code to
- Code: Select all
if _time mod 10 = 0 then
to display a 100Hz waveform (event triggered 200 times a second)