Help please with 20M2 inputs

#1
Hi. I'd be very grateful for a bit of guidance. I have a 20M2 board - 7 outputs & 7 inputs. The outputs work fine but I'm having trouble with the inputs and I think I must be making a fundamental error in either my programming or in the way I have configured the inputs.

1. In reading the inputs, (for example input 7) I am using the syntax 'if pinC.7 = 1 then high <6>. I think this should make output 6 'high' when input 7 is 'on'. This doesn't work :( What am I doing wrong?
2. If I want to get input 7 to remain in a loop until the input os 'on', what syntax do I use?
3. Have I connected the inputs correctly? I have assumed each input is a pair of wires from the PicAxe board and that when a connection is made between these two wires, the input is 'on' (pinC.7 = 1). When the connection is broken, the input is 'off' (pinC.7 =0).

Thanks.


using editor 6.0.9.3 on Windows XP
 

techElder

Well-known member
#2
1. In reading the inputs, (for example input 7) I am using the syntax 'if pinC.7 = 1 then high <6>. I think this should make output 6 'high' when input 7 is 'on'. This doesn't work What am I doing wrong?
Code:
if pinC.7 = 1 then
   high B.6
endif
or

Code:
if pinC.7 = 1 then : high B.6 : endif
 

techElder

Well-known member
#3
2. If I want to get input 7 to remain in a loop until the input os 'on', what syntax do I use?
Code:
do : loop until C.7 = 1 ; assuming the pin is tied LOW until activated
Add this if C.7 is driven by a switch with a finger pressing on it. This will wait in the loop until they lift the finger.

Code:
do : loop until C.7 = 0
 

hippy

Technical Support
Staff member
#4
Welcome to the PICAXE forum.

1) What you have should work but you perhaps have the syntax wrong. For a one line IF-THEN what follows must be a label. To have the HIGH 6 - which should ideally be B.6 - you would use a multi-line statement -

Code:
If pinC.7 = 1 Then
  High B.6
End If
Though that can be reduced to one line if you use colons to separate each line -

Code:
If pinC.7 = 1 Then : High B.6 : End If
2) The best way of waiting until an input goes high is the DO-LOOP -

Code:
Do
Loop Until pinC.7 = 1
Again that can be compacted onto one line by placing a colon between the DO and the LOOP. The UNTIL Can be replaced by a WHILE if that makes more sense.

3) It depends on which board you are using and how you have wired the button.

If the input has a pull-down resistor, the button should be between the input and +V and the input pin will read 1 when the button is pushed, 0 when it isn't.

If the input has a pull-up resistor, the button should be between the input and 0V and the input pin will read 0 when the button is pushed, 1 when it isn't.
 

techElder

Well-known member
#5
3. Have I connected the inputs correctly? I have assumed each input is a pair of wires from the PicAxe board and that when a connection is made between these two wires, the input is 'on' (pinC.7 = 1). When the connection is broken, the input is 'off' (pinC.7 =0).
If one of wires of the pair is tied to VCC (the power connection or HIGH level) and the other is tied to the pin which is connected to GND or LOW level with a 1K to 10K resistor, then yes you are correct.

There are several ways to do this by rearranging the electrical part and the programming logic.
 
#6
Thanks :)

Thanks for the welcome and the help.

I have resorted to running test programs to see what works.

test:
If pinC.7 <> 1 then test; pin7 is a push to make switch
high 6; switches on a lamp
pause 1000; waits a second
low 6; switches off lamp
end

this didn't work - the program ignores the 'if pinC' line and goes immediately to the next line. I'm still uncertain as to whether I'm electrically connecting the inputs correctly.

my next move is to try your suggestion...

test:
If pinC.7 = 1 Then
High B.6
pause 1000
Low B.6
End If


Hopefully, this will make the difference. This will show if the input is working.

Then

test:
Do
Loop Until pinC.7 = 1
High B.6
pause 1000
Low B.6
End If


Does this look right? What's the 'endif' command all about?

Board photo2.jpg

