Compare commits
No commits in common. "b93a01f8c5fd0d963c7cbd7d786688000e294a4e" and "87b1cb9acd39f8cdf366aff799cb8356478e67f5" have entirely different histories.
b93a01f8c5
...
87b1cb9acd
2 changed files with 3 additions and 18 deletions
|
|
@ -49,11 +49,9 @@
|
||||||
#define SPEED_PIN PB2 // Pin 7/ADC1
|
#define SPEED_PIN PB2 // Pin 7/ADC1
|
||||||
#define BUTTON_PIN PB4 // Pin 3 - Button input
|
#define BUTTON_PIN PB4 // Pin 3 - Button input
|
||||||
|
|
||||||
#define MOTOR_RAMPDOWN_DIST 16
|
|
||||||
#define MOTOR_PULSE 6 //uS motor base pulse
|
#define MOTOR_PULSE 6 //uS motor base pulse
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*The timing of "ticks" is dependent on the AVR timer's counter register
|
/*The timing of "ticks" is dependent on the AVR timer's counter register
|
||||||
* so for an 8bit register the maximum value is 256. Given we stick with
|
* so for an 8bit register the maximum value is 256. Given we stick with
|
||||||
* a 1Mhz cpu frequency can use this formula to calculate the number of
|
* a 1Mhz cpu frequency can use this formula to calculate the number of
|
||||||
|
|
|
||||||
19
src/main.c
19
src/main.c
|
|
@ -142,23 +142,11 @@ void MotorMoveTo(uint8_t target) {
|
||||||
|
|
||||||
uint8_t on_delay = ReadSpeed();
|
uint8_t on_delay = ReadSpeed();
|
||||||
uint8_t pos = ReadFader();
|
uint8_t pos = ReadFader();
|
||||||
uint8_t delta = diff(target, pos);
|
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
|
|
||||||
while (delta > 0) {
|
while (diff(target, pos) > 4) {
|
||||||
pos = ReadFader();
|
|
||||||
delta = diff(target, pos);
|
|
||||||
|
|
||||||
//Impliment a ramp down when near target position.
|
|
||||||
if(delta <= MOTOR_RAMPDOWN_DIST){
|
|
||||||
//Ignore speed value and set for 50% speed.
|
|
||||||
on_delay = 127;
|
|
||||||
}
|
|
||||||
//Otherwise use the speed input.
|
|
||||||
else{
|
|
||||||
on_delay = ReadSpeed();
|
on_delay = ReadSpeed();
|
||||||
}
|
pos = ReadFader();
|
||||||
|
|
||||||
if (target > pos) {
|
if (target > pos) {
|
||||||
MotorMove(1);
|
MotorMove(1);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -173,7 +161,6 @@ void MotorMoveTo(uint8_t target) {
|
||||||
for (; idx < 255; idx++) {
|
for (; idx < 255; idx++) {
|
||||||
_delay_us(MOTOR_PULSE);
|
_delay_us(MOTOR_PULSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
@ -284,7 +271,7 @@ static void UpdateButtonOutput(btn_state *b) {
|
||||||
if (b->is_active) {
|
if (b->is_active) {
|
||||||
|
|
||||||
/*If already in saved position then go back to original pos.*/
|
/*If already in saved position then go back to original pos.*/
|
||||||
if(diff(MotorGetSavedPos((uint8_t *)POSITION1_ADR), ReadFader()) <= 3){
|
if(diff(MotorGetSavedPos((uint8_t *)POSITION1_ADR), ReadFader()) < 4){
|
||||||
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION2_ADR));
|
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION2_ADR));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue