As per a request by Xan I wrote a version of the DIY transmitter code that used a timer (in this case wtimer) to generate the pulses that go to the transmitter. This should allow for some minor interrupt processing to happen, without throwing off the timings. Not sure if it is an improvement for normal use, but here is a version of the function GeneratePulses.
[code];------------------------------------------------------------------------------
; Generate Pulse function
;
; Variables used: ChanVals array has the pulse widths in us
GeneratePulses:
#ifndef DO_OLD_WAYS
; fudge the values. It looks like the transmitter may not fully accuratly take
; the signals in and give them out 100% correctly. So try to fudge…
for iFudge = 0 to 6
ChaVals(iFudge) = chaVals(iFudge) - 2 + (ChaVals(iFudge)-988)/70
next
output DM8PPM
; The DM8PPM pin should already be configured for output...
; This is P15 on BAP which is P87 on the underlying H8/3694
; transistion to assembly language.
; fist setup loop counters and the like before we manipulate the IO port
; we will use TimerW to do our timings for us. The idea is that
; we will configure it to increment on every 8th clock so .5us. We will then keep track of what time
; we will expect a transistion, and then do it when we make or exceed that time. This should keep
; us on track whenever some interrupt handler might eat some of our time.
TCRW = 0x30 ; divides the clock by 8
; transistion to ASM.
mov.l #CHAVALS:32, er3 ; er3 has pointer to our array of desired values
mov.b #7, r2l ; r2l has count of how many channels we wish to output
bset.b #7,@PCR8:8 ; make sure set to output, basic should have done earlier!
xor.w r1, r1 ; zero out the clock count. this will be compared to the TCNT
mov.w r1, @TCNT:16 ; zero out TCNT to start off with.
bset.b #7, @TMRW:8 ; make sure the clock is running.
bset.b #7,@PDR8:8 ; (L8)set P15 high (Low over head here 26)
_MP_LOOP:
add.w #400, r1 ; Value the timer should go up to for this high pulse
_MP_HIGH_PULSE_LOOP:
mov.w @TCNT:16,r0 ; get the current count
cmp.w r0, r1 ; see if we got to the desired time
bgt _MP_HIGH_PULSE_LOOP:8 ; still more to go.
bclr.b #7,@PDR8:8 ; (H8) Go low again - so high overhead here (26)
mov.w @er3+, r0 ; Get the wait time in uS
sub.w #400, r0 ; (L4) subtract off our high pulse widths..
shll.w r0 ; Multiply by 2 to get to .5uS to match timer scale
add.w r0, r1 ; calculate the new transistion time
_MP_LOW_PULSE_LOOP:
mov.w @TCNT:16,r0 ; 6 get the current count
cmp.w r0, r1 ; 2 see if we got to the desired time
bgt _MP_LOW_PULSE_LOOP:8;4 still more to go.
bset.b #7,@PDR8:8 ; (8)set P15 high before testing to see if we are done to keep timing correct
dec.b r2l ; (L2) decrement our counter for how many items to output
bne _MP_LOOP:8 ; (L4) still more channels to output
; loop is done, need to do trailing pulse
add.w #400, r1 ; Value the timer should go up to for this high pulse
_MP_LAST_HIGH_PULSE_LOOP:
mov.w @TCNT:16,r0 ; get the current count
cmp.w r0, r1 ; see if we got to the desired time
bgt _MP_LAST_HIGH_PULSE_LOOP:8 ; still more to go.
bclr.b #7,@PDR8:8 ; (8) Go low again
; will fall through to return and transition back into basic
return[/code]
As before the pulse widths may need to be slightly tweeked in order to get it to match… Also could also tweek this code slightly to test for .25uS instead of .5uS but would need to either use the overflow bit of the timer or reset the counter…
Kurt