Compare commits
No commits in common. "87b1cb9acd39f8cdf366aff799cb8356478e67f5" and "deaa59f5a294c0e5903fec567aa54743a0321ed8" have entirely different histories.
87b1cb9acd
...
deaa59f5a2
4 changed files with 19 additions and 19 deletions
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
# Use the fancy version substitution
|
# Use the fancy version substitution
|
||||||
project(main
|
project(main
|
||||||
VERSION 0.2.4
|
VERSION 0.2.2
|
||||||
DESCRIPTION "template for cmake + cpputest"
|
DESCRIPTION "template for cmake + cpputest"
|
||||||
LANGUAGES C CXX
|
LANGUAGES C CXX
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,9 @@ set(AVR_MCU attiny13a)
|
||||||
|
|
||||||
#set(F_CPU 16000000UL)
|
#set(F_CPU 16000000UL)
|
||||||
#set(F_CPU 8000000UL)
|
#set(F_CPU 8000000UL)
|
||||||
#set(F_CPU 9600000UL)#AVR without prescaler
|
#set(F_CPU 9600000UL)
|
||||||
set(F_CPU 1200000UL) #AVR (9.6MHz) with prescaler 8DIV
|
set(F_CPU 1200000UL)
|
||||||
#set(F_CPU 4800000UL) #AVR without prescaler
|
#set(F_CPU 4800000UL)
|
||||||
#set(F_CPU 600000UL) #AVR (4.8MHz) with prescaler 8DIV
|
|
||||||
|
|
||||||
add_compile_definitions(F_CPU=${F_CPU})
|
add_compile_definitions(F_CPU=${F_CPU})
|
||||||
# add_compile_definitions(MCU=atmega328p)
|
# add_compile_definitions(MCU=atmega328p)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
#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_PULSE 6 //uS motor base pulse
|
#define MOTOR_PULSE 1 //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
|
||||||
|
|
@ -105,7 +105,7 @@ void InitProg(void);
|
||||||
/**
|
/**
|
||||||
* @brief Reads the ADC pin from the fader.
|
* @brief Reads the ADC pin from the fader.
|
||||||
*/
|
*/
|
||||||
uint8_t ReadFader(void);
|
uint16_t ReadFader(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
25
src/main.c
25
src/main.c
|
|
@ -104,7 +104,7 @@ uint8_t ReadSpeed(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// change to ReadFader(void)
|
// change to ReadFader(void)
|
||||||
uint8_t ReadFader(void) {
|
uint16_t ReadFader(void) {
|
||||||
// Initialize ADC
|
// Initialize ADC
|
||||||
ADMUX = (1 << MUX1) | (1 << MUX0); // Select ADC3 (PB3)
|
ADMUX = (1 << MUX1) | (1 << MUX0); // Select ADC3 (PB3)
|
||||||
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
|
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
|
||||||
|
|
@ -112,7 +112,7 @@ uint8_t ReadFader(void) {
|
||||||
ADCSRA |= (1 << ADSC); // Start conversion
|
ADCSRA |= (1 << ADSC); // Start conversion
|
||||||
while (ADCSRA & (1 << ADSC)) {
|
while (ADCSRA & (1 << ADSC)) {
|
||||||
} // Wait for conversion to finish
|
} // Wait for conversion to finish
|
||||||
return (uint8_t)(ADC >> 2);
|
return ADC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -129,24 +129,25 @@ static inline uint8_t diff(uint8_t a, uint8_t b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorSetSavePos(uint8_t *ADR) {
|
void MotorSetSavePos(uint8_t *ADR) {
|
||||||
uint8_t pos = ReadFader();
|
uint8_t pos = (uint8_t)(ReadFader() >> 2);
|
||||||
eeprom_write_byte((uint8_t *)ADR, pos);
|
//eeprom_write_byte((uint8_t *)ADR, pos);
|
||||||
|
eeprom_update_byte((uint8_t *)ADR, pos);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MotorGetSavedPos(uint8_t *ADR) {
|
uint8_t MotorGetSavedPos(uint8_t *ADR) {
|
||||||
return (uint8_t)eeprom_read_byte((uint8_t *)ADR);
|
return (uint8_t)eeprom_read_byte((uint8_t *)POSITION1_ADR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotorMoveTo(uint8_t target) {
|
void MotorMoveTo(uint8_t target) {
|
||||||
|
|
||||||
uint8_t on_delay = ReadSpeed();
|
uint8_t on_delay = ReadSpeed();
|
||||||
uint8_t pos = ReadFader();
|
uint8_t pos = (uint8_t)(ReadFader() >> 2);
|
||||||
uint8_t idx = 0;
|
uint8_t idx = 0;
|
||||||
|
|
||||||
while (diff(target, pos) > 4) {
|
while (diff(target, pos) > 8) {
|
||||||
on_delay = ReadSpeed();
|
on_delay = ReadSpeed();
|
||||||
pos = ReadFader();
|
pos = (uint8_t)(ReadFader() >> 2);
|
||||||
if (target > pos) {
|
if (target > pos) {
|
||||||
MotorMove(1);
|
MotorMove(1);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -269,14 +270,14 @@ static void UpdateButtonOutput(btn_state *b) {
|
||||||
/*If the button pres was a short one.*/
|
/*If the button pres was a short one.*/
|
||||||
else if (!b->is_long_pressed) {
|
else if (!b->is_long_pressed) {
|
||||||
if (b->is_active) {
|
if (b->is_active) {
|
||||||
|
/*Save the current position into position 2 EEPROM*/
|
||||||
|
MotorSetSavePos((uint8_t *)POSITION2_ADR);
|
||||||
|
|
||||||
/*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()) < 4){
|
if(diff(MotorGetSavedPos((uint8_t *)POSITION1_ADR), ReadFader()) > 8){
|
||||||
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION2_ADR));
|
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION1_ADR));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/*Save the current position into position 2 EEPROM*/
|
|
||||||
MotorSetSavePos((uint8_t *)POSITION2_ADR);
|
|
||||||
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION1_ADR));
|
MotorMoveTo(MotorGetSavedPos((uint8_t *)POSITION1_ADR));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue