Shop OBEX P1 Docs P2 Docs Learn Events
For ... Next loop never ending — Parallax Forums

For ... Next loop never ending

Mag748Mag748 Posts: 269
edited 2006-04-01 03:35 in General Discussion
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

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • BeanBean Posts: 8,129
    edited 2006-03-20 16:13
    Marcus,
    "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."
    ·
  • Mag748Mag748 Posts: 269
    edited 2006-03-20 18:17
    Bean, Thank you very much. that was the problem. Now the SX works perfectly. There is one other problem with my project that is the currect bottleneck. I am trying to send reliable IR messages and currently I am using a 555 timer which powers an IR LED at 40 Khz. I have tried many different configurations with different resistors, different schematics and none of them seem to work very well. Does anyone have any better ideas to power an IR led at 40 Khz?
    Thank you,
    Marcus.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RsadeikaRsadeika Posts: 3,837
    edited 2006-03-20 19:35
    For starters you could go to the robotics forum and read this thread -·How to build your own SSIR Detector. It contains some information that you might be able to use.··
  • BeanBean Posts: 8,129
    edited 2006-03-20 20:00
    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."
    ·
  • Mag748Mag748 Posts: 269
    edited 2006-03-20 23:19
    Thank you again Bean for the great quick responses. I considered and implemented your idea. I was thinking that since the SX will be interrupted every so often, wouldnt the pause and pauseus commands need to be shortened? this would be to compensate for the amount of time the program is in the interrupt. I could very well be wrong, because i still know nothing of interrupts.

    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

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RsadeikaRsadeika Posts: 3,837
    edited 2006-03-20 23:49
    Below is a file that I found in the SX/B examples folder. You may want to check your program against this one. You may have to figure out at what Khz the IR LED is firing at. If I remember correctly, if you are at 42KHz, 3 - 4 inches is all that you will be getting. Even at 38KHz you will only be able to get around 6 - 8 inches I believe.

    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
  • BeanBean Posts: 8,129
    edited 2006-03-21 00:41
    Marcus,
    · 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."
    ·
  • Mag748Mag748 Posts: 269
    edited 2006-04-01 01:19
    Hello again. I have been trying this Interrupt routine that you guys suggested and I don’t know why, but I am having some kind of problem. I am still using the very basic test program that pulses the IR led at 40 KHz. I even used an oscope to determine the output and it is exactly 40000Hz at 50% duty cycle. And, using a 62 Ohm resistor, the LED is getting plenty of power. Yet, I still can only get the phototransistor to turn on if the unit is less than about 1 foot away. I have tried many different RETURNINT ## values and different clock speeds and different IR LEDs and different resistor values. But nothing seems to be working. I can’t find any information on Google either. I can’t understand either why it worked with a 555 timer. Anyway, if anyone can shed some light (Ill accept IR as well) on this subject, I'd be very grateful.

    Thank you,
    Marcus.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-01 02:14
    I say you need some lenses/optics.· [noparse][[/noparse]Try a magnifying glass or maybe a fresnel at the receiver.]
  • Mag748Mag748 Posts: 269
    edited 2006-04-01 02:42
    Um, the reciever is not the problem. Its the transmitter. I know this because the Phototransistor (or IR demodulator, i guess) that I am using as the reciever responds to any IR remote from at least 50 feet away.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-04-01 02:48
    I'll offer that all IREDs do not emit at the same wavelength.· Perhaps the optics could be of good effect on/with the emitter.· Just a suggestion.· I've seen in mcminone.com a device that you can stick over your TV/VCR/etc.'s IR-rcvr so that it can get signals from more angles (kind of like a pyramid, with more sides), a sort of IR-prism like.
  • Mag748Mag748 Posts: 269
    edited 2006-04-01 03:35
    I do not think it is the IR led becuase I used the same led with the 555 timer circuit and it worked fine (well, not perfectly, and that is why I am not using it now.) Another thing that I noticed is that when I first start up the SX by connecting it to power, the reciever comes on. Even if its more than like 5 feet away. Somehow, during that first few milliseconds, the detector is recieving something that it likes. If anyone else has try this before and got it to work, can they show me a schematic or program they used?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.