SX/B IR Remote control revisited
Rsadeika
Posts: 3,837
This is essentially a problem that I had talked about earlier. I have below some SX/B code for the SX28 Tech board and the SX52 proto board. This is in essence a derivitive of Jons SIRC code. I tried to make things as equal as possible for the two scenarios. Meaning, I set up a circuit so that I can hook up either the SX28 tech board or the SX52 proto board. Each board powers the circuit when it is hooked up.
I think I have narrowed the problem down to either·a quirk with the SX52 board or a quirk in the compiler when it deals with the particular piece of code in SX52 setting.
The specific piece of code is:
·do
··· pulsin IRpin, 0, temp1
· loop until temp1 > 216
When this segment is run on the SX28 Tech board, the code runs as expected. When I run this segment on the SX52 proto board, it hangs, or freezes if you will. For the SX52 proto board I played around with some values just to see what would happen. When I put in 'loop until temp1 > 0', there seemed to be a response, the LED came on. When I put in 'loop until temp1 < 216', the program liked that, the LED came on. In the SIRCS program, in order for it to work correctly the·code has to be 'loop until temp1·> 216'. There is something definetly wrong. My SX28 Tech board is doing just fine, and Jons SIRCS program works fine on the board.
Last week I was trying to replicate this in asm code, that is·when I started to run into some big problems. Just enough knowledge to get you into some really big trouble. So, now I will not know for sure until somebody else replicates this on an SX52 proto board. I am still leaning toward, a quirk in the compiler, the SX52 part of it, anyway.
Any ideas?
Ray
' =========================================================================
'
'·· File...... MyTut0228.sxb
'·· Purpose... SX/B Programming Template
'·· Author....·
'·· E-mail....·
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
'
' IO Pins
'
Led1 var RB.0
IRpin var RC.0
'
' Constants
'
'
' Variables
'
·temp1 var byte
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
·BlinkLED sub
·Get_Code sub
'
' Program Code
'
Start:
· PLP_A = %0000
· PLP_B = %00000000
· PLP_C = %00000000
Main:
· DO
··· Get_Code
··· BlinkLED·
· LOOP
end
'
'Suroutine Code
'
Get_Code:
· do
··· pulsin IRpin, 0, temp1
· loop until temp1 > 216
return
BlinkLED:
··· LOW Led1···· 'Turn on the LED
··· PAUSE 1000
··· HIGH Led1··· 'Turn off the LED
return
'
'User Data
'
' =========================================================================
'
'·· File...... MyTut0352.SXB
'·· Purpose...·
'·· Author....
'·· E-mail....
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX52, OSC4MHZ
FREQ··········· 4_000_000
'
' IO Pins
'
LED1 var RD.0
IRpin var RE.0
'
' Constants
'
'
' Variables
'
temp1 var byte
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
BlinkLED sub
'
' Program Code
'
Start:
· PLP_A = %00000000···· 'PLP_ activates the pull ups
· PLP_B = %00000000
· PLP_C = %00000000
· PLP_D = %00000000
· PLP_E = %00000000
·
Main:
· DO
·· pulsin IRpin, 0, temp1
· LOOP until temp1 > 216·· '*******
· BlinkLED
· goto Main
· END
'
' Subroutine Code
'
BlinkLED:
·· LOW LED1···· 'Low makes rd.0 pin output, sets pin to 0 (Vdd) led is on
··· PAUSE 1000
·· HIGH LED1··· 'High makes rd.0 pin output, sets pin to 1 (Vss) led is off
return
' =========================================================================
' User Data
' =========================================================================
I think I have narrowed the problem down to either·a quirk with the SX52 board or a quirk in the compiler when it deals with the particular piece of code in SX52 setting.
The specific piece of code is:
·do
··· pulsin IRpin, 0, temp1
· loop until temp1 > 216
When this segment is run on the SX28 Tech board, the code runs as expected. When I run this segment on the SX52 proto board, it hangs, or freezes if you will. For the SX52 proto board I played around with some values just to see what would happen. When I put in 'loop until temp1 > 0', there seemed to be a response, the LED came on. When I put in 'loop until temp1 < 216', the program liked that, the LED came on. In the SIRCS program, in order for it to work correctly the·code has to be 'loop until temp1·> 216'. There is something definetly wrong. My SX28 Tech board is doing just fine, and Jons SIRCS program works fine on the board.
Last week I was trying to replicate this in asm code, that is·when I started to run into some big problems. Just enough knowledge to get you into some really big trouble. So, now I will not know for sure until somebody else replicates this on an SX52 proto board. I am still leaning toward, a quirk in the compiler, the SX52 part of it, anyway.
Any ideas?
Ray
' =========================================================================
'
'·· File...... MyTut0228.sxb
'·· Purpose... SX/B Programming Template
'·· Author....·
'·· E-mail....·
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
'
' IO Pins
'
Led1 var RB.0
IRpin var RC.0
'
' Constants
'
'
' Variables
'
·temp1 var byte
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
·BlinkLED sub
·Get_Code sub
'
' Program Code
'
Start:
· PLP_A = %0000
· PLP_B = %00000000
· PLP_C = %00000000
Main:
· DO
··· Get_Code
··· BlinkLED·
· LOOP
end
'
'Suroutine Code
'
Get_Code:
· do
··· pulsin IRpin, 0, temp1
· loop until temp1 > 216
return
BlinkLED:
··· LOW Led1···· 'Turn on the LED
··· PAUSE 1000
··· HIGH Led1··· 'Turn off the LED
return
'
'User Data
'
' =========================================================================
'
'·· File...... MyTut0352.SXB
'·· Purpose...·
'·· Author....
'·· E-mail....
'·· Started...
'·· Updated...
'
' =========================================================================
'
' Program Description
'
'
' Device Settings
'
DEVICE········· SX52, OSC4MHZ
FREQ··········· 4_000_000
'
' IO Pins
'
LED1 var RD.0
IRpin var RE.0
'
' Constants
'
'
' Variables
'
temp1 var byte
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Subroutine Declarations
'
BlinkLED sub
'
' Program Code
'
Start:
· PLP_A = %00000000···· 'PLP_ activates the pull ups
· PLP_B = %00000000
· PLP_C = %00000000
· PLP_D = %00000000
· PLP_E = %00000000
·
Main:
· DO
·· pulsin IRpin, 0, temp1
· LOOP until temp1 > 216·· '*******
· BlinkLED
· goto Main
· END
'
' Subroutine Code
'
BlinkLED:
·· LOW LED1···· 'Low makes rd.0 pin output, sets pin to 0 (Vdd) led is on
··· PAUSE 1000
·· HIGH LED1··· 'High makes rd.0 pin output, sets pin to 1 (Vss) led is off
return
' =========================================================================
' User Data
' =========================================================================
Comments
Yesterday I determined that the pulsin command for the SX28 worked as expected. Today I eliminated the SX52 proto board as a problem, by having Jon's SIRCS_ISR program work as expected. The program has an asm simulation of what the pulsin command is supposed to be doing. I also ran his non asm version of SIRCS_ISR, that also ran as expected.·I guess since the SX52 is now EOL, then it's hard to say when the bug will be fixed in the SX/B compiler.
I am not going to re-quote my "tip of the ...", but I will me more meticulous with making sure that the command is supposed to work as expected. Programming will take a little longer, but I will not end up chasing problems like I did a week or so ago.
Ray
When it comes to SXB, I'm not fully up to speed on the nuances of the language, so I would have a tough time spotting anything incorrect or unusual. If you can convert and post both to as identical as possible assembly routines, I can can give helping a good shot.
Cheers,
Peter (pjv)
I am not sure if this is what you requseted. As much as I can understand of this, I think Jon's code is really pretty good; I kind of like his coding style. The first snippet is basically an SX/B version of getting the code from the irpin. The second snippet is the asm version. Both of these work, so, that is what I used to eliminate·a board problem.
Some where along the line I will have to sit down and study this code, and see what it really means.
Thanks
Ray
******CODE
This is a snippet of the SX/B SIRCS_ISR program non-asm version, in here lies the pulsin command, somewhere.
·························
'_________________________________________________________________________
INTERRUPT NOPRESERVE
'_________________________________________________________________________
ISR_Start:
·· if hasCmd = 1 then ISR_Exit
·· if rxCmd = 1 then Check_Bit
·· if irpin = 1 then ISR_Exit·······
Start_Packet:
·· rxCmd = 1
·· rxBit = 1
·· cmdWork = 0
·· bitWidth = 0
·· bitCount = 0
·· goto ISR_Exit
Check_Bit:
·· if irpin = 0 then Update_BitWidth
·· if rxBit = 0 then ISR_Exit
·· rxBit = 0
·· if bitCount > 0 then Test_DBit
Test_SBit:
·· if bitwidth > 74 then Next_Bit
·· rxCmd = 0
·· goto ISR_Exit
Test_DBit:
·· cmdWork = cmdWork >> 1
·· if bitWidth < 34 then Next_Bit
·· cmdWork.6 = 1
Next_Bit:
·· bitwidth = 0
·· inc bitCount
·· if bitCount < 8 then ISR_Exit
·· hasCmd = 1
·· cmdCode = cmdWork
·· rxCmd = 0
·· goto ISR_Exit
Update_Bitwidth:
·· inc bitWidth
·· rxBit = 1
ISR_Exit:
· returnint 104
*******************
This is a snippet of the asm version of the SIRCS_ISR program,·in here lies the pulsin command also.·This is a cut from Jon's original code. The variables apply to both snippets.
'
' Variables
'
cmdCode··VAR·Byte···' IR command code (7 bits)
cmdWork··VAR·Byte···' work space for cmd byte
bitCount·VAR·Byte···' track bits received
bitWidth·VAR·Byte···' measure bit width
flags··VAR·Byte
rxCmd··VAR·flags.0···' receiving command
rxBit··VAR·flags.1···' measuring bit width?
hasCmd··VAR·flags.2···' command code available
temp1··VAR·Byte···' subroutine work vars
temp2··VAR·Byte
temp3··VAR·Byte
'
· INTERRUPT NOPRESERVE
'
ISR_Start:
· ASM
··· JB··· hasCmd, ISR_Exit···' exit if holding command
··· JB··· rxCmd, Check_Bit···' receiving now?
··· JB··· IR, ISR_Exit····' exit if IR line idle
Start_Packet:
··· SETB· rxCmd·····' set rx flags
··· SETB· rxBit
··· CLR·· cmdWork····' clear work vars
··· CLR·· bitWidth
··· CLR·· bitCount
··· JMP·· ISR_Exit
Check_Bit:
··· JNB·· IR, Update_BitWidth···' still in bit?
··· JNB·· rxBit, ISR_Exit···' in idle period?
··· CLRB· rxBit·····' no, clear bit flag
··· CJA·· bitCount, #0, Test_DBit··' start or data bit?
Test_SBit:
··· CJA·· bitWidth, #74, Next_Bit··' proper start bit?
··· CLR·· rxCmd·····' no, reset
··· JMP·· ISR_Exit
Test_DBit:
··· CLC
··· RR··· cmdWork····' prep for next bit
··· CJB·· bitWidth, #34, Next_Bit··' "1" bit?
··· SETB· cmdWork.6····' yes, set it
Next_Bit:
··· CLR·· bitWidth····' clear for next bit
··· INC·· bitCount····' update count
··· CJB·· bitCount, #8, ISR_Exit··' done?
··· SETB· hasCmd····' set available flag
··· MOV·· cmdCode, cmdWork···' copy work to output
··· CLRB· rxCmd·····' clear rx flag
··· JMP·· ISR_Exit
Update_BitWidth:
··· INC·· bitWidth····' else inc width
··· SETB· rxBit·····' refresh in bit flag
· ENDASM
ISR_Exit:
· RETURNINT 104·····' 26 uS @ 4 MHz