I know effectively nothing about assembly. I don't think HPWM can be used like that on sequential pins. I would try something interrupt based, like this:
Code:
'16F1825
Define OSC 32
'32 MHz
'= 8 MHz instruction time
'= 0.000000125 s/instruction
'= 0.000125 ms/instruction
'= 0.125 us/instruction
'So, 320 us = 2560 clocks
'Set up Timer1
T1CON = %00000001
' |||||||1 - TMR1ON
' ||||||0 - Unimplemented
' |||||0 - T1SYNC: 1 = Do not synchronize external clock input
' ||||0 - T1OSCEN: 0 = Dedicated Timer1 oscillator circuit disabled
' ||00 - T1CKPS: 00 = 1:1 Prescale value
' 00 - TMR1CS: 00 = Timer1 clock source is instruction clock (FOSC/4)
PortOffset var byte
Cycles var byte
Pulse_cnt var byte
Pulse_cnt = 0
T var byte
bGo var bit
bGo = 0
T = 0
INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _TMR1_Handler, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE TMR1_INT ; enable the interrupt
'Load Timer 1 with value to make it interrupt after 320 us
'for 320 us delay, want 2560 clocks
' 65534 - 2560 = 62974
' subtract ~7 more to account for the time to load the timer = 62967
' in hex, = $F5F7
TMR1H = $F5
TMR1L = $F7
'Main Loop
Main:
if bGo = 1 then
LOOKUP T, [1,2,4,5,16,17,18,19,20,21],PortOffset ' Offsets from Port A to point to port A and port C I/O ports ( number of offset relates to bits offset in mem map of chip)
Cycles = 0 ' Set to 0
for Cycles = 1 to Pulse_cnt ' Each IR led increments the amount of pulses by 2 for IR LED ID use
PORTA.0[PortOffset] = 1 ' Set IR LED High
pauseus 2 ' Remain on for 2uS
PORTA.0[PortOffset] = 0 ' Set IR LED Low
pauseus 9 ' remain off for 9uS
next Cycles
Pulse_cnt = Pulse_cnt + 2 ' increment pulse count by offset of 2 for each IR LED
T = T + 1
if T = 10 then
T = 0
endif
bGo = 0
endif
goto main
TMR1_Handler:
'Re-load Timer1
TMR1H = $F5
TMR1L = $F7
bGo = 1
@ INT_RETURN
Untested but it compiles...
Best Regards,
Paul
Bookmarks