1/steps per sec = period dividing by 2 gives low time and high time speedspm calculated from some sort of PID in steps per sec float counter ĭigitalWrite(steppin1, !digitalRead(steppin1) I created something i would do in the most basic form for 1 motor. Hi, thank you MarkT for your reply, I don't exactly understand what you are doing in your ISR routine. Have enough granularity since STEP_AMOUNT can be a large valueĪnd the ratio of frequency to STEP_AMOUNT is the ratio of stepping Which will automatically interpolate if the phase and frequency variables It would be much simpler to do something like this in the ISR: ISR(TIMER1_COMPA_vect) This is at its core just a DDS style step generation done a rather complicatedĪnd perverse way. The subperiods simply allow finer granularity in speed for a given Just running at a set rate and checking which motor needs to be stepped byĬomparing number of interrupts in the count array against relevant periodĬounts. The setMotorSpeed() routine is setting up the period array for each motor viaĬalculateSubperiods(), the ISR is the compare-channel-A interrupt which is Īny help for any of the issue described will be appreciated. I also used this to identify the pins for the Leonardo chip which the original code is designed for. Will the code i have above work when uploaded onto a Leonardo board? (or am i missing something?)Ī simplified logic flow on what this code is doing so i can understand the process?Īnd finally i would like to use this on an arduino mega 2560 if possible, from what i understand the timer pins are different for the different chip would it be a simple matter of changing it to timer 1 pins on the mega? (11 and 12 according to this ). If anybody has any experience with this i would appreciate help with the following Also this is designed to control 2 motors yet i only see 1 timer being used in setup. I also am clueless to what the sub-periods function is doing. I'm not sure on exactly what it does though with the period array and the counter. TIMSK1 |= (1<<OCIE1A) // Enable Timer1 interruptĭigitalWrite(4,LOW) // Enable stepper driversįrom looking at this i assume that "ISR(TIMER1_COMPA_vect)" this refers to the timer interrupt event. Generally we use a divider of 8, resulting in a 2MHz timer on 16MHz CPU PinMode(12,OUTPUT) // STEP MOTOR 2 PORTD,6 PinMode(6,OUTPUT) // STEP MOTOR 1 PORTD,7 Void setMotorSpeed(uint8_t motor, int16_t tspeed)Įlse if ((speed_m - tspeed)<-MAX_ACCEL)ĬalculateSubperiods(motor) // We use four subperiods to increase resolution Period_m_index = (period_m_index+1)&0x07 įor (j=0 j subperiod=0, if module subperiod=1. Period_m_index = (period_m_index+1)&0x07 // period_m_index from 0 to 7 We need to wait at lest 200ns to generate the Step pulse. Int16_t actual_robot_speed_Old // overall robot speed (measured from steppers speed) Int16_t actual_robot_speed // overall robot speed (measured from steppers speed) Uint8_t dir_m // Actual direction of steppers motors Int16_t speed_m // Actual speed of motors So i tried to remove the part of the code which i think is for the motor. This sketch shows a fully functioning inverted pendulum robot. I have come across this open source sketch that does this. The idea for this method is to preform a non-blocking method of controlling the motors. The driver described here Easy Driver stepper motor driver. Motor and the driver takes in step and direction input. I am trying to use the onboard timer on the Arduino to control a stepper motor using a driver board.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |