I am currently running this main program on my arduino uno.
#include "speed_profile.h"
void setup() {
// put your setup code here, to run once:
output_pin_setup();
cli();
timer1_setup();
sei();
}
void loop()
{
int motor_steps = 23400;//-9600; //23400 - 100%
// Accelration to use.
int motor_acceleration = 500;//500;
// Deceleration to use.
int motor_deceleration = 500;//500;
// Speed to use.
int motor_speed = 1000; // 1000
init_tipper_position();
compute_speed_profile(motor_steps, motor_acceleration, motor_deceleration, motor_speed);
}
For some weird reason is the init_tipper_position(); not being executed, it is rather skipped from the whole program for some weird reason.
The function looks like this
void init_tipper_position()
{
digitalWrite(en_pin, HIGH);
delay(1);
digitalWrite(dir_pin, LOW);
delay(1);
int decrement = 0;
while((PINB & (1 << 2)))
{
decrement++;
digitalWrite(step_pin, HIGH);
delayMicroseconds(600);
digitalWrite(step_pin, LOW);
delayMicroseconds(600);
}
digitalWrite(en_pin, LOW);
}
I know for fact it being skipped as it doesn’t perform the task it should be performing which is,
move the motor until you hit a sensor. The motor doesn’t move, that could be due to me providing it a PWM
with an to high frequency. The other things it that the enable signal is never set. It would be impossible to
move the motor, if the en_pin was set, but as the motor can be easily moved, i guess that the en_pin isn’t being setted.
I own a logic analyzer, and have currently tested the signal of the en_pin and confirmed that it never becomes high?
So why is the program skipping the init_tipper_position(); and goes directly to compute_speed_profile()?..
All other part of the program works as it should. The sensor is not defect, i’ve tested it with a dummy program, it is capable outputting HIGH or LOW.
So something is very wrong with my program?
I’ve attached .cpp files and .h being used in the program
speed_profile.cpp (9.63 KB)
speed_profile.h (2.25 KB)
main.ino (516 Bytes)
main.ino (516 Bytes)