Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

simple arduino pulse occupancy detection

6466 views
9 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    July 2009
  • From: lavale, md
  • 4,640 posts
simple arduino pulse occupancy detection
Posted by gregc on Saturday, March 31, 2018 2:11 PM

i'm looking for simple ...

the basic idea of the pulse occupancy detector is that when something on the track draws current, that current passes thru the transformer and with DCC, a pulse is generated with each change in track polarity.   That pulse is used to discharge a capacitor that slowly charges when there are no pulses.   The capacitor voltages affects some sense voltage in the circuit used to indicate occupancy.

but i think the pulse transformer output, properly limited (diode, transistor, resistor), can be connected to an interrupt on a processor like Arduino.  The interrupt routine can set a flag.   A monitor routine checks the flag to determine occupancy,   clearing it when set.

If an interrupt is not available, a capacitor can be added and a digital input monitored.

no separate occupancy detector circuit board.

greg - Philadelphia & Reading / Reading

  • Member since
    May 2004
  • 7,500 posts
Posted by 7j43k on Saturday, March 31, 2018 2:40 PM

.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Saturday, March 31, 2018 3:23 PM

 Since a 555/556 is so cheap, I wouldn;t bother - the output of the circuit is directly usable as an Arduino input. Also a polled system scanning for pin status is more than fast enough to catch block occupancy without dealing with interrupts - which can be a pain with Arduino, depending on which model you use. If you program to the native Atmel without the Arduino overlays, you can utilize the interrupts in a more normal manner.

                                   --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2009
  • From: lavale, md
  • 4,640 posts
Posted by gregc on Saturday, March 31, 2018 4:06 PM

the capacitor in the Paisely's circuit effectively captures the occupancy state.  While the 556 provides hysterisis, it primarily drives the output that may be connected across a length of wire.   There's no need for a strong drive circuit if the circuit is on the Arduino.  SW can debounce the input lacking hysterisis.

if an interrupt is used, there's no need for a capacitor.

i have limited space on my Arduino boards which already have circuitry for other functions.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Saturday, March 31, 2018 6:00 PM

 I'm sure it would detect. Instead of a 556 (for 2 detectors), a Schmidt trigger might work, just to give a steady detection output. If you simulate the circuit in some Spice variant, you can get an idea of how it works - the cap charges with half the DCC signal, drains through the resistor during the other half, until it hits the threshold to flip the 555. Certainly you can detect that with an Arduino and I suppose also eliminate a pot for detection sensitivity and just adjust in it software. I'm not sure the interupt would be a way to go. Too many false triggers, I think, without some hysterisis in the circuit. Plus interrupts are limited, you'd need a lot more boards.

                                       --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2009
  • From: lavale, md
  • 4,640 posts
Posted by gregc on Saturday, March 31, 2018 6:37 PM

don't see why I need a Schmidt trigger. 

The capacitor charges when there are no DCC pulses.  When fully charged, the voltage across R2 is ~zero volts.  It remains charged as long as the block is not occupied.

i believe the RC time constant is 2.2 seconds (1.1M 1.01M, 2.2 uF)

as soon as there is a DCC polarity change, a pulse is generated and the capacitor is discharged thru the transistor.   This raises the trigger/threshold voltage to ~Vcc (1M / (10K + 1M)).   The capacitor is continually discharged every other DCC transistion, at least every 200 usec, as long as the block is occupied.

after becoming unoccupied, the capacitor slowly charges.   The 555 switches states once it is above 2/3 the voltage across R2 is below 1/3 Vcc.   Debouncing a digital input will do likewise.