Thanks again.


Welcome to the PICAXE forum.



1) What you have should work but you perhaps have the syntax wrong. For a one line IF-THEN what follows must be a label. To have the HIGH 6 - which should ideally be B.6 - you would use a multi-line statement -

Code:
If pinC.7 = 1 Then
  High B.6
End If
Though that can be reduced to one line if you use colons to separate each line -

Code:
If pinC.7 = 1 Then : High B.6 : End If
2) The best way of waiting until an input goes high is the DO-LOOP -

Code:
Do
Loop Until pinC.7 = 1
Again that can be compacted onto one line by placing a colon between the DO and the LOOP. The UNTIL Can be replaced by a WHILE if that makes more sense.

3) It depends on which board you are using and how you have wired the button.

If the input has a pull-down resistor, the button should be between the input and +V and the input pin will read 1 when the button is pushed, 0 when it isn't.

If the input has a pull-up resistor, the button should be between the input and 0V and the input pin will read 0 when the button is pushed, 1 when it isn't.
 
#7
Hi. Thanks for your replies. My understanding is developing but the learning curve is steep.
Board photo2.jpg
I think this is the board I am using. The inputs are pairs numbered from 0 to 7. I had assumed that the each pair for each input was connected as you have said. However, I have not placed a resistor in any of the input circuits. Does this mean my switch across these two input wires has produced a 'short' and therefore damaged the pic? When I last did this sort of stuff, I used a proprietary 'buffer box' connected directly to a computer. The programming was very similar but I guess the buffer box provided circuit protection.



If one of wires of the pair is tied to VCC (the power connection or HIGH level) and the other is tied to the pin which is connected to GND or LOW level with a 1K to 10K resistor, then yes you are correct.

There are several ways to do this by rearranging the electrical part and the programming logic.
 
#8
Hi again. Trying desperately to get this straight in my head. Can I use this as follows...

Code:
test:
do : loop until C.7 = 1
high B.6; turn on lamp
pause 1000
low B.6
end
Will this wait indefinitely until there is a connection across the two wires of input 7 before turning the lamp on and off?
Should I place a 10k resistor in the input circuit?

Thanks again?

Code:
do : loop until C.7 = 1 ; assuming the pin is tied LOW until activated
Add this if C.7 is driven by a switch with a finger pressing on it. This will wait in the loop until they lift the finger.

Code:
do : loop until C.7 = 0
 

hippy

Technical Support
Staff member
#10
The board you have seems to be an AXE118. If so then the pins on the left are input pins with V+ next to them. Shorting the two together should take the input high. The pull-down resistors are in the 'thin black strip' component on the left; that's a Single In-Line resistor package (SIL).

Perhaps try this code ...

Code:
#Picaxe 20M2
#Terminal 4800
Do
  If pinC.7 = 0 Then
    SerTxd( "Pin C.7 is low (0)", CR, LF )
    Do : Loop While PinC.7 = 0
  Else
    SerTxd( "Pin C.7 is high (1)", CR, LF )
    Do : Loop While PinC.7 = 1
  End If
Loop
 
#12
Hi. Thanks for your input. I must admit that I haven't tried the simulator. I'm assuming it emulates the PicAxe board running a code. This would certainly be good to see if any of the code is failing to perform its intended task. I will give it a go.
:)


Hi oldbloke,
Are you using the simulator in PE6? No soldering required. Its quick & easy.

Regards bear..
 
#14
Right, so I needn't worry about having resistors in the input circuits???

Looking at the code you have suggested. I had a read of this in the manual and failed to understand most of it. However, I did find some bits. Are you suggesting that the inputs I am using may already be set 'high' and that's why the code does not respond to an open circuit on the input? Does the SerTxd command clear that? I'm right at the edge of my knowledge here.
Thanks again.


The board you have seems to be an AXE118. If so then the pins on the left are input pins with V+ next to them. Shorting the two together should take the input high. The pull-down resistors are in the 'thin black strip' component on the left; that's a Single In-Line resistor package (SIL).

Perhaps try this code ...

Code:
#Picaxe 20M2
#Terminal 4800
Do
  If pinC.7 = 0 Then
    SerTxd( "Pin C.7 is low (0)", CR, LF )
    Do : Loop While PinC.7 = 0
  Else
    SerTxd( "Pin C.7 is high (1)", CR, LF )
    Do : Loop While PinC.7 = 1
  End If
Loop
 

Technical

Technical Support
Staff member
#15
As long as you have soldered the SIL resistor (the long thin black thing) the correct way around (the dot at the correct end) then all the inputs now have a 10k pull down resistor fitted (thanks to the SIL resistor - it's basically lots of resistors in one long package).
 

hippy

Technical Support
Staff member
#16
Looking at the code you have suggested. I had a read of this in the manual and failed to understand most of it.
Basically it will report what levels are detected on the input, which should change whenever you press or release the button connected to the input pin.

If things are working as expected then it should show "Pin C.7 is low (0)" when the program first starts, show "Pin C.7 is high (1)" when the button is pressed, and "Pin C.7 is low (0)" when it is released.

What results do you get ?

If the result is always "Pin C.7 is high (1)" that suggests that your button may be permanently closed. That would most likely be a result of having wired the wrong legs of the button if it's a 6mm square button with four legs.

If it's "Pin C.7 is low (0)" then it may also be a miswiring of the button or the button may not be connected to the C.7 input point.
 
#17
Thanks. I will check that it's the right way around. Which end should the dot be?
(I built this board a few years ago but have not needed the inputs until now.)


As long as you have soldered the SIL resistor (the long thin black thing) the correct way around (the dot at the correct end) then all the inputs now have a 10k pull down resistor fitted (thanks to the SIL resistor - it's basically lots of resistors in one long package).
 
#18
Right, so this should provide feedback to my computer screen? I will give it a go.
I'm struggling a bit because the PicAxe software is on an old netbook and not my computer and the PicAxe chip is in my shed. The whole process takes a lot longer :)
Update soon.
Thanks again.


Basically it will report what levels are detected on the input, which should change whenever you press or release the button connected to the input pin.

If things are working as expected then it should show "Pin C.7 is low (0)" when the program first starts, show "Pin C.7 is high (1)" when the button is pressed, and "Pin C.7 is low (0)" when it is released.

What results do you get ?

If the result is always "Pin C.7 is high (1)" that suggests that your button may be permanently closed. That would most likely be a result of having wired the wrong legs of the button if it's a 6mm square button with four legs.

If it's "Pin C.7 is low (0)" then it may also be a miswiring of the button or the button may not be connected to the C.7 input point.
 

hippy

Technical Support
Staff member
#19
I will check that it's the right way around. Which end should the dot be?
The dot is the resistor package's common connector so should be 0V.

Code:
 .-.-.-.-.-.-.-.
 | | | | | | | |
 R R R R R R R |
 | | | | | | | |<-- Dotted leg
I don't have a board to hand to say which way round that is but if you turn the board over the 0V on the PICAXE, download socket and 0V power input should go to the resistor package pin which should have the dot.

Even if the resistor package is the wrong way round it should still work with just the one button connected.

What results do you get with the test program in post #10 ? That will help indicate what is wrong.
 
#20
Many thanks

Well, thanks to everyone for your help. SUCCESS!

The problem appears to have arisen from the syntax. I downloaded a simple bit of test code based on the advice given and the input appears to work. I tested it with two other inputs and they now work too.
So, here we go, I can now move my project onwards. Also now considering buying another PicAxe pic and devising some other control project.
Many thanks!
:)
 
#21
ANOTHER PROBLEM!

Well, the new syntax was successful and I wrote a code sequence to do the stuff I wanted. It downloaded correctly to the pic and ran faultlessly on test.
The code is designed to make a model train go around a circuit, return to it's original position and then make another model train go around the circuit in the opposite direction. This involves the PicAxe pic outputs controlling railway points solenoids through relays, another relay to reverse the polarity and two sensors to detect when each model train has left its start point and when it returns. The sensors are LDRs beneath the track that operate relays via a bit of basic electronics.

I tested the sequence with a dummy model train (no motor). It all works fine, all the 'loop until' commands, etc. However, when the actual model trains are running on the circuit, the inputs appear to go high randomly. Even worse, when the AC track cleaning pulse is in operation, the pic goes haywire and powers outputs randomly.

Bearing in mind that there are no electrical connections between the current that powers the model trains and the pic and no current connections between the current that powers the solenoids and the pic, I can only conclude that there must be some level of induced current that is corrupting the operation of the pic.

So, my next problem is, how do I solve this? The PicAxe pic is mounted within about 200mm of the relays and about 150mm from the AC track cleaning electronics.
I'd be very grateful for some guidance here. :)
 
#22
A schematic diagram and maybe a few photos of the layout of the electronics may assist folks identifying solutions.

Using twisted pairs of wires for track, AC track cleaner circuit and solenoids may help.
How is the PICAXE power sourced?
 
#23
G'Day. Thanks for your reply. Photos and a diagram or two coming up soon.

PicAxe power sourced from 12v transformer. This is the same transformer that provides power to the electronics that control the sensors. The transformer has 3 outputs, a 0 to 12v DC variable, 12v DC constant and 16v AC. The 16v powers the point solenoids. The 12v constant powers the PicAxe and sensor electronics and the 12v variable powers the model trains. This all sounds grand but it's just a small model/toy railway where the electronic bit has got a bit out of hand.

The PicAxe has worked fine until I added the sensors. Even now, everything works very well unless there's a model train actually moving on the track. This seems to indicate that the train motor is causing the problem. I have no idea why.
My next move is to attempt to put a separate power supply to the PicAxe. If that fails, I will try disconnecting the sensors temporarily and replace each one with a robust switch so that I can simulate their operation. These moves will isolate two possible causes but neither would explain why it's the model train motor that appears the cause the fault.



A schematic diagram and maybe a few photos of the layout of the electronics may assist folks identifying solutions.

Using twisted pairs of wires for track, AC track cleaner circuit and solenoids may help.
How is the PICAXE power sourced?
 

Circuit

Senior Member
#24
...everything works very well unless there's a model train actually moving on the track. This seems to indicate that the train motor is causing the problem. I have no idea why.
Model railways are a notorious source of powerful noise and interference; the motor is a really effective "spark-gap generator" and the rails act as excellent aerials. I am minded of a letter a couple of years ago in Railway Modeller where the writer found that his model railway was causing hell with neighbouring radios and television sets - he sought answers but they never seemed to appear.

To start with, try disconnecting the track cleaner - this operates by generating a spark across the dirt on the track to produce a conductive plasma through which the D.C. to the motor can run. Clean the track properly - I find that lighter fuel works best but watch out for the obvious fire hazard; I normally use cotton-bud soaked in lighter fuel to run along the tracks. Then make sure the wheels of the loco and the pick-ups that press against them are also clean.

The wires going in and out of your PICAXE chips need only tiny currents to trigger and therefore it is not at all surprising that you are experiencing these issues. My approach to my (several) model railway systems is to keep the PICAXE chips well separated electrically from the actual model railway; I use opto-couplers where there is actually an interface; and keep all the leads in and out of the chips as short as possible. Decouple the power supply properly with decent capacitance across the power terminals to avoid interference on the power lines. Please tell the vintage of your locomotives; some of the older motors are really filthy electrically whereas the newer ones generally have some form of suppression built in; usually a couple of inductances and perhaps three capacitors across the brushes and to the metal can of the motor - you may need to add suppression to your locomotive. So tell us about your circuits etc. and I am sure that we can help. I have one model railway with more than a dozen PICAXE chips controlling things and they work really reliably and effectively; it can be done.

edit: I note that you are using LDRs to trigger your PICAXE; therefore I presume you are using ADC functions; I think that this is probably where your spurious data is coming in. As suggested, try using twisted-pair cables from the LDRs to the PICAXE to minimise the induced currents from the locomotive, but I suspect that you may well have an issue on the power-lines.
 
Last edited:
#25
Wow! There's a lot there. Thank you for the guidance.
I had another go at solving it today. I tried many things such as reversing input triggers so that the pickaxe responds when the input is off. I also tried using entirely separate power supplies to isolate any problems there.
My LDR sensors are made from MERG kits. (www.merg.org.uk). I use them to operate a relay which then switches the pickaxe inputs. Having exhausted everything I can think of and having successfully tested the system without the locomotive motors actually running, I can only conclude that it is just as you suggest, the locomotives themselves. I have used twisted pairs for the electronic links but the track supply uses hefty wire running beneath the baseboard.
I have to be honest in saying that the electronics and the PIC are of more interest to me than the actual model railway and I was determined to build something that was automated. This problem is therefore a big setback.
The model train locomotives I am using are old, some are very old. None are modern. I checked for internal suppression, there is none! Similarly, the three transformers are also old. There is also 16v AC floating about which operates two point motors. All these wires criss-cross beneath the baseboard.
So, as you can see, it's all a bit of a mess.

It only appears to be inputs to the pic that are affected and inputs that happen when the model train is stationary are not affected either. So, I have been contemplating some way to make inputs only happen when the model train is isolated.
The big benefit is that all this stimulates the brain.

Any ideas would be gratefully received. :)


