For ... Next loop never ending
Mag748
Posts: 269
Hello, I am·very new to the SX. I wrote the attached program which assembles fine and seems like it should work. But I am having a problem. There is a For ... Next loop which is supposed to go from 0 to 6 but for some reason just keeps looping forever. when I have idx go from 0 to 0, it loops once, like it should. But even if I change it to "0 to 1" it just goes forever. I dont understand what is happening. sorry if my code seems very crappy. I am just beginning to understand how the sx thinks.
-Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Marcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
"Read PRSData + Code + idx, theByte" is not a valid SX/B statement. Only one "+" operator is allowed.
I would try changing the code to:
READ PRSData + Code, theByte
INC Code
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Sometimes it is better to remain silent and be thought a fool, than to speak and remove all doubt."
·
Thank you,
Marcus.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The best way would be to setup and interrupt routine to toggle the IR-Led pin @ 40Khz.
Here is what you need to do:
1) Make your interrupt code:
· INTERRUPT NOCODE
· IRpin = ~IRpin
· RETURNINT 50
2) After the "Start:" label add
· OPTION = $88
3) Change all your "LOW IRpin" lines to "INPUT IRpin" (I assume LOW means no output).
4) Change all your "HIGH IRpin" lines to "OUTPUT IRpin" (again assuming HIGH means 40KHz output)
5) Multiply all of your PAUSE and PAUSEUS values by 1.19 for example PAUSE 500 will be PAUSE 595
· · This is to account for the time the SX spends in the interrupt routine.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Sometimes it is better to remain silent and be thought a fool, than to speak and remove all doubt."
·
Also, I gathered that the numbers you gave me above were for when the SX is running at 4MHz. I was planning on running the final program at 50MHz, solely to reduce the time the SX worked, in order to keep the actual pause and pauseus commands as acurate as possible.
Finally, I created a very simple test program which just outputted a constant 40KHz on a pin in order to test the IR LED. I found that with a 220 Ohm resistor in series with the IR LED, the led was very dim, even though it was consuming 16mA of power. could this led be getting 'old' as in, I should replace it with a fresh one? or does an IR LED only output full capacity at 20 mA? I am not sure, actually, i dont know the specs of this led since i just found it somewhere. anyway, with this setup it only transmits about 3-4 inches. I will play around some more.
Thank you very much,
Macrcus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ray
' =========================================================================
'
'·· File...... INTERRUPT_RTCC.SXB
'·· Purpose... IR modulation with Interrupt code
'·· Author.... (c) Parallax, Inc. -- All Rights Reserved
'·· E-mail.... support@parallax.com
'·· Started...
'·· Updated... 29 OCT 2004
'
' =========================================================================
'
' Program Description
'
'
' This program modules an IR LED using the interrupt handler to toggle the
' IR LED state every 13 microseconds.· When an object is detected, the
' alarm LED is illuminated.
'
' Device Settings
'
DEVICE········· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
IrLed··VAR·RB.0···' IR LED control
Detect··VAR·RB.1···' detector input
Alarm··VAR·RB.2···' alarm LED output
'
· INTERRUPT
'
ISR_Start:
· IrLed = ~IrLed····' toggle IR LED
· RETURNINT 52······························· ·'·· every 13 us @ 4 MHz
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
· LOW IrLed·····' make output, off
· LOW Alarm·····' make output, off
· OPTION = $88 ·····' interrupt, no prescaler
Main:
· Alarm = ~Detect····' check detector
· PAUSE 50
· GOTO Main
· You are right. The pause values should be DIVIDED by 1.19
· 50MHz would probably be overkill. If it works at 4MHz all the less power you will need.
· The way I got 1.19 was that I used SX-Sim and it told me that the interrupt uses 8 clocks.
· So the interrupt is called every 50 clocks, so it uses 8 of every 50 clocks. So the main program get 42 of every 50 clocks. 50/42 = 1.19
· If you want to be really accurate you would have a counter in the interrupt routine, then you could determine the exact number of 40KHz pulses you wanted the signal to be on/off. You would probably need a faster clock to do that.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module"·available from Parallax for only $28.95 http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module"·available from Parallax for only·$49.95 http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Sometimes it is better to remain silent and be thought a fool, than to speak and remove all doubt."
·
Thank you,
Marcus.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