Simple uP for precise timing of I/O pins

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
MJHanagan
 
Posts: 42
Joined: Tue Dec 09, 2014 5:25 pm

Simple uP for precise timing of I/O pins

Post by MJHanagan »

I am building a controller for a Lionel model train setup. My ultimate goal is to control the train via a web page on my iPhone. I have just recently discovered how easy it is to use a Raspberry Pi for controlling such things. I have one RPi programmed to collect data from my weather station and control some landscape lighting. I am using some simple Python and Flask code which was relatively easy to learn. So I would like to use a RPi as the main controller for the train setup.

The speed control of 3-rail Lionel trains is done by phase-angle triggering of the AC track voltage. I have a zero cross detector that triggers on and off as the AC track voltage passes through 0 volts so I have an input signal which marks the beginning/end of each AC phase. What I now need is the controller to react to this signal mark and wait a designated period of time before triggering the output pin which turns on the Triac to apply voltage to the track. The wait period from the zero cross input signal ranges from about 1 msec (95% power) to 4.2 msec (50% power) to about 7.5 msec (5% power). In order to maintain a reasonable consistency in speed I want the triggering of the Triac to be within 0.1 msec of the target time. The timing gets a bit more complicated as the train's internal sound circuitry (bell and whistle) are triggered by adding a +0.5V or -0.5V DC offset to the track voltage. This is done by altering the timing of the Triac turn-on signal during the positive AC cycle and the negative AC cycle. And it appears as though this DC offset needs to be maintained for a minimum of 3-5 consecutive AC cycles in order for the train to detect and respond to the signal offset.

I initially assumed that the RPi would be capable of 0.1 msec timing control but I now have doubts about this. I have observed several on many occasions that the RPi seems to be unresponsive for periods of time (up to a few seconds), presumably when the Linux OS is off "taking care of business". Most recently, I have been playing with servo motors on the RPi using Python and the RPi.GPIO library and find that uncertainties in output pulse timing causes jittering of the motors. So here is my basic question: is there a simple to use microprocessor that is easy to program that can maintain the Triac triggering to 0.1 msec? I have experience with the Parallax Propeller microprocessor but this seems like overkill for such a simple task, likewise using an Arduino.

Would something like a Trinket uP be capable of maintaining this type of timing? The uP would need I2C or SPI capabilities to facilitate communication of the positive and negative phase angle timing parameters from the RPi. And, can the Trinket be programmed using CircuitPython to accomplish these tasks and maintain the necessary timing?

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Simple uP for precise timing of I/O pins

Post by adafruit_support_mike »

You're right that a RasPi will have trouble producing signals that are stable to 100uS, but a microcontroller can generate signals at that rate easily.

It's fairly common to use microcontrollers in parallel with a RasPi. The RasPi does the serious number crunching and data-intensive work, and the microcontroller handles things like time-critical signals. It's usually easiest to use a Serial connection between the microcontroller and RasPi so they can communicate.

User avatar
MJHanagan
 
Posts: 42
Joined: Tue Dec 09, 2014 5:25 pm

Re: Simple uP for precise timing of I/O pins

Post by MJHanagan »

Which of your microcontrollers would you suggest if I wanted a minimum of ±100 µsec precision on the IO pin timing (Feather, Trinket, Teensy, etc)? Being able to program in a language as simple to learn as Python or Micro/CircuitPython would be a plus. I have managed to avoid learning C/C++ and would like to keep my streak for a bit longer if possible. I did manage to learn Parallax's SPIN and PASM (the Propeller chip's assembly language) but it was time consuming and a bit frustrating on certain occasions.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Simple uP for precise timing of I/O pins

Post by adafruit_support_bill »

The M0 Express will run CircuitPython: https://www.adafruit.com/product/3505
You will lose some speed due to the python interpreter overhead, but I'd expect that the M0 running at 48MHz should still be capable of the achieving the timing precision you need.

If not, you can always program it in C++.

User avatar
plutonic
 
Posts: 89
Joined: Wed Jan 06, 2016 3:21 am

Re: Simple uP for precise timing of I/O pins

Post by plutonic »

You might also look at the Beaglebone Black, which has two realtime coprocessors (PRU's) that you can program in C. They are 32 bit processors that run at 200 mhz and have completely deterministic timing (no caches or pipelines). They should be able to easily handle neopixel timing. Also look at the DotStar led strips which cost a little more than the neopixels, but don't need accurate timing since they use a separate clock signal that your software controls.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”