Model railways are a notorious source of powerful noise and interference; the motor is a really effective "spark-gap generator" and the rails act as excellent aerials. I am minded of a letter a couple of years ago in Railway Modeller where the writer found that his model railway was causing hell with neighbouring radios and television sets - he sought answers but they never seemed to appear.

To start with, try disconnecting the track cleaner - this operates by generating a spark across the dirt on the track to produce a conductive plasma through which the D.C. to the motor can run. Clean the track properly - I find that lighter fuel works best but watch out for the obvious fire hazard; I normally use cotton-bud soaked in lighter fuel to run along the tracks. Then make sure the wheels of the loco and the pick-ups that press against them are also clean.

The wires going in and out of your PICAXE chips need only tiny currents to trigger and therefore it is not at all surprising that you are experiencing these issues. My approach to my (several) model railway systems is to keep the PICAXE chips well separated electrically from the actual model railway; I use opto-couplers where there is actually an interface; and keep all the leads in and out of the chips as short as possible. Decouple the power supply properly with decent capacitance across the power terminals to avoid interference on the power lines. Please tell the vintage of your locomotives; some of the older motors are really filthy electrically whereas the newer ones generally have some form of suppression built in; usually a couple of inductances and perhaps three capacitors across the brushes and to the metal can of the motor - you may need to add suppression to your locomotive. So tell us about your circuits etc. and I am sure that we can help. I have one model railway with more than a dozen PICAXE chips controlling things and they work really reliably and effectively; it can be done.

edit: I note that you are using LDRs to trigger your PICAXE; therefore I presume you are using ADC functions; I think that this is probably where your spurious data is coming in. As suggested, try using twisted-pair cables from the LDRs to the PICAXE to minimise the induced currents from the locomotive, but I suspect that you may well have an issue on the power-lines.
 

hippy

Technical Support
Staff member
#26
One option may be to put PICAXE chips at the LDR ends. That way a more significant hard-on or hard-off signal can be passed back to the master. Higher voltages are more immune to noise and removing glitches can merely require a capacitor, maybe a resistor.

If noise is really bad then quite high voltages can be used with appropriate transmit and receive buffers. The higher the voltage the less the fixed noise will be once attenuated for use. Differential signalling can also help. As can using screened cable.

There may still be induced noise and glitches on the LDR signals, but a PICAXE dedicated to just monitoring the LDR can use noise and glitch removal techniques to filter those out.

If it comes to it, it may be possible to rewire the board so all the noise is in one half, kept well away from the PICAXE in the other.

Before doing anything I would propose you temporarily replace your actual software with something which just monitors the LDR and reports oddities. That may indicate what type of problem you actually have and clarify the circumstances in which it occurs.

You don't want to strip down the board, re-build it, or spend a lot of time or money on something which isn't actually the problem. It does look like it's just 'train running' noise but the more you can be confident that it is the better.

That also gives a platform for trying different things, even simple capacitors, to see what improves the situation and what doesn't.
 
#27
Thank you. I will look at these issues. Moving the PicAxe board away from the rest of the electromagnetic noise might be a good place to start. It's currently in the thick of it.
I'll report back on how things go. :)


One option may be to put PICAXE chips at the LDR ends. That way a more significant hard-on or hard-off signal can be passed back to the master. Higher voltages are more immune to noise and removing glitches can merely require a capacitor, maybe a resistor.

If noise is really bad then quite high voltages can be used with appropriate transmit and receive buffers. The higher the voltage the less the fixed noise will be once attenuated for use. Differential signalling can also help. As can using screened cable.

There may still be induced noise and glitches on the LDR signals, but a PICAXE dedicated to just monitoring the LDR can use noise and glitch removal techniques to filter those out.

If it comes to it, it may be possible to rewire the board so all the noise is in one half, kept well away from the PICAXE in the other.

Before doing anything I would propose you temporarily replace your actual software with something which just monitors the LDR and reports oddities. That may indicate what type of problem you actually have and clarify the circumstances in which it occurs.

You don't want to strip down the board, re-build it, or spend a lot of time or money on something which isn't actually the problem. It does look like it's just 'train running' noise but the more you can be confident that it is the better.

That also gives a platform for trying different things, even simple capacitors, to see what improves the situation and what doesn't.
 
#28
Moving on. I figured a good place to start might be to return to the original code that was running on the picaxe before I added the LDR sensors. This employed no inputs and the stages of the code were controlled by 'pause' commands. This didn't work, the outputs are corrupting now too.
Two questions:
1. Could the 4.5v battery pack that powers the pic be a problem?
2. I have a spare set of pic axe chips for this board. Is it worth swapping them over?
 

hippy

Technical Support
Staff member
#29
Check the batteries aren't flat, try new ones, but there shouldn't be any problem in using a battery supply.

Yes, it's worth swapping PICAXE over to see if they all demonstrate the same issue or not.

How are the outputs corrupting; what is actually happening ?

Have you tried disconnecting the LDR from the PICAXE inputs rather than just not using them ? If there is a big enough spike being induced on the wires that may be enough to upset the PICAXE even if those inputs are not being used.

Have you added #TERMINAL and a SERTXD("RESET") message at the start of the program so you can check if it is being reset ?

Perhaps post your code and circuit diagram.
 
#30
Thanks again.

Check the batteries aren't flat, try new ones, but there shouldn't be any problem in using a battery supply.
I have tried new batteries - no luck. Maybe I'll try some Duracells.

Yes, it's worth swapping PICAXE over to see if they all demonstrate the same issue or not.
I will try this tomorrow. Shed is cold right now.


How are the outputs corrupting; what is actually happening ?
I have 5 outputs. 4 of them operate point motors through 4 small 12v relays. The output is high for half a second. This is enough to push the point actuator solenoid across. The 5th output operates a DPDT relay that reverses the polarity to the track. Mostly, the polarity relay drops out randomly, there's no pattern to it. The point actuating outputs fire randomly, still in ½ second pulses. The code fails to end and will keep doing random stuff until I switch off. It's almost like the pic has lost it's position in the code sequence.

Have you tried disconnecting the LDR from the PICAXE inputs rather than just not using them ? If there is a big enough spike being induced on the wires that may be enough to upset the PICAXE even if those inputs are not being used.
Yes. I have isolated them totally. The track cleaner is also isolated.

Have you added #TERMINAL and a SERTXD("RESET") message at the start of the program so you can check if it is being reset ?
No. I wasn't sure of the syntax . I will try this as there are indications that the pic has not always reset. It frequently fails to start at all.

