diff --git a/lambda/Makefile b/lambda/Makefile index 5525397..8da700c 100644 --- a/lambda/Makefile +++ b/lambda/Makefile @@ -3,7 +3,7 @@ MCU = atmega328p # Currently supported are 1 MHz and 8 MHz -F_CPU = 8000000 +F_CPU = 1000000 # Also try BAUD = 19200 or 38400 if you're feeling lucky. BAUD = 9600 diff --git a/lambda/airgate.c b/lambda/airgate.c index 9d7cab6..e60c5ce 100644 --- a/lambda/airgate.c +++ b/lambda/airgate.c @@ -21,8 +21,7 @@ #include "airgate.h" #include "integers.h" #include "interrupts.h" - -// TODO pins +#include "pins.h" /* Direction */ volatile static int8_t dir = 0; @@ -44,17 +43,17 @@ * starts the motor by starting the timer. */ static void start(void) { - if (bit_is_clear(PORTC, PC5)) { + if (bit_is_clear(PORT, PIN_SLEEP)) { // wake up driver - PORTC |= (1 << PC5); + PORT |= (1 << PIN_SLEEP); // wakeup time _delay_ms(2); } // set dir if (dir == 1) { - PORTB &= ~(1 << PB6); + PORT &= ~(1 << PIN_DIR); } else { - PORTB |= (1 << PB6); + PORT |= (1 << PIN_DIR); } // setup time _delay_us(1); @@ -79,19 +78,20 @@ * the motor. */ static void set(void) { - stop(); int16_t diff = (((int16_t)target) << SCALE) - pos; if (diff != 0) { dir = MAX(-1, MIN(diff, 1)); steps = abs(diff); ramp = MIN(abs(MAX_SPEED - MIN_SPEED), steps >> 1); start(); + } else { + setSleepMode(); } } void makeSteps(void) { if (steps > 0) { - PORTB ^= (1 << PB7); + PORT ^= (1 << PIN_STEP); done++; steps--; if (done < ramp && speed < MAX_SPEED) { @@ -104,6 +104,7 @@ // linearize an unfavourably increasing acceleration curve OCR2A = (MIN_SPEED * MAX_SPEED) / speed; } else { + stop(); pos += (done * dir); done = 0; // move to new target position if necessary @@ -135,5 +136,5 @@ } void setSleepMode(void) { - PORTC &= ~(1 << PC5); + PORT &= ~(1 << PIN_SLEEP); } diff --git a/lambda/display.c b/lambda/display.c index c782d54..08eb461 100644 --- a/lambda/display.c +++ b/lambda/display.c @@ -22,6 +22,7 @@ #include "alert.h" #include "messages.h" #include "rules.h" +#include "airgate.h" DisplayPos position = displayPosCurrent; bool updatePending = false; @@ -79,6 +80,15 @@ } /** + * Displays the airgate position in %. + */ +static void displayAirgate(uint8_t const airgate) { + char line1[17]; + snprintf(line1, sizeof(line1), "%d%%", airgate); + setText(MSG_AIRGATE, line1); +} + +/** * Formats and displays the time since last start/reset. */ static void displayTime(void) { @@ -126,10 +136,12 @@ if (position == displayPosMax) { displayMeas(measMax, " ^"); - } else if (position == displayPosLastText) { - setText(lastLine0, lastLine1); + } else if (position == displayPosAirgate) { + displayAirgate(getAirgate()); } else if (position == displayPosHeater) { displayCurrent(measLatest.current); + } else if (position == displayPosLastText) { + setText(lastLine0, lastLine1); } else if (position == displayPosTime) { displayTime(); } else { diff --git a/lambda/display.h b/lambda/display.h index 4a51fb0..0b46583 100644 --- a/lambda/display.h +++ b/lambda/display.h @@ -19,9 +19,10 @@ typedef enum { displayPosCurrent = 0, displayPosMax = 1, - displayPosHeater = 2, - displayPosLastText = 3, - displayPosTime = 4 + displayPosAirgate = 2, + displayPosHeater = 3, + displayPosLastText = 4, + displayPosTime = 5 } DisplayPos; uint8_t getPosition(void); diff --git a/lambda/interrupts.c b/lambda/interrupts.c index ae5c439..ebdf46a 100644 --- a/lambda/interrupts.c +++ b/lambda/interrupts.c @@ -86,11 +86,9 @@ DDR |= (1 << PIN_HEATER); // enable dir and step pin for stepper motor driver - // TODO pins - DDR |= (1 << PB6); - DDR |= (1 << PB7); - // DDR |= (1 << PB3); // (OC2A) - DDRC |= (1 << PC5); + DDR |= (1 << PIN_SLEEP); + DDR |= (1 << PIN_STEP); + DDR |= (1 << PIN_DIR); } void setupSleepMode(void) { diff --git a/lambda/messages.h b/lambda/messages.h index 20f1e27..33011af 100644 --- a/lambda/messages.h +++ b/lambda/messages.h @@ -23,6 +23,9 @@ #define MSG_IDEAL "Ideal" #define MSG_RICH "Rich!" + /* display.c */ + #define MSG_AIRGATE "Air gate" + /* rules.c */ #define MSG_AIRGATE_50_0 "Air gate 50%" #define MSG_AIRGATE_25_0 "Air gate 25%" @@ -50,6 +53,9 @@ #define MSG_IDEAL "Ideal" #define MSG_RICH "Fett!" + /* display.c */ + #define MSG_AIRGATE "Luftschieber" + /* rules.c */ #define MSG_AIRGATE_50_0 "Luftschieber 50%" #define MSG_AIRGATE_25_0 "Luftschieber 25%" diff --git a/lambda/pins.h b/lambda/pins.h index 244c81d..4374476 100644 --- a/lambda/pins.h +++ b/lambda/pins.h @@ -35,6 +35,12 @@ #define PIN_BEEPER_TOGGLE COM1A0 /** Pin for the oxygen sensor heater */ #define PIN_HEATER PB2 +/** Pin for the stepper motor driver sleep mode **/ +#define PIN_SLEEP PB3 +/** Pin for the stepper motor driver step input */ +#define PIN_STEP PB4 +/** Pin for the stepper motor driver direction input */ +#define PIN_DIR PB5 /* Pins for the LCD */ #define LCD_PORT PORTD