diff --git a/lambda/.cproject b/lambda/.cproject index d38c159..64b02fc 100644 --- a/lambda/.cproject +++ b/lambda/.cproject @@ -49,7 +49,7 @@ - + diff --git a/lambda/.settings/de.innot.avreclipse.core.prefs b/lambda/.settings/de.innot.avreclipse.core.prefs index bc2bfbd..77eaca7 100644 --- a/lambda/.settings/de.innot.avreclipse.core.prefs +++ b/lambda/.settings/de.innot.avreclipse.core.prefs @@ -1,4 +1,4 @@ -avrtarget/ClockFrequency=8000000 +avrtarget/ClockFrequency=1000000 avrtarget/ExtRAMSize=0 avrtarget/ExtendedRAM=false avrtarget/MCUType=atmega328p @@ -15,7 +15,7 @@ avrtarget/avrdude/NoVerify=false avrtarget/avrdude/NoWrite=false avrtarget/avrdude/OtherOptions= -avrtarget/avrdude/ProgrammerID=programmerconfig.2 +avrtarget/avrdude/ProgrammerID=programmerconfig.1 avrtarget/avrdude/UseCounter=false avrtarget/avrdude/WriteEEPROM=false avrtarget/avrdude/WriteFlash=true diff --git a/lambda/DEBUG b/lambda/DEBUG index 7ba5183..618224c 100644 --- a/lambda/DEBUG +++ b/lambda/DEBUG @@ -1,2 +1,8 @@ +Compile: avr-gcc -Wall -g2 -gstabs -O0 -std=gnu99 -funsigned-char -funsigned-bitfields -mmcu=atmega328p -DF_CPU=1000000UL +Create hex: avr-objcopy -R .eeprom -O ihex lambda.elf lambda.hex Upload hex: avrdude -pm328p -cjtag2isp -B10 -Uflash:w:lambda.hex:a -Start AVaRICE: avarice -2 -w -B10 -j usb :4242 \ No newline at end of file +Start AVaRICE: avarice -2 -w -B10 -j usb :4242 +Start avr-gdb: avr-gdb lambda.elf +Connect to remote: target remote localhost:4242 +Set breakpoint: break lambda.c:74 +Continue: continue \ No newline at end of file diff --git a/lambda/airgate.c b/lambda/airgate.c index bdcacb6..2672b67 100644 --- a/lambda/airgate.c +++ b/lambda/airgate.c @@ -4,12 +4,9 @@ * Created on: 19.02.2016 * Author: dode@luniks.net * - * Simple (maybe naive) stepper motor control with a linear acceleration - * profile using the DRV8825. An absolute position from 0 to 255 can be set - * which relates to the actual number of degrees by the SCALE constant and the - * stepping mode. If a new position is set while the motor is busy, it is - * decelerated before it starts to move to the new position. - * The idea is to be able to set the airgate position from 0 - 100%. + * Simple stepper motor control with a linear acceleration profile using the + * DRV8825. An absolute position from 0 to 255 can be set where 200 units + * correspond to 360° rotation. */ #include @@ -22,22 +19,21 @@ #include "pins.h" /* Direction */ -volatile static int8_t dir = 0; +static volatile int8_t dir = 0; /* Current position */ -volatile static uint16_t pos = 0; +static volatile uint16_t pos = 0; /* Steps remaining */ -volatile static uint16_t steps = 0; +static volatile uint16_t steps = 0; /* Steps done */ -volatile static uint16_t done = 0; +static volatile uint16_t done = 0; /* Acceleration profile ramp */ -volatile static uint16_t ramp = 0; +static volatile uint16_t ramp = 0; /* Speed */ -volatile static uint8_t speed = MIN_SPEED; +static volatile uint8_t speed = MIN_SPEED; /** - * Sets increased current for higher torque, - * sets the direction and initial speed and - * starts the motor by starting the timer. + * Sets increased current for higher torque,sets the direction and initial + * speed and starts the motor by starting the timer. */ static void start(void) { // set increased current for higher torque diff --git a/lambda/rules.c b/lambda/rules.c index 97e4d78..d301da1 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -258,8 +258,7 @@ tempIMax = MAX(tempIMax, meas.tempI); // rules applied at each measurement - size_t heaterRulesSize = sizeof(heaterRules) / sizeof(heaterRules[0]); - for (size_t i = 0; i < heaterRulesSize; i++) { + for (size_t i = 0; i < ARRAY_LENGTH(heaterRules); i++) { heaterRules[i].cond(&(heaterRules[i].fired), meas); } @@ -268,8 +267,7 @@ if (measCount == MEAS_INT && ! isAirgateBusy()) { measCount = 0; - size_t rulesSize = sizeof(rules) / sizeof(rules[0]); - for (size_t i = 0; i < rulesSize; i++) { + for (size_t i = 0; i < ARRAY_LENGTH(rules); i++) { rules[i].cond(&(rules[i].fired), meas); } @@ -304,15 +302,13 @@ setAirgate(AIRGATE_OPEN); } - size_t rulesSize = sizeof(rules) / sizeof(rules[0]); - for (size_t i = 0; i < rulesSize; i++) { + for (size_t i = 0; i < ARRAY_LENGTH(rules); i++) { rules[i].fired = false; } // default for warmStart should be true rules[6].fired = true; - size_t heaterRulesSize = sizeof(heaterRules) / sizeof(heaterRules[0]); - for (size_t i = 0; i < heaterRulesSize; i++) { + for (size_t i = 0; i < ARRAY_LENGTH(heaterRules); i++) { heaterRules[i].fired = false; } } diff --git a/lambda/sensors.c b/lambda/sensors.c index 501007a..b6d47ee 100644 --- a/lambda/sensors.c +++ b/lambda/sensors.c @@ -131,15 +131,13 @@ } int16_t toTempO(uint16_t const mV) { - size_t size = sizeof(tempOTable) / sizeof(tempOTable[0]); - int16_t temp = lookupLinInter(mV, tempOTable, size); + int16_t temp = lookupLinInter(mV, tempOTable, ARRAY_LENGTH(tempOTable)); return temp; } uint16_t toLambda(uint16_t const mV) { - size_t size = sizeof(lambdaTable) / sizeof(lambdaTable[0]); - int16_t lambda = lookupLinInter(mV, lambdaTable, size); + int16_t lambda = lookupLinInter(mV, lambdaTable, ARRAY_LENGTH(lambdaTable)); return lambda; } @@ -174,8 +172,7 @@ } int32_t linADC(uint16_t const mV) { - size_t size = sizeof(linADCTable) / sizeof(linADCTable[0]); - int16_t dev = lookupLinInter(mV, linADCTable, size); + int16_t dev = lookupLinInter(mV, linADCTable, ARRAY_LENGTH(linADCTable)); return (int32_t)mV == 0 ? 0 : mV - dev; }