Perhaps post your code and circuit diagram.
I need to copy this from the old Netbook I use for pic axe. Later this evening (probably). :)
 

lbenson

Senior Member
#31
I need to copy this from the old Netbook I use for pic axe. Later this evening (probably). :)
If this is your only copy, you should develop the habit of making a copy (e.g. to thumb drive) whenever you have made changes. PICAXE code cannot be recovered from the programmed chips in the event the source is lost.

Otherwise I can provide no help concerning your problems--sorry.
 
#32
If this is your only copy, you should develop the habit of making a copy (e.g. to thumb drive) whenever you have made changes. PICAXE code cannot be recovered from the programmed chips in the event the source is lost.

Otherwise I can provide no help concerning your problems--sorry.
Fortunately, PE6 can create periodical backups of your code, if you have enabled the feature. Refer to "Workspace Explorer", Options (spanner/shifter icon), "Backup" Tab.

Of course, it is likely to be on the local drive, unless the PC is networked and/or cloud enabled.
 

hippy

Technical Support
Staff member
#33
there are indications that the pic has not always reset. It frequently fails to start at all.
That sounds like the download serial pin is floating, or whatever is meant to pull it low has become detached. That could explain both not starting and being affected by electrical noise.
 
#34
If this is your only copy, you should develop the habit of making a copy (e.g. to thumb drive) whenever you have made changes. PICAXE code cannot be recovered from the programmed chips in the event the source is lost.

Otherwise I can provide no help concerning your problems--sorry.
You are absolutely right. :)
 
#35
Fortunately, PE6 can create periodical backups of your code, if you have enabled the feature. Refer to "Workspace Explorer", Options (spanner/shifter icon), "Backup" Tab.

Of course, it is likely to be on the local drive, unless the PC is networked and/or cloud enabled.

Nothing that good I'm afraid. It's an old Netbook running WinXP. No network and no wifi. I have just made a copy to a USB flash drive.
 
#36
That sounds like the download serial pin is floating, or whatever is meant to pull it low has become detached. That could explain both not starting and being affected by electrical noise.

Okay, so how do I solve this? Does it matter if the download lead is still plugged in? Is the potential problem within the pic? It seems strange that it used to work properly and now seems to be having this problem.
 
#37
Here's the code I have been using.

Sorry this is a long and tedious post.

Here's the code I have been using. There may be a few typos because I had difficulty moving the text between computers and therefore typed it in.

The model railway consists of a simple oval of track.
Along the nearest side there is a double section where trains can pass. This section has a point at each end.
A train running clockwise runs through the 'east' point which is set 'right'. The last little bit of the passing section is isolated so that the train will stop unless the West Point is set left.
A train running anti-clockwise runs through the 'west' point which is set 'right'. The last little bit of the passing section is isolated so that the train will stop unless the East Point is set left.
So starting and stopping of the trains in the passing loop is controlled by the position of the points.
LDR sensors under the track go dark when train is waiting in isolated section of passing tracks. When dark, a relay switches pickaxe input to 'on'. (Inputs 6 and 5)
Point solenoids are activated through relays.
Polarity is switched by DPDT relay.

I have tried stepping through the code by moving the 'end' command.
Input 7 sometimes fails to start the sequence. It all works until the locomotive is actually running. Then the whole sequence goes haywire. (Subroutines happen randomly). I have checked that the operation of the sensors is consistent by placing a multimeter across them.

Code:
main:

gosub starter; wait for start switch to be pressed

low B.4; sets polarity relay to off
gosub eastright
gosub westleft; clockwise train leaves

do: loop until pinC.6 <> 1; waits until sensor goes 'light' indicating that the train has departed
pause 5000; pause allows train to clear west points

do: loop until pinC.6 = 1; under-track sensor - when 'on' indicates that clockwise train has returned to passing loop
gosub westright; points change and isolate westbound passing loop

pause 20000; just a delay

high B.4; sets track polarity relay on
gosub eastleft; anti-clockwise train leaves 

do: loop until pinC.5 <> 1; waits until sensor goes 'light' indicating that the train has departed
pause 5000; pause allows train to clear east points

do: loop until pinC.5 = 1; under-track sensor - when 'on' indicates that anto-clockwise train has returned to passing loop
gosub eastright; points change and isolate eastbound passing loop

pause 20000; just a delay

low B.4; polarity relay off

goto main
end

_________
starter:
do: loop until pinC.7 = 1;starter switch
pause 1000; one sec pause
return
_________
eastleft:	high 0; east point set LEFT		
		pause 300; output 0 pulses east point solenoid to operate point
		low 0
		return
_________
eastright:	high 1; east point set RIGHT
		pause 300
		low 1
		return
__________
westleft:	high 2; west point set LEFT
		pause 300
		low 2	
		return	
____________		
westright:	high 3; west point set RIGHT
		pause 300
		low 3
		return
____________
 

lbenson

Senior Member
#38
Your code runs fine for me in simulation (once the "____" lines are removed). This is a longish thread, so I'm not sure what has been covered.

Do all of the inputs have pulldown resistors so that they are not floating (which could cause them to be especially succeptible to noise)?

To check for resets, place "sertxd("Restarting",cr,lf)" before main.

To confirm that the program is proceeding as you anticipate, place sertxd statements in each of your subroutines, e.g., "sertxd("eastright ",cr,lf)".

If it's going wrong or timing is off, post sertxd output. To show timing off, you might want to add ",#time" to your sertxd statements before ",cr"--on M2 PICAXEs this will show the elapsed runtime in seconds.

Can you obtain/borrow an engine which does have noise suppression in order to test further?
 
Last edited:
#39
Your code runs fine for me in simulation (once the "____" lines are removed). This is a longish thread, so I'm not sure what has been covered.
That's good to know. Thank you.
It has been a long thread. As far as I'm aware, the resistors are included in the pic axe board.

Do all of the inputs have pulldown resistors so that they are not floating (which could cause them to be especially succeptible to noise)?
As far as I'm aware, the resistors are included in the pic axe board. This bit goes beyond my understanding. My inputs are literally just switches (relays) across the pairs of connections for each input on the pic axe board.

To check for resets, place "sertxd("Restarting",cr,lf)" before main.

To confirm that the program is proceeding as you anticipate, place sertxd statements in each of your subroutines, e.g., "sertxd("eastright",cr,lf)".
This has been suggested earlier in the thread. I will do this.

Can you obtain/borrow an engine which does have noise suppression in order to test further?
Possibly. I don't know anyone who has such stuff.

I have today replaced the two chips on the pic axe board with new ones. I'm hoping this may help. Failing that, I'm looking at moving the position of the picaxe board.
An earlier post suggested that the 'Download serial pin' might be floating. I have no idea what this means or how to check or solve. Maybe the new chips and a new download of the code will work.
Thank you for your input. This has been a long thread but I have learnt a lot from it and the more I learn, the more ambitious I get. That's no bad thing. :)
 

lbenson

Senior Member
#40
... An earlier post suggested that the 'Download serial pin' might be floating. I have no idea what this means or how to check or solve. Maybe the new chips and a new download of the code will work.
If the 'Download serial pin' is floating, that would mean that the download circuit as shown in Manual 1 on page 8 is not in place. That is not likely if you are using a board from Rev-Ed, and if it were the case you would not be able to download a program (unless your download cable was custom-built and included the download circuit resistors, in which case disconnecting it would leave your serial download pin floating--but that does not appear to be the case).

Reprogramming the new chip with the sertxd statements added would seem to be your best step. Then you should be able to see everything that your code is doing--with and without engines on the tracks (assuming you are able to operate the pinC.6 and pinC.7 inputs with no train present).

(Another thought--are your switches "debounced" so that you don't get multiple repeated activations? But I think your PAUSEs should take care of that.)
 
Last edited:
Top