i don't think such a long time constant is necessary, but I believe Paisley chose it to provide a delay when reporting unoccupied.

 

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Monday, August 27, 2018 6:05 PM

 Revisiting this because I toook advantage of a day off to play around with some of this stuff.

 I came across an article here: http://thenscaler.com/?p=1080 on directly wiring a current transfoemr to an Arduino. So I decided to do some experimenting. These GikFun circuits are less than $2 each, and I was thinking even if I use say an ATTiny85 for each detector (to do the hysteresis and sensitivity in software), this would be under $4/block for detectioon. Technically an ATTiny85 could handle 2 transformers and 2 outputs, which makes it under $3/block. That beats anything available commercially.

 Not being a complete idiot, I decided to test the transformer output before actually hooking it to an Arduino.  The results were noot too promising. In the article, he ran 3 loops around the transformer. I started there, and quickly backed down to just a single pass through the donut hole, based on the high voltages I was getting. I'm not sure how that guy is connecting them directly to either the Arduino (max 5 volts an an ADC input) or the ADC shield he is using (which has a max 10V input, or +/-10V in differential mode. Because with just ONE loco, not even moving, drawing an indicated 10ma, I was measuring 8V P-P. In the momentary time of a short before power is disconnected - it peaks as high as 40+ volts! 1 loco, moving, but with the sound muted, is a little rough to follow, even on a single piece of flex, but the voltage is all over, 15-20V P-P. No way can this be directly connected to an Arduino analog pin without frying something. Definitely will need at least a pair of diodes to clamp the voltage swings. 

 The GikFun sensor kits come with a resistor that goes across the coil pins, and you then detemine current based on the drop across this resistor. With that in place, the loco, running or not, or a 10K resistor placed accross the track, does not result in noticeable output. Which makes sense because the sensor module is specified to be 5mv at 5 amps.

 That was a simple quicky test. I will have to make this a bit more complex and see if I can get something that returns a resonable resolution while not killing whatever I have this drive in case of a full 5 amp short - the inrush of a QSI loco also caused a peak over 40 volts for a brief flash.

                          --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2009
  • From: lavale, md
  • 4,640 posts
Posted by gregc on Monday, August 27, 2018 6:35 PM

i hadn't planned on updating this post until after the summer when i had a chance to integrate it into a signal system.  I did build a couple circuits and tested them.  I wrote some notes,

rrinker
I'm not sure how that guy is connecting them directly to either the Arduino (max 5 volts an an ADC input) or the ADC shield he is using (which has a max 10V input, or +/-10V in differential mode.

relying on the pull-up of an Arduino digital input, the circuit (partial Paisley's) is just an open-collector driver using a capacitor to ride thru the DCC polarity reversals and doesn't require any power.

A single Arduino (a node in a signaling system) can support multiple of these or other inputs.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Monday, August 27, 2018 6:35 PM

 So that was quick. I notice it appears Dick Bronson puts a potentiometer across the coils in his detector circuit (no schematic, but looking at pictures of the board). So I put a 10k pot across the coil and measure the output. With some adjustment, I got it to read 2mv with nothing on the rails, 5mv with a 10k resistor across the rails, and putting two locos on and then holding the QSI-equipped Atlas Trainmaster (can't stall it, the wheels still slip) while at top speed, drawing nearly 600ma, the peak voltage across the pot is 2V. This keeps it in range of the Arduino, except possibly in a short (I was using my bench meter and the peak hold works differently than a handheld, so I have to review exactly how to make it work). Or I could just use a pair of diodes to clamp the voltage between the rails (less the diode drops). Don't think it gets much simpler and still would work from one car left in a block all the way up to a derailment shorting the rails out.

                                   --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Monday, August 27, 2018 9:42 PM

 Part of the problem is there never was any data cheet for the original transformer Rob used. I built one about 12 years ago based on his circuit using a transformer that was supposed to be similar, but it wasn't, and it never worked. At the time I didn;t have the tools I do not to see what's going on.

 It seems these el-cheap Chinese ones (I've since found them bare, without GikFun's PCB, resistor, and 2 pin header, even cheaper) are 1:1000. WAAAAAY too much. So I swapped in one of these other ones I have (Coilcraft CS1200L - 1:200) and I got better results, I can get it to where a single 10K is a 2mV change and really pinning down the loco and drawing nearly a full amp (another loco also on the track) the peak is around 4V. But a 10K pot is useless, I can't turn it much more than 2-300 ohms or the peak output goes way too high.

 What I need to do is get some 1:50 transformers which seems to be what every other circuit uses. Such at the ones here: 

http://dcc-mueller.de/wire4dcc/sensor_e.htm

 There are some pretty simple direct interface ones here.

                              --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!