Blink an LED while waiting for IR signal

edmunds

Senior Member
Dear all,

I have an application in mind with 20X2, where the chip should be able to "do something" while waiting for the next IR instruction in a form of SONY IR code. While the manual says "all processing stops" during the irin command, I think this is not a problem as the chip would take a pin high or low, apply DAC level or something else after each received command and go into the "wait state" again. In other words, there would be no other inputs to monitor - only one IR sensor. This sounds doable (also DAC level?). One function, requires a blinking LED, though. Could this be done with something that is "irin independent"? Like using internal timer or something. Or is the only way to change the state between two irin commands? Or external "blinker circuit", of course.


Thank you for your time,

Edmunds
 
Last edited:

edmunds

Senior Member
And another question about IR sequencing. To output, say 10 different IR codes at the same time, a code per pin - I just loop over 10 irout commands for each pin and code?


Thank you once again,

Edmunds
 

hippy

Technical Support
Staff member
IRIN does block so while it is waiting for IR nothing else can happen unless implemented using autonomous on-chip hardware.

You could use IRIN timeout or interrupt or poll on IR going low then grab the next IR command after that. That would allow you to choose between doing one thing or reading the IR.

For your second question; yes, just execute the IROUT commands on the appropriate pins in sequence. The codes will be sent sequentially in turn rather than at the same time though.
 

Technical

Technical Support
Staff member
You can buy 'flashing LEDs' that just need a high/low signal to control, and flash automatically. That could be used alongside irin.
 

inglewoodpete

Senior Member
If you're happy with a fairly slow flash rate, use the IRIN timeout feature set to a reasonably long period (eg 600mS or longer) and the Toggle command on the LED, all in a loop. The longer the timeout period, the chance of receiving an IR signal when not waiting for it is reduced.

I'm not sure why you want to output IR signals on different pins. Perhaps you're hard wiring to the receiving hardware? If you're actually sending infrared signals, then only one output pin is required.
 

edmunds

Senior Member
I'm not sure why you want to output IR signals on different pins. Perhaps you're hard wiring to the receiving hardware? If you're actually sending infrared signals, then only one output pin is required.
The "signal generating" chip would be responsible for maintaining a "signal bus" which would go around the model train/car/ship layout. The hardware responsible for routing logic, would switch the signals on and off for different locations. Some signals have to be transmitting at all times in some locations. Other possible implementation would be to have signals generated "locally" i.e. in the routing logic hardware, but this would create longer blank periods, while other processing takes place if compared to just looping pins. I'm not sure at this point, if this difference would be crucial.

Anyway, I'm building everything with foreign signals now - this is where the switching comes from. This is how it will work in the beginning. For the future, I'm considering how viable and fun :) it would be to try and build all the hardware of my own, so I do not need any closed protocols or foreign decoders. Would like to build dome prototypes to check feasibility in the coming months. Thus all the wave of new questions in the forum :).

Thank you for your input,

Edmunds
 

geoff07

Senior Member
I use a dedicated 08M2 chip to receive the IR and then send a message by interrupt and serial on the same line into the main picaxe. Simple, cheap and effective.
 

edmunds

Senior Member
I use a dedicated 08M2 chip to receive the IR and then send a message by interrupt and serial on the same line into the main picaxe. Simple, cheap and effective.
You must have the luxury of space :). This is to be fit into HO scale [1:87] vehicle along with motor, gearbox, LiPo and other gadgets. I'm trying to avoid soldering things to a PCB from both sides and doing more than two layers. A commercial decoder that works with its deficiencies is 14.5x10x1.5mm "big". About that size or smaller is what I need to achieve.

Edmunds
 

Buzby

Senior Member
In my projects I use an interrupt on the same pin as I use for IRIN.

The main loop runs around as fast as it can, until the IR signal triggers the interrupt.

Then the interrupt executes the actual IRIN command, and processes whatever it needs, then returns to the main loop.

I may be missing the first IR signal, but because the transmitter repeats the command as long as the button is held down I get the next IRIN response within the repeat time, which I think is 45ms.

This is plenty fast enough for me.
 

erco

Senior Member
No need to overthink this one. All Sony codes from the remote except power loop continuously. IR receiver is actively low. Write your blink routine using loops, not long pauses, regularly checking the IR receiver output with a simple "if pinb.1=0 then (goto read sony ir code)". That is, keep looping and blinking as long as the IR sensor output is high. When it goes low, jump to a routine to read the IR code next time it repeats.
 

erco

Senior Member
Here's a quickie routine that checks the IR sensor as described inside a for/next loop. You can add a TOGGLE command to blink your LED, and adjust the blink rate by changing the for/next parameters.

Code:
#picaxe 08m2
#no_data
sertxd("ready",13,10)
do
'fwd=116   stop/center=101   reverse=117    left=52    right=51
'channel+=16   channel-=17     volume+=18   volume-=19
'button n=(n-1)  button 1=0, 2=1, etc  0=9
'pause 100
for b0=1 to 255
if pinc.3=0 then irin c.3,b7
sertxd("irin=",#b7,13,10)
pause 200
else sertxd(#b0,13,10)
pause 10
endif
next
loop
 

edmunds

Senior Member
Thank for all the advice,

Here are pieces of the code that achieve this in my version. Or so I think :)

Code:
main:
'IR receiver is idling high, so on incoming signal, the pin goes low
  if pinB.0 = 0 then
    irin IRSENS, IRCode
    select case IRCode
    case 8 to 40 :        NewSpeed = IRCode
    case 51 :               NewSpeed = 0
    case 41                 gosub SetUpID
    case 52 :               BLKLON = 1
    case 53 :               BLKRON = 1
    case 54 :               BLKRON = 1 : BLKRON = 1
    case 55 :               BLKLON = 0 : BLKRON = 0
    case 56 :               high RUNL
    case 57 :               low RUNL
.....
'left blinker ON phase for 10 loops
  if BLKLON = 1 and BLKRON = 0 and Counter2 < 10 then
  	high BLKL
  	inc Counter2
  else
 'left blinker OFF phase 
  	low BLKL
  	Counter2 = 0
  endif
'right blinker ON phase for 10 loops
  if BLKRON = 1 and BLKLON = 0 and Counter2 < 10 then
  	high BLKR
  	inc Counter2
  else
'right blinker OFF phase
  	low BLKR
  	Counter2 = 0
  endif
'hazzard lights ON phase for 10 loops
  if BLKLON = 1 and BLKRON = 1 and Counter2 < 10 then
  	high BLKL
  	high BLKR
  	inc Counter2
  else
'hazzard lights OFF phase
  	low BLKL
  	low BLKR
  	Counter2 = 0
  endif
.........
goto main
Edmunds
 
Top