Stepper motor driver with pulse and direction interface

Posted on
  • I am tinkering with a NEMA 23 stepper motor and a motor drive that has a pulse input, a direction input and an enable input. The motor is driving an indexing table with a 3M timing belt, with gears that give 8:1 reduction.
    The drive can accept pulse frequency up to 200kHz. The motor is a common two winding bipolar with 1.8 degree step angle, and if not micro stepping I think that 1kHz frequency is fine. But I would like to take advantage of the micro stepping capability which means the pulse frequency must be much higher.
    I expect that the mass that is mounted to the indexing table can be large, so to avoid problems with stalling, position errors etc I am trying to optimize the acceleration (ramp up and ramp down of the stepping frequency).
    My question is what limitations I should expect from the changeInterval() function. I assume there is a 1ms resolution limit. is there a better way to control the pulse frequency accurately and with higher frequency than 1kHz?

  • Well, the average resolution of setInterval is actually very high (1 uS) but the speed of execution of JavaScript is really going to cause you problems - so while you could maybe get nearer 8kHz with a few lines of the inline assembler, other bits of JavaScript that run will get in the way of it.

    It's a bit difficult really... You can get an accurate, very high pulse rate using the built-in timers and analogWrite, but crucially you won't be able to accurately count how many pulses have been sent out.

    So if you really want the higher speeds with Espruino I guess you have three options - none of which is great:

    • Use peek and poke to set up one of the hardware timers as a counter, then use that counter to count the number of pulses that have been sent with the analogWrite command.
    • Some of the hardware timers have a register for 'repeat count'. I don't know if you could somehow set/query that with peek and poke in order to make sure that you sent out only the amount of pulses that you wanted.
    • Modify Espruino's source so that you can use the software timer (in jstimer.c) to do what you want. It's what is used for digitalPulse/Waveform/etc and is capable of sending repeated pulses at relatively high (~50kHz?) rates. You'd have to add something such that it could keep track of how many pulses had been sent, and so that you could also change the interval between them.
  • Thanks. I will have to look into those options as time allows. This is not a high priority project right now. Perhaps I could generate the pulses with acceleration ramps in hardware and count the number of pulses to know the position.

  • Gordon,

    Have you seen the new NXP dual-core mcu[1] which starts at $2(for 256K/108K flash/ram) ? it might be a good fit to enable Espruino with real-time :

    1 core could run Espruino with all it's benefits especially with high ram. Another core run Arduino/Mbed,exactly for those real-time tasks. People who don't care to learn Arduino/Mbed, but want to add some real-time stuff can easily copy code from the net.

    I believe there are even ports of the mbed to the lpc4500(a board called bambino-200) , which is another dual core chip from nxp, so it might make the job easier.

    [1]http://www.eetimes.com/document.asp?doc_­id=1324539&

  • Hi Jack,

    Looks interesting - however from my point of view, making people use two separate IDEs and languages goes against the idea of Espruino a bit - it should be nice and easy to use. The micro itself is capable of realtime without needing a separate processor - it's just how you expose it to the programmer.

    I will probably add the ability to run (native) code in interrupts (and timers) soon, which should make life a lot easier. Things like counting pulses could be done in a few lines of assembler and then rolled up into a module so that the programmer using it didn't have to care about it.

  • I will probably add the ability to run (native) code in interrupts
    (and timers) soon

    That would be great this would allow me to add half duplex RS485 comms easily.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Stepper motor driver with pulse and direction interface

Posted by Avatar for tage @tage

Actions