FrequencyTimer2 - How to count pulses on FREQUENCYTIMER2_PIN for Stepper Motor?


while developing stepper motor sketch drilling circuit boards on 3-axis mill came across frequencytimer2 library. "frequencytimer2::setperiod(ipulsetime);" simple way set stepper motor speed without jitter.  short version of code shows how control speed , direction of 1 motor joystick included @ bottom of post.

i using st-m5045 microstep drivers nema23 stepper motors in mill.  driver set 1600 pulses per revolution of stepper motor provide resolution needed.  drill file output pcb design software simplified g-code , lists x-y coordinates of each drilled hole.

my question is:  where/how add pulse count variable in frequencytimer2 library increments 1 each time pulse sent the  "frequencytimer2_pin"?  once know add counter can add functions manage overflow , reset zero.

i need count number of pulses sent "frequencytimer2_pin"  calculate exact x-y distances moved when using joystick control.

i have studied .cpp code , not yet have enough avr timer , register knowledge understand add pulse count variable library code.  not need use interrupt function , unable figure out how counting.  believe pulse count must maintained in library avoid timing issues delays may occur in main sketch loop.

any in regard appreciated!!!

i have tried using various stepper libraries unsuccessfully st-m5045 stepper motor driver.  if knows of work-around or way make them functional larger stepper motor drivers save me lot of time too.



// stepper motor speed , direction control
// using joystick , frequencytimer2 library

// microstep driver st-m5045, steps per revolution set 1600

#include <frequencytimer2.h>

// joy stick variables
    int pinjoy1 = a0;  // used stepper motor  x-axis
    int pinjoy2 = a1;   // used stepper motor  y-axis

    int ijoy1 = 0;
    int ijoy2 = 0;

// stepper motor variables
    int ipulsetime = 0;

    int idisttotal = 0;
    int idistnet = 0;

void setup() {   
             
    pinmode(8, output);  //direction pin  connected dir- on st-m5045
    digitalwrite(8, low);
 
    pinmode(frequencytimer2_pin, output);  // pin 11 on uno board connected pul- on st-m5045

     //  st-m5045 dir+ , pul+ connected arduino 5vdc
}

void loop() {
 
    ijoy1 = analogread(pinjoy1);   // read joystick resistance value

   // 509-510 neutral output reading of joystick using
   //  full code includes calibration routine in setup()

  if (ijoy1 >= 510)  {                                                                               
        ipulsetime = map(ijoy1,509,1023,10000,200);   // map resistance value time interval
         digitalwrite(8, high);                                                // set direction clockwise
           frequencytimer2::setperiod(ipulsetime);        // set time interval timer2
           frequencytimer2::enable();                                   // turn on stepper motor
     }

     else if (ijoy1 <= 495)  {                                                             
        ipulsetime = map(ijoy1,0,517,200,10000);            // map resistance value time interval
         digitalwrite(8,low);                                                  // set direction counter-clockwise
           frequencytimer2::setperiod(ipulsetime);        // set time interval timer2
           frequencytimer2::enable();                                   // turn on stepper motor
     }

     else  {                                                            // when joystick in neutral, turn stepper motor off
        frequencytimer2::disable();
     }
   }

a link library referring make easier you.


Arduino Forum > Using Arduino > Programming Questions > FrequencyTimer2 - How to count pulses on FREQUENCYTIMER2_PIN for Stepper Motor?


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support