StefanL38
10-14-2011, 08:31 PM
Hi,
my current project is "recording" IR-remote-signals in a special way.
I'm using an IR-receiver that is NOT decoding the carrier-frequency.
The Output of the TSOP98200 (http://www.google.de/url?sa=t&source=web&cd=2&ved=0CDgQFjAB&url=http%3A%2F%2Fwww.vishay.com%2Fdocs%2F84795%2Ft sop9820.pdf&ei=MZiYTvn1D4Gt8QO-yenoBQ&usg=AFQjCNGuGB391lMyVM2x65Hvlyl3nfFjAg) does still show all the single-pulses with carrier-frequency. (usually these receivers are used for lowest-level IR-repeaters re-emitting the carrier-signal)
Why am I using this one? Because I want to record all carrierfrequencies (30, 33, 36, 38, 40, 44, 50. 56 kHz) Because of this a standard demodulator with a fixed carrier-frequecy can't be used.
Now my current approach to to this is to measure the carrier-frequency of the first pulses.
Then setting up counterA to neg-edge-mode FRQA := 1 and then running a loop that looks for PHSA
beeing bigger than zero. This loop runs at a frequency of 8 times carrierfreuquency.
Whenever a carrier-pulse is detected a bit is added to a long But only at the carrier-frequency.
If 32 bits are put together this long will be stored into HUB-RAM.
This means each bit represents one carrier-pulse to reduce needed RAM.
Now the strange thing is that some pulses are not detected.
in the fixed-font part below you see a long row if "1"s but at two places 3 zeros inbetween.
(the bold red ones)
I re-checked with a digital storage oscilloscope (DSO) several times if these short "no carrier"-sequences are coming from the IR-receiver. The do not. The IR-receiver it self produces
a continious pulsetrain.
Know I'm puzzled why my PASM-loop is missing some pulses as the loop is running at 8 times higher speed as the pulses come in.
I'm using the counter which is independet of code-execution. The time between reading out PHSA and resetting PHSA to zero for the next cycle is pretty short.
Much shorter than a period. I even added another cog that strechtes the pulses from the IR-reiver from 1 microsecond up to half carrier-frequency (38kHz = 26 microseconds) Pulsewidth 13 microseconds.
How can it be that some pulses are detected as zero = no carrier-pulse? while there are carrier-pulses!
ser.start(30,31,0,115200) done
cognew(Toggle_Pin(0, 4),@ToggleStack)done
cognew(@entryMeasureFreq,0) done
ready for recording pulsetrain
wait for pulsetrain
wait for pulsetrain
11111111111111111111111111111111
11111111111111111111000111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11110001111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111100000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000001111
11111000111111111000000000000000
00000000000000000000000000000000
00000000000001111111111111111111
10000000000000000000000000000000
00000000000000000000000000000011
11111111111111111100000000000000
00000000000000000000000000000000
00000000000000111111111111111111
11000000000000000000000000000000
00000000000000000000000000000001
11111111111111111110000000000000
00000000000000000000000000000000
00000000000000011111111111111111
11100000000000000000000000111111
11111111111100000000000000000000
11111111111111111111000000000000
00000000000000000000000000000000
00000000000000001111111111111111
11110000000000000000000000000000
00000000000000000000000000000000
01111111111111111111100000000000
00000000011111111111111111111000
00000000000000000111111111110001
11111100000000000000000000111111
11111111111111000000000000000000
00111111111111111111110000000000
00000000001111111111111111111100
00000000000000000001111111111111
11111110000000000000000000011111
11111111111111100000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
recording of pulsetrain done
clockticks from pulse to pulse TestVar1 2090
_Period_8tel TestVar2 261
I attach my full testcode as a ZIP-archive.
and here is the interesting part of the PASM-code
edit:
arrrgh!! What is this forum-software doing with my well-fomatted fixed-font code????
Even when I copy it back from the forumsoftware-editor field and paste it into the propeller-tool
everything looks fine again. Only when showing it in the forum the columms jump back and forth like they want.
Forum-Administrator !! Get the forum-software-guy up and solving this problem!!!
DAT
ORG 0
entryMeasureFreq
{
' --------- Debugger Kernel add this at Entry (Addr 0) ---------
long $34FC1202,$6CE81201,$83C120B,$8BC0E0A,$E87C0E03,$8 BC0E0A
long $EC7C0E05,$A0BC1207,$5C7C0003,$5C7C0003,$7FFC,$7FF 8
' --------------------------------------------------------------
}
StartOfCode call #SetOutPuts
call #Read_SPIN_CmdM
call #SetupCounterMode
'initialise variables for recording IR-signalstates
mov _IR_Recv_Long, #0 'reset long containing bits of sampled pulsetrain
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2HUB_RAM_Buff
mov _HUB_Act_Idx, _HUB_Base_AdrM 'Reset BufferIndex to baseadress
mov _Buff_Count, _BuffSize 'setup variable for buffer-filling-loop
mov _32Bit_Count, #c_NoOfBitsPerLong 'setup variable for filling long with IR-statebits
mov _Period_8Cycl, #0
mov _CarrierOnFlag, #0
mov _CarrierONCnt, #0
mov _CarrierOffCnt, #0
mov _NrOfPulses, #0
mov _LastNoOfPulses,#0
mov _NewNoOfPulses, #0
mov _SumOfPulses, #0
mov _PeriodFrac, #1
shl _PeriodFrac, #c_Divisor '_PeriodFrac contains the fractional how often
call #MeasureCarrierFreq
'coming back from this subr means new carrier-period starts right now
'the counter is already prepared through a mov PHSA, #0 to catch the next high-to-low-transition
'and PHSA containing 1 (and not a highrer value)
mov _TestVar1M, #0'_Period
mov _TestVar2M, _Period_8tel
mov _SPIN_CmdM, #1 'set Status to 0 to indicate command finished
call #Write_SPIN_CmdM
xor OutA, _LED_RightM 'set bit "_LED_LeftM" in OutA-register to 1
mov PHSA, #0
Record_IR_Bits_Loop
waitcnt _MFlopMatch, _Period_8tel 'wait for 1/8 of a period
mov _NrOfPulses, PHSA 'PHSA holds actual sum of pulses update actual number of pulses
add _Period_8Cycl, #1 'increment number of Period 8th cycles
cmp _Period_8Cycl, _PeriodFrac wz 'check if a complete period is over
if_nz jmp #Record_IR_Bits_Loop 'only if period is over do the rest
mov PHSA, #0
mov _Period_8Cycl, #0 'reset loopcounter
cmp _NrOfPulses, #1 wc 'check if there were new pulses
if_c mov _IR_Recv_Bit, #0 'no pulse received => set IR_Recv_Bit to 0
if_nc mov _IR_Recv_Bit, #1 'a pulse received => set IR_Recv_Bit to 1
add _IR_Recv_Long, _IR_Recv_Bit 'add actual bit to long
sub _32Bit_Count, #1 wz 'check for last loop within actual long
if_nz shl _IR_Recv_Long, #1 'if not last bit shift bits 1 to the left
if_z call #WriteLongToBuffer
if_z sub _Buff_Count, #1 wz 'if byte was written to buffer decrement _Buff_Count by one
if_z jmp #Recording_finished 'if _Buff_Count reaches zero buffer is full
'mov _NrOfPulses, PHSA 'PHSA holds actual sum of pulses update actual number of pulses
'cmp _NrOfPulses, #1 wc 'check if there were new pulses
'if_nc or OutA, _VPTriggerPin 'if _NrOfPulses is >= 1 then the C-Flag is cleared
'if_nc add _TestVar1M, #1
jmp #Record_IR_Bits_Loop
Recording_finished
mov _TestVar1M, _Period
'mov _TestVar2M, _Snapshot2
'sub _TestVar2M, _Snapshot1
mov _SPIN_CmdM, #0 'set Status to 0 to indicate command finished
call #Write_SPIN_CmdM
infLoop nop
jmp #infLoop
'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS SSSSSSSS
'# START Subroutines
'################################################# ########
SetOutPuts mov _BitMaskM, _LED_LeftM
or _BitMaskM, _LED_MiddleM
or _BitMaskM, _LED_RightM
'or _BitMaskM, _MonoFlopPin
or _BitMaskM, _VPTriggerPin
or _BitMaskM, _toggleBit
or DirA, _BitMaskM 'set bits of BitMakM in DirA-register to 1
andn OutA, _BitMaskM 'clear bits of BitMakM in OutA-register to 0
SetOutPuts_ret ret
'---------------------------------------------------------
'################################################# ########
SetupCounterMode 'setup counter-mode and initialise INcS-Register and TSUM-register
' 3 2 1
'10987654321098765432109876543210
'10987654321098765432109876543210
'%-CMODEPLL--------B__PIN---A__PIN
'%00111000000000000000000000000011
movi CTRA, #c_NegEdgeDetectorNoPLL 'setup counter for negative-edge-mode
movs CTRA, #%000000010 'sense IO-pin 2
mov FRQA, #1 'load summand-register with 1
mov PHSA, #0 'load summerise-register with 0
SetupCounterMode_ret ret
'---------------------------------------------------------
'################################################# ########
MeasureCarrierFreq
or OutA, _LED_LeftM 'set bit "_LED_LeftM" in OutA-register to 1
cmp _TestVar2M, #120 wz
if_z jmp #PresetPeriod
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
WaitIRPinLow waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _FirstPulse, cnt 'take snapshot of free running systemcounter
or OutA, _LED_MiddleM 'set bit "_LED_MiddleM" in OutA-register to 1
mov _InputStateM, #8 'load bitpattern that should be matched
WaitIRPinHigh waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
WaitIRPinLow2 waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _SecondPulse, cnt 'take snapshot of free running systemcounter
andn OutA, _LED_LeftM 'clear bit "_LED_LeftM" in OutA-register to 0
mov _Period, _SecondPulse
sub _Period, _FirstPulse 'calculate clockticks of pulsedistance (=carrier-frequency)
mov _Period25, _Period
shr _Period25, #c_Divisor 'shr c_Divisor bits to the right means divide by 2^c_Divisor
jmp #here
PresetPeriod mov _Period, _2000
mov _Period_8tel, _Period
shr _Period_8tel, #c_Divisor 'shr 3 bits to the right means divide by 2^3 = 8 - 1/8 of a period
mov _MFlopMatch, _SecondPulse 'copy value of systemcounter-snapshot before
add _MFlopMatch, _Period 'add clockticks of 1 period
sub _MFlopMatch, _AheadTicks 'substract clockticks to be ahead of the next high-to-low-transition
mov PHSA, #0 'prepare counter to detect high-to-low-transition
or OutA, _LED_MiddleM 'set bit "_LED_LeftM" in OutA-register to 1
jmp #MeasureCarrierFreq_ret
here mov _Period_8tel, _Period
shr _Period_8tel, #c_Divisor 'shr 3 bits to the right means divide by 2^3 = 8 - 1/8 of a period
'wait until next pulse-period begins
mov _MFlopMatch, _SecondPulse 'copy value of systemcounter-snapshot before
add _MFlopMatch, _Period 'add clockticks of 1 period
sub _MFlopMatch, _AheadTicks 'substract clockticks to be ahead of the next high-to-low-transition
waitcnt _MFlopMatch, _Period
mov PHSA, #0 'prepare counter to detect high-to-low-transition
or OutA, _LED_MiddleM 'set bit "_LED_LeftM" in OutA-register to 1
MeasureCarrierFreq_ret ret
'---------------------------------------------------------
'################################################# ########
WriteLongToBuffer
wrlong _IR_Recv_Long, _HUB_Act_Idx 'write long to HUB-RAM
add _HUB_Act_Idx, #4 'set HUB-RAM-adress to next long
mov _IR_Recv_Long, #0 'reset long that contains sampled bits of pulsetrain
mov _32Bit_Count, #c_NoOfBitsPerLong 'setup variable for filling long with IR-statebits
WriteLongToBuffer_ret ret
'---------------------------------------------------------
'################################################# ########
ReSyncToCarrier
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _MFlopMatch, cnt 'new snapshot of systemcounter
add _MFlopMatch, _Period
sub _MFlopMatch, _AheadTicks
or OutA, _DebugPin
add _TestVar2M, #1
waitcnt _MFlopMatch, _Period
'mov _IR_Recv_Bit, #1 'resyncing means a pulse has occurred so set _IR_Recv_Bit to 1
ReSyncToCarrier_ret ret
'---------------------------------------------------------
'################################################# ########
Read_SPIN_CmdM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2_S2A_Cmd
rdlong _SPIN_CmdM, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar1
rdlong _TestVar1M, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar2
rdlong _TestVar2M, _HUB_Base_AdrM
Read_SPIN_CmdM_ret ret
'---------------------------------------------------------
'################################################# ########
Write_SPIN_CmdM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar1
wrlong _TestVar1M, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar2
wrlong _TestVar2M, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2_S2A_Cmd
wrlong _SPIN_CmdM, _HUB_Base_AdrM
Write_SPIN_CmdM_ret ret
'---------------------------------------------------------
_IR_Recv_Pin2 long |< 3
_MonoFlopPin long |< c_IR_Recv_Pin
_DebugPin long |< 5
_VPTriggerPin long |< 6
_10microSecs long c_10microSecs
_toggleBit long |< c_C3_LED
_LED_LeftM long |< c_LED_Left
_LED_MiddleM long |< c_LED_Middle
_LED_RightM long |< c_LED_Right
_BuffSize long c_Buffer_Size
_zero long 0
_AheadTicks long c_AheadTicks
_CarrierOnFlag long 1
_2000 long 2000
_SPIN_CmdM res 1
_TestVar1M res 1
_TestVar2M res 1
_HUB_Act_Idx res 1
_HUB_Base_AdrM res 1
_Buff_Count res 1
_32Bit_Count res 1
_FirstPulse res 1
_SecondPulse res 1
_Period res 1
_Period25 res 1
_Period50 res 1
_Period75 res 1
_MFlopMatch res 1
_EOSamplMatch res 1
_IR_Recv_Bit res 1
_IR_Recv_Long res 1
_InputStateM res 1
_BitMaskM res 1
_dummyLongM res 1
_NrOfPulses res 1
_LastNoOfPulses res 1
_NewNoOfPulses res 1
_SumOfPulses res 1
_MatchVal res 1
_Period_8tel res 1
_Period_8Cycl res 1
_CarrierOffCnt res 1
_CarrierONCnt res 1
_PeriodFrac res 1
_Snapshot1 res 1
_Snapshot2 res 1
I hope some PASM-gurus can explain to me why some pulses are missing and how I can
make 101% sure that not even a single pulse is missing.
keep the hints coming
best regards
Stefan
my current project is "recording" IR-remote-signals in a special way.
I'm using an IR-receiver that is NOT decoding the carrier-frequency.
The Output of the TSOP98200 (http://www.google.de/url?sa=t&source=web&cd=2&ved=0CDgQFjAB&url=http%3A%2F%2Fwww.vishay.com%2Fdocs%2F84795%2Ft sop9820.pdf&ei=MZiYTvn1D4Gt8QO-yenoBQ&usg=AFQjCNGuGB391lMyVM2x65Hvlyl3nfFjAg) does still show all the single-pulses with carrier-frequency. (usually these receivers are used for lowest-level IR-repeaters re-emitting the carrier-signal)
Why am I using this one? Because I want to record all carrierfrequencies (30, 33, 36, 38, 40, 44, 50. 56 kHz) Because of this a standard demodulator with a fixed carrier-frequecy can't be used.
Now my current approach to to this is to measure the carrier-frequency of the first pulses.
Then setting up counterA to neg-edge-mode FRQA := 1 and then running a loop that looks for PHSA
beeing bigger than zero. This loop runs at a frequency of 8 times carrierfreuquency.
Whenever a carrier-pulse is detected a bit is added to a long But only at the carrier-frequency.
If 32 bits are put together this long will be stored into HUB-RAM.
This means each bit represents one carrier-pulse to reduce needed RAM.
Now the strange thing is that some pulses are not detected.
in the fixed-font part below you see a long row if "1"s but at two places 3 zeros inbetween.
(the bold red ones)
I re-checked with a digital storage oscilloscope (DSO) several times if these short "no carrier"-sequences are coming from the IR-receiver. The do not. The IR-receiver it self produces
a continious pulsetrain.
Know I'm puzzled why my PASM-loop is missing some pulses as the loop is running at 8 times higher speed as the pulses come in.
I'm using the counter which is independet of code-execution. The time between reading out PHSA and resetting PHSA to zero for the next cycle is pretty short.
Much shorter than a period. I even added another cog that strechtes the pulses from the IR-reiver from 1 microsecond up to half carrier-frequency (38kHz = 26 microseconds) Pulsewidth 13 microseconds.
How can it be that some pulses are detected as zero = no carrier-pulse? while there are carrier-pulses!
ser.start(30,31,0,115200) done
cognew(Toggle_Pin(0, 4),@ToggleStack)done
cognew(@entryMeasureFreq,0) done
ready for recording pulsetrain
wait for pulsetrain
wait for pulsetrain
11111111111111111111111111111111
11111111111111111111000111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11110001111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111111111
11111111111111111111111111100000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000001111
11111000111111111000000000000000
00000000000000000000000000000000
00000000000001111111111111111111
10000000000000000000000000000000
00000000000000000000000000000011
11111111111111111100000000000000
00000000000000000000000000000000
00000000000000111111111111111111
11000000000000000000000000000000
00000000000000000000000000000001
11111111111111111110000000000000
00000000000000000000000000000000
00000000000000011111111111111111
11100000000000000000000000111111
11111111111100000000000000000000
11111111111111111111000000000000
00000000000000000000000000000000
00000000000000001111111111111111
11110000000000000000000000000000
00000000000000000000000000000000
01111111111111111111100000000000
00000000011111111111111111111000
00000000000000000111111111110001
11111100000000000000000000111111
11111111111111000000000000000000
00111111111111111111110000000000
00000000001111111111111111111100
00000000000000000001111111111111
11111110000000000000000000011111
11111111111111100000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
recording of pulsetrain done
clockticks from pulse to pulse TestVar1 2090
_Period_8tel TestVar2 261
I attach my full testcode as a ZIP-archive.
and here is the interesting part of the PASM-code
edit:
arrrgh!! What is this forum-software doing with my well-fomatted fixed-font code????
Even when I copy it back from the forumsoftware-editor field and paste it into the propeller-tool
everything looks fine again. Only when showing it in the forum the columms jump back and forth like they want.
Forum-Administrator !! Get the forum-software-guy up and solving this problem!!!
DAT
ORG 0
entryMeasureFreq
{
' --------- Debugger Kernel add this at Entry (Addr 0) ---------
long $34FC1202,$6CE81201,$83C120B,$8BC0E0A,$E87C0E03,$8 BC0E0A
long $EC7C0E05,$A0BC1207,$5C7C0003,$5C7C0003,$7FFC,$7FF 8
' --------------------------------------------------------------
}
StartOfCode call #SetOutPuts
call #Read_SPIN_CmdM
call #SetupCounterMode
'initialise variables for recording IR-signalstates
mov _IR_Recv_Long, #0 'reset long containing bits of sampled pulsetrain
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2HUB_RAM_Buff
mov _HUB_Act_Idx, _HUB_Base_AdrM 'Reset BufferIndex to baseadress
mov _Buff_Count, _BuffSize 'setup variable for buffer-filling-loop
mov _32Bit_Count, #c_NoOfBitsPerLong 'setup variable for filling long with IR-statebits
mov _Period_8Cycl, #0
mov _CarrierOnFlag, #0
mov _CarrierONCnt, #0
mov _CarrierOffCnt, #0
mov _NrOfPulses, #0
mov _LastNoOfPulses,#0
mov _NewNoOfPulses, #0
mov _SumOfPulses, #0
mov _PeriodFrac, #1
shl _PeriodFrac, #c_Divisor '_PeriodFrac contains the fractional how often
call #MeasureCarrierFreq
'coming back from this subr means new carrier-period starts right now
'the counter is already prepared through a mov PHSA, #0 to catch the next high-to-low-transition
'and PHSA containing 1 (and not a highrer value)
mov _TestVar1M, #0'_Period
mov _TestVar2M, _Period_8tel
mov _SPIN_CmdM, #1 'set Status to 0 to indicate command finished
call #Write_SPIN_CmdM
xor OutA, _LED_RightM 'set bit "_LED_LeftM" in OutA-register to 1
mov PHSA, #0
Record_IR_Bits_Loop
waitcnt _MFlopMatch, _Period_8tel 'wait for 1/8 of a period
mov _NrOfPulses, PHSA 'PHSA holds actual sum of pulses update actual number of pulses
add _Period_8Cycl, #1 'increment number of Period 8th cycles
cmp _Period_8Cycl, _PeriodFrac wz 'check if a complete period is over
if_nz jmp #Record_IR_Bits_Loop 'only if period is over do the rest
mov PHSA, #0
mov _Period_8Cycl, #0 'reset loopcounter
cmp _NrOfPulses, #1 wc 'check if there were new pulses
if_c mov _IR_Recv_Bit, #0 'no pulse received => set IR_Recv_Bit to 0
if_nc mov _IR_Recv_Bit, #1 'a pulse received => set IR_Recv_Bit to 1
add _IR_Recv_Long, _IR_Recv_Bit 'add actual bit to long
sub _32Bit_Count, #1 wz 'check for last loop within actual long
if_nz shl _IR_Recv_Long, #1 'if not last bit shift bits 1 to the left
if_z call #WriteLongToBuffer
if_z sub _Buff_Count, #1 wz 'if byte was written to buffer decrement _Buff_Count by one
if_z jmp #Recording_finished 'if _Buff_Count reaches zero buffer is full
'mov _NrOfPulses, PHSA 'PHSA holds actual sum of pulses update actual number of pulses
'cmp _NrOfPulses, #1 wc 'check if there were new pulses
'if_nc or OutA, _VPTriggerPin 'if _NrOfPulses is >= 1 then the C-Flag is cleared
'if_nc add _TestVar1M, #1
jmp #Record_IR_Bits_Loop
Recording_finished
mov _TestVar1M, _Period
'mov _TestVar2M, _Snapshot2
'sub _TestVar2M, _Snapshot1
mov _SPIN_CmdM, #0 'set Status to 0 to indicate command finished
call #Write_SPIN_CmdM
infLoop nop
jmp #infLoop
'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS SSSSSSSS
'# START Subroutines
'################################################# ########
SetOutPuts mov _BitMaskM, _LED_LeftM
or _BitMaskM, _LED_MiddleM
or _BitMaskM, _LED_RightM
'or _BitMaskM, _MonoFlopPin
or _BitMaskM, _VPTriggerPin
or _BitMaskM, _toggleBit
or DirA, _BitMaskM 'set bits of BitMakM in DirA-register to 1
andn OutA, _BitMaskM 'clear bits of BitMakM in OutA-register to 0
SetOutPuts_ret ret
'---------------------------------------------------------
'################################################# ########
SetupCounterMode 'setup counter-mode and initialise INcS-Register and TSUM-register
' 3 2 1
'10987654321098765432109876543210
'10987654321098765432109876543210
'%-CMODEPLL--------B__PIN---A__PIN
'%00111000000000000000000000000011
movi CTRA, #c_NegEdgeDetectorNoPLL 'setup counter for negative-edge-mode
movs CTRA, #%000000010 'sense IO-pin 2
mov FRQA, #1 'load summand-register with 1
mov PHSA, #0 'load summerise-register with 0
SetupCounterMode_ret ret
'---------------------------------------------------------
'################################################# ########
MeasureCarrierFreq
or OutA, _LED_LeftM 'set bit "_LED_LeftM" in OutA-register to 1
cmp _TestVar2M, #120 wz
if_z jmp #PresetPeriod
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _InputStateM, #8 'load bitpattern that should be matched
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _InputStateM, #0 'load BitPattern ZERO
WaitIRPinLow waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _FirstPulse, cnt 'take snapshot of free running systemcounter
or OutA, _LED_MiddleM 'set bit "_LED_MiddleM" in OutA-register to 1
mov _InputStateM, #8 'load bitpattern that should be matched
WaitIRPinHigh waitpeq _InputStateM, _IR_Recv_Pin2 'wait until INA-registerbit specified in _IR_Recv_Pin2
'has the same state as in _InputStateM
mov _InputStateM, #0 'load BitPattern ZERO
WaitIRPinLow2 waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
'which means pulsetrain starts
mov _SecondPulse, cnt 'take snapshot of free running systemcounter
andn OutA, _LED_LeftM 'clear bit "_LED_LeftM" in OutA-register to 0
mov _Period, _SecondPulse
sub _Period, _FirstPulse 'calculate clockticks of pulsedistance (=carrier-frequency)
mov _Period25, _Period
shr _Period25, #c_Divisor 'shr c_Divisor bits to the right means divide by 2^c_Divisor
jmp #here
PresetPeriod mov _Period, _2000
mov _Period_8tel, _Period
shr _Period_8tel, #c_Divisor 'shr 3 bits to the right means divide by 2^3 = 8 - 1/8 of a period
mov _MFlopMatch, _SecondPulse 'copy value of systemcounter-snapshot before
add _MFlopMatch, _Period 'add clockticks of 1 period
sub _MFlopMatch, _AheadTicks 'substract clockticks to be ahead of the next high-to-low-transition
mov PHSA, #0 'prepare counter to detect high-to-low-transition
or OutA, _LED_MiddleM 'set bit "_LED_LeftM" in OutA-register to 1
jmp #MeasureCarrierFreq_ret
here mov _Period_8tel, _Period
shr _Period_8tel, #c_Divisor 'shr 3 bits to the right means divide by 2^3 = 8 - 1/8 of a period
'wait until next pulse-period begins
mov _MFlopMatch, _SecondPulse 'copy value of systemcounter-snapshot before
add _MFlopMatch, _Period 'add clockticks of 1 period
sub _MFlopMatch, _AheadTicks 'substract clockticks to be ahead of the next high-to-low-transition
waitcnt _MFlopMatch, _Period
mov PHSA, #0 'prepare counter to detect high-to-low-transition
or OutA, _LED_MiddleM 'set bit "_LED_LeftM" in OutA-register to 1
MeasureCarrierFreq_ret ret
'---------------------------------------------------------
'################################################# ########
WriteLongToBuffer
wrlong _IR_Recv_Long, _HUB_Act_Idx 'write long to HUB-RAM
add _HUB_Act_Idx, #4 'set HUB-RAM-adress to next long
mov _IR_Recv_Long, #0 'reset long that contains sampled bits of pulsetrain
mov _32Bit_Count, #c_NoOfBitsPerLong 'setup variable for filling long with IR-statebits
WriteLongToBuffer_ret ret
'---------------------------------------------------------
'################################################# ########
ReSyncToCarrier
mov _InputStateM, #0 'load BitPattern ZERO
waitpeq _InputStateM, _IR_Recv_Pin2 'wait until specified bit "_IR_Recv_Pin" is ZERO
mov _MFlopMatch, cnt 'new snapshot of systemcounter
add _MFlopMatch, _Period
sub _MFlopMatch, _AheadTicks
or OutA, _DebugPin
add _TestVar2M, #1
waitcnt _MFlopMatch, _Period
'mov _IR_Recv_Bit, #1 'resyncing means a pulse has occurred so set _IR_Recv_Bit to 1
ReSyncToCarrier_ret ret
'---------------------------------------------------------
'################################################# ########
Read_SPIN_CmdM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2_S2A_Cmd
rdlong _SPIN_CmdM, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar1
rdlong _TestVar1M, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar2
rdlong _TestVar2M, _HUB_Base_AdrM
Read_SPIN_CmdM_ret ret
'---------------------------------------------------------
'################################################# ########
Write_SPIN_CmdM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar1
wrlong _TestVar1M, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2TestVar2
wrlong _TestVar2M, _HUB_Base_AdrM
mov _HUB_Base_AdrM, par
add _HUB_Base_AdrM, #ptr2_S2A_Cmd
wrlong _SPIN_CmdM, _HUB_Base_AdrM
Write_SPIN_CmdM_ret ret
'---------------------------------------------------------
_IR_Recv_Pin2 long |< 3
_MonoFlopPin long |< c_IR_Recv_Pin
_DebugPin long |< 5
_VPTriggerPin long |< 6
_10microSecs long c_10microSecs
_toggleBit long |< c_C3_LED
_LED_LeftM long |< c_LED_Left
_LED_MiddleM long |< c_LED_Middle
_LED_RightM long |< c_LED_Right
_BuffSize long c_Buffer_Size
_zero long 0
_AheadTicks long c_AheadTicks
_CarrierOnFlag long 1
_2000 long 2000
_SPIN_CmdM res 1
_TestVar1M res 1
_TestVar2M res 1
_HUB_Act_Idx res 1
_HUB_Base_AdrM res 1
_Buff_Count res 1
_32Bit_Count res 1
_FirstPulse res 1
_SecondPulse res 1
_Period res 1
_Period25 res 1
_Period50 res 1
_Period75 res 1
_MFlopMatch res 1
_EOSamplMatch res 1
_IR_Recv_Bit res 1
_IR_Recv_Long res 1
_InputStateM res 1
_BitMaskM res 1
_dummyLongM res 1
_NrOfPulses res 1
_LastNoOfPulses res 1
_NewNoOfPulses res 1
_SumOfPulses res 1
_MatchVal res 1
_Period_8tel res 1
_Period_8Cycl res 1
_CarrierOffCnt res 1
_CarrierONCnt res 1
_PeriodFrac res 1
_Snapshot1 res 1
_Snapshot2 res 1
I hope some PASM-gurus can explain to me why some pulses are missing and how I can
make 101% sure that not even a single pulse is missing.
keep the hints coming
best regards
Stefan