IRIN Command Hangs Up

4jaba6

New Member
I am using a 20M2.
The IRIN command works well for a few times.
The program cycles and visits the IRIN each time it recycles.
Anywhere from the 2nd to 4th or 5th program circuit, IRIN hangs up and does not leave.
Apparently it does not "timeout" !???
Is it possible that the time(timeout) being monitored would somehow get greater than the timeout specified and
consequently the command not know what to do?
Explanations and esp. SOLUTIONS will be greatly appreciated.
TIA ( Thanks in Advance )

John
 

eclectic

Moderator
I am using a 20M2.
The IRIN command works well for a few times.
The program cycles and visits the IRIN each time it recycles.
Anywhere from the 2nd to 4th or 5th program circuit, IRIN hangs up and does not leave.
Apparently it does not "timeout" !???
Is it possible that the time(timeout) being monitored would somehow get greater than the timeout specified and
consequently the command not know what to do?
Explanations and esp. SOLUTIONS will be greatly appreciated.
TIA ( Thanks in Advance )

John
First off John,

Program and Circuit please.

e
 

4jaba6

New Member
PROGRAM:

irin[7000,SEARCHDONE],C.4,reccode

if reccode = 59 then GOTO TRANSLOOPB

pause 100

GOTO SEARCHDONE


CIRCUIT:

The circuit is the basic circuit for an IR receiver sensor...
such as a Panasonic 4602 or TSOP 38238.
They have 3 pins.
As one faces the Sensor:
+5V is on right
ground is in middle
20M2 pin is on left
 

AllyCat

Senior Member
Hi,

You haven't given enough code for us to be able to judge if there might be any "bugs", but the way to solve problems like this is to use the "Debugging" features of the Program Editor / Terminal Emulator. Add SERTXD commands to indicate each stage of the program execution to see where (and maybe why) it hangs, for example:
Code:
#picaxe 20m2
#terminal 4800     ; Assuming a normal SetFreq M4

sertxd (cr,lf,"Waiting for IR")
irin[7000,SEARCHDONE],C.4,reccode

TRANSLOOPB:
sertxd (cr,lf,"TransLoop Entered, value= ",#reccode)                

SEARCHDONE:
sertxd (cr,lf,"SearchDone Entered")
; etc..
Isn't a better description of "SearchDone" actually "SearchFailed" ?

Cheers, Alan.
 

inglewoodpete

Senior Member
Hi John,

(Beaten to the punch by Alan. But anyway, my code does almost exactly the same thing, altough it is a complete hardware diagnostic.)

Try the following code. It will show if there are any hardware issues.

Peter

Rich (BB code):
#picaxe 20M2
#terminal 4800
'
SerTxd ("Bootup...", CR, LF)
Main:
      Do
         IRIN [7000,TimeOut],C.4,b0
         SerTxd (#b0, CR, LF)
      Loop

TimeOut:
      SerTxd ("Time out", CR, LF)
      Goto Main
 

4jaba6

New Member
Hi John,

(Beaten to the punch by Alan. But anyway, my code does almost exactly the same thing, altough it is a complete hardware diagnostic.)

Try the following code. It will show if there are any hardware issues.

Peter

Rich (BB code):
#picaxe 20M2
#terminal 4800
'
SerTxd ("Bootup...", CR, LF)
Main:
      Do
         IRIN [7000,TimeOut],C.4,b0
         SerTxd (#b0, CR, LF)
      Loop

TimeOut:
      SerTxd ("Time out", CR, LF)
      Goto Main
ter,

Peter,

Great to hear from you again.

Peter and Alan, I appreciate your diagnostic recommendations.
I hope to test them with my project this weekend but there is a potential monkey in wood pile with Tropical Storm Fred bearing down on Florida;
so might have to delay.

I recently discovered that testing on the bench with not running the motors, the IRIN does NOT fail.
I have not tested this enough yet.
New testing shall include motors running and not running to confirm.

Eventually shall do more "floor" testing,
but difficult to do because of the download cable.

Thanks again for the Terminal diagnostic testing suggestions; I have never done this before.

John
 

4jaba6

New Member
I have determined that ( A ) IRIN does NOT HANGUP when on the bench with motors NOT running
and same for ( B ) with motors running and no friction floor or plat surface .
However ( C ) when on the floor, that is not the case. The IRIN command will eventually hang up
as it cycles thru the program several times. I started to believe that the issue might be somehow related to friction of floor.

I took Inglewoodpete and Alan's Terminal Programs and repeated the testing as above.
I had to enter motor code to their programs to do this ( see code below ).
Ran the motors on bench and not fail.
I gave the motors a chance to run on a flat surface and the "timeout's" continued to occur as they should.

My thought was that due to friction of wheels( motors ) on floor or flat surface and not freewheeling on bench
may be generating some kind of EMF event that affected the IRIN timeout ( seems kind of like an obscure reason but why would it not hang up when freewheeling but fail when running on floor ?!?! ).
The fact that timeout's seemed normal in the modified Terminal Program does not appear to gel with that theory.

Next is the modified program.
Perhaps there is better code to address solving this problem than the motor code I used.!?!?

#picaxe 20M2
#terminal 4800
'
SerTxd ("Bootup...", CR, LF)
Main:
HIGH B.6

PAUSE 500 'Motor Code to go forward in short spurts
LOW B.6
HIGH C.1
LOW C.0
HIGH B.2
LOW B.3
PAUSE 250

LOW B.6
LOW C.0
LOW C.1
LOW B.2
LOW B.3
PAUSE 1000


Do
IRIN [7000,TimeOut],C.4,b0
SerTxd (#b0, CR, LF)


Loop

TimeOut:
SerTxd ("Time out", CR, LF)
Goto Main


Looking forward to suggestions/recommendations.

John
 

Technical

Technical Support
Staff member
A loaded motor will produce far more electrical noise than a freewheeling motor. When you have unwanted noise on the power rail this can cause the sensor to output random pulses - and hence the timeout never occurs.

Make sure:
1) You have an external pull up resistor on the sensor output (4k7), the sensor internal pullups are normally quite high values.
2) capacitors physically close to the sensor across the power rails, both 100nF and a 47uF/100uF
3) the motors have suppressing capacitors across their contacts
4) you have well laid out power rails, keeping the motor power away from the picaxe electronics
 

4jaba6

New Member
A loaded motor will produce far more electrical noise than a freewheeling motor. When you have unwanted noise on the power rail this can cause the sensor to output random pulses - and hence the timeout never occurs.

Make sure:
1) You have an external pull up resistor on the sensor output (4k7), the sensor internal pullups are normally quite high values.
2) capacitors physically close to the sensor across the power rails, both 100nF and a 47uF/100uF
3) the motors have suppressing capacitors across their contacts
4) you have well laid out power rails, keeping the motor power away from the picaxe electronics

Technical,

I appreciate your instructions on how to REDUCE MOTOR NOISE.

I Am having some difficulty visualizing schematics but I believe have
found some help in Picaxe books.

Regarding Your Comments:

1) Book: "Programming and Customizing the Picaxe Microcontroller has an infra-red receiver sensor circuit on page 61. It uses the 4K7 resistor you recommend. They show the resistor between picaxe pin/sensor output and + 5v. I always thought the resistor went directly between the sensor output and the picaxe pin!?!? ( see attachment A )

2) Book: "Picaxe Microcontroller Projects for the Evil Genius" page 219 shows the 47/100 uf
capacitors across the power rails. I assume this is motor power rails ( microcontroller? both? ).
I am using an L293D for "motor control". ( see attachment B )
I can not figure out where to place the 100nf capacitor you recommend?

3) I have a motor supply diagram that shows .01uF capacitors between motor supply on the L293D and ground.
( also see attachment B )

4) The motor power is away from the electronics.

I scanned the attachments but in the "preview" to this post,
it appeared that they would not attach.
From what I can tell, they are in PDF format.
Is there a better way of attaching?

Is there a tutorial showing how to use a keyboard to draw the kind of schematics/circuits we are discussing?

Thanks,

John
 

inglewoodpete

Senior Member
1) ... It uses the 4K7 resistor you recommend. They show the resistor between picaxe pin/sensor output and + 5v. I always thought the resistor went directly between the sensor output and the picaxe pin!?!? ( see attachment A )

2) Book: "Picaxe Microcontroller Projects for the Evil Genius" page 219 shows the 47/100 uf
capacitors across the power rails. I assume this is motor power rails ( microcontroller? both? ).
I am using an L293D for "motor control". ( see attachment B )
I can not figure out where to place the 100nf capacitor you recommend?

3) I have a motor supply diagram that shows .01uF capacitors between motor supply on the L293D and ground.
( also see attachment B )

4) The motor power is away from the electronics.

John
@John,

I'll jump in while Technical is asleep ;) .

1. Relatively low value of the pullup resistor places a lower resistance "pull up" urge on the data line between the sensor and the PICAXE input. Treat the resistor like a spring. Technical mentions that the internal pullup resistor in the IR sensor is quite weak (Ie high resistance) - equivalent to a weak spring and susceptible to external electrical noise interfering with the output. The stronger pull-up makes the circuit less suseptable to noise interference.

2. You should have two wires connecting the L293D to each motor. Solder the 100nF capacitor to the two terminals of the motor. A capacitor has a low impedance to higher frequencies, so will will remove a lot of the motor's comutator noise off the supply wires. Refer to the drawing in Manual 3 "Output Devices 5 - DC "Toy" motors (Page 12 in my copy)

3. The 10nF capacitors across the L293D's power pins adds to the noise quenching, further reducing the external effects of electrical noise.

4. It is good to keep the motor power wiring as seperate as possible from the controler (PICAXE) power wires. If the motor/s and PICAXE share a power source, the wiring for the controller should run between the controller and the power source. I think I provided a diagram some time is the past, included here again.
24787
Peter
 

4jaba6

New Member
@John,

I'll jump in while Technical is asleep ;) .

1. Relatively low value of the pullup resistor places a lower resistance "pull up" urge on the data line between the sensor and the PICAXE input. Treat the resistor like a spring. Technical mentions that the internal pullup resistor in the IR sensor is quite weak (Ie high resistance) - equivalent to a weak spring and susceptible to external electrical noise interfering with the output. The stronger pull-up makes the circuit less suseptable to noise interference.

2. You should have two wires connecting the L293D to each motor. Solder the 100nF capacitor to the two terminals of the motor. A capacitor has a low impedance to higher frequencies, so will will remove a lot of the motor's comutator noise off the supply wires. Refer to the drawing in Manual 3 "Output Devices 5 - DC "Toy" motors (Page 12 in my copy)

3. The 10nF capacitors across the L293D's power pins adds to the noise quenching, further reducing the external effects of electrical noise.

4. It is good to keep the motor power wiring as seperate as possible from the controler (PICAXE) power wires. If the motor/s and PICAXE share a power source, the wiring for the controller should run between the controller and the power source. I think I provided a diagram some time is the past, included here again.
View attachment 24787
Peter
Peter,

Thank You for the information and suggestions.

I am still struggling on how to attach my circuit drawings, so my comments shall probably not be in depth until I can attach the drawings.

Regarding the capacitors in items 2. and 3 from your message.
I assume polarity does not matter in item 2 for the capacitors across the motor terminals.
Polarity probably does matter for the capacitors across the power pins in item 3.

This may be a little preliminary until I can get the schematic attached.
item 3. "....... across the L293D's power pins....".
My circuit has two +5v power sources to the L293D:
A. One is from the 20M2 +5v power rail to pin 16 ( and intersection with a 10k resistor and on to enable pins 9 and 1 ).
B. The other is a Separate +7.5v ( not 5 ) power source to pin 8.
Are you wanting the.01uf capacitors across both these power sources or just one of them?
( by "across" I assume the capacitor is placed between the power source and ground )

Item 4:
Yes, You did provide the diagram previously.
I believe it was 9/13/2020 or very close to that date.
The topic was "5v Source for SN754410 Enable Pins".
THANKS AGAIN!
I did use your diagram to construct my L293D circuit and the tie-in to the 20M2.

Best,

John
 

Goeytex

Senior Member
To attach a file simply click on "Attach Files" at the bottom of the text input window. In the popup find the file on your PC, then select it and click on "OPEN". It will be attached.

If you drew the diagram by hand you will need scan into your PC or take a photo and then transfer it to your PC.
Alternatively you can redraw the diagram with Windows Paint or with a schematic capture program of some kind.

I did this one using LTSpice, saved it, and then marked it up with Paint.
 

Attachments

4jaba6

New Member
To attach a file simply click on "Attach Files" at the bottom of the text input window. In the popup find the file on your PC, then select it and click on "OPEN". It will be attached.

If you drew the diagram by hand you will need scan into your PC or take a photo and then transfer it to your PC.
Alternatively you can redraw the diagram with Windows Paint or with a schematic capture program of some kind.

I did this one using LTSpice, saved it, and then marked it up with Paint.
Goeytex,

Thank you for the advice.
Apologize for the delay in getting back to you.

John
 

erco

Senior Member
Using alkaline cells? Try new batteries, their voltage is dropping under load and resetting your Picaxe. Or use separate batteries for your Picaxe and motor.

Rechargeables are much better for delivering current and maintaining voltage.

If motor noise is the culprit, try 3 filter caps per motor in a delta arrangement. 0.1 uF (104) caps are typical for small DC motors, per https://www.etechnog.com/2019/06/capacitor-with-dc-motor.html
 
Last edited:

4jaba6

New Member
I have been going down several rabbit holes since first posted last August.
The one hole that did not contain rabbits was the need for noise suppression and capacitors to help with this. Inglewoodpete ( and other's ) suggestions greatly helped with this. There still are some problems with motor behavior...more on this later.

Other approaches to prevent the hangup included "timing out" with the Time variable, "Interrupts" and other ideas. None have worked satisfactorily.
While occasionally perusing the Forum, I remembered reading that a "PWMOUT" command could affect performance of code. I can not remember where I read this but in any event, I researched the command since I have IR obstacle Detection that uses it. "The Pwmout command runs continuously ( in the background ) until another pwmout command is sent. To stop, issue a pwmout pin, off (pwmout, 0,0 ). When I entered this code after using the pwmout in my obstacle detection it apparently ( so far ) solved the hangup in the IRIN code that was NOT TIMING OUT! YEAH! Going back to the original code, I saw where I did stop the command at first but later wrongly assumed that it was not needed because it was ...."0, 0", so I deleted it. A renewed lesson in coding that even the smallest of things matter!

Inglewoodpete's circuit from last August with noise suppression capacitors appeared to also help.
The motors perform reasonably well but seems to depend upon where I place that
code in the program. Not sure yet how true this is or that it is actually a factor since I hurried this missive.
I have not fully investigated this ...just VERY HAPPY to be rid of IRIN hanging up due to the PWM command not being used properly.
 
Top