Compare commits

..

No commits in common. "b96945a2a5919f9ac188a5c0838fd265c5e64643" and "a88fae412e4b8528450d34647041b0c55112269c" have entirely different histories.

4 changed files with 10 additions and 44 deletions

View file

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20)
# Use the fancy version substitution
project(main
VERSION 0.2.0
VERSION 0.1.2
DESCRIPTION "template for cmake + cpputest"
LANGUAGES C CXX
)

View file

@ -32,10 +32,6 @@ The position will now be saved into the EEPROM memory.
To automatically move the fader into the saved location preform a quick
press of the button.
The speed can be adjusted by changing the input value of the speed pot. The
speed adjustment affects the on/off ratio of the motor and has a programmed
minimum speed value in the function to prevent endless looping.
## Building Project(Windows)

View file

@ -42,7 +42,6 @@
#define PWM_PIN1 PB0 // Pin 5 - Motor PWM 1
#define PWM_PIN2 PB1 // Pin 6 - Motor PWM 2
#define ADC_PIN PB3 // Pin 2 - Fader position reading
#define SPEED_PIN PB2 // Pin 7/ADC1
#define BUTTON_PIN PB4 // Pin 3 - Button input
@ -98,15 +97,9 @@ void InitProg(void);
/**
* @brief Reads the ADC pin from the fader.
* @brief Reads the ADC pin
*/
uint16_t ReadFader(void);
/**
* @brief Reads the ADC value from the Speed pot.
*/
uint8_t ReadSpeed(void);
uint16_t ReadADC(void);
/**

View file

@ -83,28 +83,7 @@ void InitProg(void) {
InitTimer0();
}
uint8_t ReadSpeed(void) {
// Initialize ADC
ADMUX = (0 << MUX1) | (1 << MUX0); // Select ADC1 (PB2)
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
ADCSRA |= (1 << ADSC); // Start conversion
while (ADCSRA & (1 << ADSC)) {
} // Wait for conversion to finish
uint8_t val = (uint8_t)(ADC >> 2);
//We want to set a minimum acceptable speed.
if(val < 32){
val = 32;
}
return val;
}
//change to ReadFader(void)
uint16_t ReadFader(void) {
uint16_t ReadADC(void) {
// Initialize ADC
ADMUX = (1 << MUX1) | (1 << MUX0); // Select ADC3 (PB3)
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0); // Enable ADC, prescaler 8
@ -129,7 +108,7 @@ static inline uint8_t diff(uint8_t a, uint8_t b) {
}
void MotorSetSavePos() {
uint8_t pos = (uint8_t)(ReadFader() >> 2);
uint8_t pos = (uint8_t)(ReadADC() >> 2);
eeprom_write_byte((uint8_t *)ROM_SS1_ADR, pos);
return;
}
@ -140,12 +119,10 @@ uint8_t MotorGetSavedPos(void) {
void MotorMoveTo(uint8_t target) {
uint8_t on_delay = ReadFader();
uint8_t off_delay = 255 - on_delay;
uint8_t pos = (uint8_t)(ReadFader() >> 2);
uint8_t pos = (uint8_t)(ReadADC() >> 2);
while (diff(target, pos) > 8) {
pos = (uint8_t)(ReadFader() >> 2);
pos = (uint8_t)(ReadADC() >> 2);
if (target > pos) {
MotorMove(1);
} else {
@ -153,9 +130,9 @@ void MotorMoveTo(uint8_t target) {
}
// The delay ratio controlls the PWM waveforms.
_delay_ms((double) on_delay);
MotorCoast();
_delay_ms((double) off_delay);
//_delay_ms(5);
// MotorCoast();
// _delay_ms(5);
}
return;