Permalink
Browse files

merge intercom-protocol into master

  • Loading branch information...
2 parents eecf3af + bfae6ff commit 8188ff3593368fb012dc9777d95a785925723f4c @triffid committed Feb 21, 2011
Showing with 803 additions and 574 deletions.
  1. +10 −0 arduino_168_328p.h
  2. +3 −0 clock.c
  3. +29 −60 extruder/analog.c
  4. +10 −0 extruder/arduino_168_328p.h
  5. +22 −84 extruder/config.h.dist
  6. +5 −11 extruder/debug.h
  7. +18 −9 extruder/extruder.c
  8. +143 −84 extruder/heater.c
  9. +20 −6 extruder/heater.h
  10. +160 −120 extruder/intercom.c
  11. +37 −4 extruder/intercom.h
  12. +113 −57 extruder/temp.c
  13. +13 −5 extruder/temp.h
  14. +6 −6 home.c
  15. +159 −119 intercom.c
  16. +37 −4 intercom.h
  17. +9 −0 mendel.c
  18. +9 −5 temp.c
View
@@ -126,6 +126,16 @@ pins
#define AIO5_WPORT PORTC
#define AIO5_DDR DDRC
+#define AIO6_PIN PINC6
+#define AIO6_RPORT PINC
+#define AIO6_WPORT PORTC
+#define AIO6_DDR DDRC
+
+#define AIO7_PIN PINC7
+#define AIO7_RPORT PINC
+#define AIO7_WPORT PORTC
+#define AIO7_DDR DDRC
+
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
View
@@ -31,6 +31,9 @@ void clock_250ms() {
/* if (temp_get_target())
temp_print();*/
}
+ #ifdef TEMP_INTERCOM
+ start_send();
+ #endif
}
void clock_10ms() {
View
@@ -1,48 +1,21 @@
#include "analog.h"
+#include "temp.h"
#include <avr/interrupt.h>
-#ifndef ANALOG_MASK
- #warning ANALOG_MASK not defined - analog subsystem disabled
- #define ANALOG_MASK 0
-#endif
+/* OR-combined mask of all channels */
+#undef DEFINE_TEMP_SENSOR
+#define DEFINE_TEMP_SENSOR(name, type, pin) | (((type == TT_THERMISTOR) || (type == TT_AD595)) ? 1 << (pin) : 0)
+static const uint8_t analog_mask = 0
+#include "config.h"
+;
+#undef DEFINE_TEMP_SENSOR
-uint8_t adc_running_mask, adc_counter;
-
-#if ANALOG_MASK & 1
- #define ANALOG_START 0
- #define ANALOG_START_MASK 1
-#elif ANALOG_MASK & 2
- #define ANALOG_START 1
- #define ANALOG_START_MASK 2
-#elif ANALOG_MASK & 4
- #define ANALOG_START 2
- #define ANALOG_START_MASK 4
-#elif ANALOG_MASK & 8
- #define ANALOG_START 3
- #define ANALOG_START_MASK 8
-#elif ANALOG_MASK & 16
- #define ANALOG_START 4
- #define ANALOG_START_MASK 16
-#elif ANALOG_MASK & 32
- #define ANALOG_START 5
- #define ANALOG_START_MASK 32
-#elif ANALOG_MASK & 64
- #define ANALOG_START 6
- #define ANALOG_START_MASK 64
-#elif ANALOG_MASK & 128
- #define ANALOG_START 7
- #define ANALOG_START_MASK 128
-#else
- // ANALOG_MASK == 0
- #define ANALOG_START 0
- #define ANALOG_START_MASK 1
-#endif
-
-volatile uint16_t adc_result[8] __attribute__ ((__section__ (".bss")));
+static uint8_t adc_counter;
+static volatile uint16_t adc_result[8] __attribute__ ((__section__ (".bss")));
void analog_init() {
- #if ANALOG_MASK > 0
+ if (analog_mask > 0) {
#ifdef PRR
PRR &= ~MASK(PRADC);
#elif defined PRR0
@@ -55,36 +28,32 @@ void analog_init() {
ADCSRA = MASK(ADEN) | MASK(ADPS2) | MASK(ADPS1) | MASK(ADPS0);
adc_counter = 0;
- adc_running_mask = 1;
-
- AIO0_DDR &= ANALOG_MASK;
- DIDR0 = ANALOG_MASK & 0x3F;
+ AIO0_DDR &= ~analog_mask;
+ DIDR0 = analog_mask & 0x3F;
// now we start the first conversion and leave the rest to the interrupt
ADCSRA |= MASK(ADIE) | MASK(ADSC);
- #endif /* ANALOG_MASK > 0 */
+ } /* analog_mask > 0 */
}
ISR(ADC_vect, ISR_NOBLOCK) {
// emulate free-running mode but be more deterministic about exactly which result we have, since this project has long-running interrupts
- adc_result[ADMUX & 0x0F] = ADC;
- // find next channel
- do {
- adc_counter++;
- adc_running_mask <<= 1;
- if (adc_counter == 8) {
- adc_counter = ANALOG_START;
- adc_running_mask = ANALOG_START_MASK;
- }
- } while ((adc_running_mask & ANALOG_MASK) == 0);
-
- // start next conversion
- ADMUX = (adc_counter) | REFERENCE;
- ADCSRA |= MASK(ADSC);
+ if (analog_mask > 0) {
+ adc_result[ADMUX & 0x0F] = ADC;
+ // find next channel
+ do {
+ adc_counter++;
+ adc_counter &= 0x07;
+ } while ((analog_mask & (1 << adc_counter)) == 0);
+
+ // start next conversion
+ ADMUX = (adc_counter) | REFERENCE;
+ ADCSRA |= MASK(ADSC);
+ }
}
uint16_t analog_read(uint8_t channel) {
- #if ANALOG_MASK > 0
+ if (analog_mask > 0) {
uint16_t r;
uint8_t sreg;
@@ -100,7 +69,7 @@ uint16_t analog_read(uint8_t channel) {
SREG = sreg;
return r;
- #else
+ } else {
return 0;
- #endif
+ }
}
@@ -126,6 +126,16 @@ pins
#define AIO5_WPORT PORTC
#define AIO5_DDR DDRC
+#define AIO6_PIN PINC6
+#define AIO6_RPORT PINC
+#define AIO6_WPORT PORTC
+#define AIO6_DDR DDRC
+
+#define AIO7_PIN PINC7
+#define AIO7_RPORT PINC
+#define AIO7_WPORT PORTC
+#define AIO7_DDR DDRC
+
#define PB0_PIN PINB0
#define PB0_RPORT PINB
#define PB0_WPORT PORTB
View
@@ -3,6 +3,9 @@
#include "arduino.h"
+// controller index- bus is multidrop after all
+#define THIS_CONTROLLER_NUM 0
+
//RS485 Interface pins
#define RX_ENABLE_PIN DIO4
#define TX_ENABLE_PIN AIO2
@@ -30,100 +33,47 @@
#define TEMP_PIN AIO3
#define TEMP_PIN_CHANNEL 3
+//Read analog voltage from thermistor
+#define TEMP_BED_PIN AIO6
+#define TEMP_BED_PIN_CHANNEL 6
+
+
#define REFERENCE REFERENCE_AVCC
-#define ANALOG_MASK (MASK(TRIM_POT_CHANNEL) | MASK(TEMP_PIN_CHANNEL))
+#define ANALOG_MASK (MASK(TRIM_POT_CHANNEL) | MASK(TEMP_PIN_CHANNEL) | MASK(TEMP_BED_PIN_CHANNEL))
#define TEMP_THERMISTOR
+#define HEATER_PIN DIO11
+#define BED_PIN AIO1
+#define FAN_PIN DIO12
+
// extruder settings
#define TEMP_HYSTERESIS 20
#define TEMP_RESIDENCY_TIME 60
-#define NUM_TEMP_SENSORS 1
-#ifdef TEMP_C
-/***************************************************************************\
-* *
-* Fill in the following struct according to your hardware *
-* *
-* If your temperature sensor has no associated heater, enter '255' as the *
-* heater index. *
-* *
-* for GEN3 set temp_type to TT_INTERCOM, temp_pin to 0 and heater index to *
-* 255 *
-* *
-\***************************************************************************/
-
-struct {
- uint8_t temp_type;
- uint8_t temp_pin;
-
- uint8_t heater_index;
-} temp_sensors[NUM_TEMP_SENSORS] =
-{
- {
- TT_THERMISTOR,
- PINC3,
- 0
- }
-};
+#ifdef DEFINE_TEMP_SENSOR
+DEFINE_TEMP_SENSOR(extruder, TT_THERMISTOR, TEMP_PIN_CHANNEL)
+DEFINE_TEMP_SENSOR(bed, TT_THERMISTOR, TEMP_BED_PIN_CHANNEL)
+#endif
+
+#ifdef DEFINE_HEATER
+DEFINE_HEATER(extruder, PORTD, HEATER_PIN, OCR0A)
+DEFINE_HEATER(bed, PORTD, BED_PIN, OCR0B)
#endif
// list of PWM-able pins and corresponding timers
// timer1 is used for step timing so don't use OC1A/OC1B (DIO9/DIO10)
// OC0A DIO6
// OC0B DIO5
// OC1A DIO9
-// OC1B DIO10
+// OC1B DIO10
// OC2A DIO11
// OC2B DIO3
#define TH_COUNT 8
#define PID_SCALE 1024L
-#define NUM_HEATERS 2
-#ifdef HEATER_C
-/***************************************************************************\
-* *
-* Fill in the following struct according to your hardware *
-* *
-* For the atmega168/328, timer/pin mappings are as follows *
-* *
-* OCR0A - PD6 *
-* OCR0B - PD5 *
-* OCR2A - PB3 *
-* OCR2B - PD3 *
-* *
-\***************************************************************************/
-struct {
- volatile uint8_t *heater_port;
- uint8_t heater_pin;
- volatile uint8_t *heater_pwm;
-} heaters[NUM_HEATERS] =
-{
- {
- &PORTD,
- PIND6,
- &OCR0A
- },
- {
- &PORTB,
- PINB4,
- 0
- }
-};
-#endif
-
-// #define HEATER_PIN DIO11
-// #define HEATER_PWM OCR2A
-//
-// #define BED_PIN DIO12
-
-/*
- Intercom
-*/
-#define enable_transmit() do { WRITE(TX_ENABLE_PIN,1); WRITE(RX_ENABLE_PIN,0); } while(0)
-#define disable_transmit() do { WRITE(TX_ENABLE_PIN,0); WRITE(RX_ENABLE_PIN,0); } while(0)
/*
Motors
@@ -132,16 +82,4 @@ struct {
#define enable_motors() do { TCCR0A |= MASK(COM0A1) | MASK(COM0B1); } while (0)
#define disable_motors() do { TCCR0A &= ~MASK(COM0A1) & ~MASK(COM0B1); } while (0)
-/*
- Heater
-*/
-
-// #ifdef HEATER_PWM
-// #define enable_heater() do { TCCR2A |= MASK(COM2A1); } while (0)
-// #define disable_heater() do { TCCR2A &= ~MASK(COM2A1); } while (0)
-// #else
-// #define enable_heater() WRITE(HEATER_PIN, 1)
-// #define disable_heater() WRITE(HEATER_PIN, 0)
-// #endif
-
#endif /* _CONFIG_H */
View
@@ -3,18 +3,12 @@
#include <stdint.h>
-#ifdef DEBUG
- #define DEBUG_PID 1
- #define DEBUG_DDA 2
- #define DEBUG_POSITION 4
-#else
- // by setting these to zero, the compiler should optimise the relevant code out
- #define DEBUG_PID 0
- #define DEBUG_DDA 0
- #define DEBUG_POSITION 0
-#endif
+// by setting these to zero, the compiler should optimise the relevant code out
+#define DEBUG_PID 0
+#define DEBUG_DDA 0
+#define DEBUG_POSITION 0
-#define DEBUG_ECHO 128
+#define DEBUG_ECHO 0
extern volatile uint8_t debug_flags;
Oops, something went wrong.

0 comments on commit 8188ff3

Please sign in to comment.