diff options
| author | Benjamin Kiessling <mittagessen@l.unchti.me> | 2013-12-08 20:58:04 +0000 | 
|---|---|---|
| committer | Christian Franke <nobody@nowhere.ws> | 2013-12-09 22:34:26 +0100 | 
| commit | 1d05cb89fd875334530e086fd0b7dc2a97b0387f (patch) | |
| tree | d72934b699602eb193ba4a19f70e5e9cca8104a0 /ferment.c | |
| parent | 12688a2578ace9776eadfaae0806eaf4ebec48e6 (diff) | |
Miscellaneous test code
Diffstat (limited to 'ferment.c')
| -rw-r--r-- | ferment.c | 74 | 
1 files changed, 66 insertions, 8 deletions
| @@ -1,4 +1,4 @@ -#define F_CPU 1000000UL +//#define F_CPU 7372800UL  #include <stdint.h>  #include <string.h>  #include <avr/io.h> @@ -8,6 +8,10 @@  #include <avr/eeprom.h>  #include <util/delay.h> +#include "serial.h" +#include "stdio.h" +#include "pid.h" +  /* port D   *   *  4 1- (NMOS, inverted)  @@ -22,6 +26,12 @@  #define D_2_MINUS	(1 << 6)  #define D_2_PLUS	(1 << 7) +const int target_temp = 30; +volatile uint16_t adc_res; +volatile uint8_t adc_new; + +struct PID_DATA pid_data; +  /* Turns the H-bridge off, putting the output   * into high impedance mode. */  static void bridge_off(void) @@ -55,15 +65,63 @@ static void bridge_init(void)  	DDRD |= D_1_PLUS | D_1_MINUS | D_2_PLUS | D_2_MINUS;  } -int main() +/* initializes ADC */ +static void adc_init(void) +{ +	adc_new = 0; +	ADMUX = (1 << REFS1) | (1 << REFS0); +	/* select channel x (0 for now) */ +	ADMUX |= 0x0; +	ADCSRA = (1 << ADEN) | (1 << ADIE) | (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); +} + +/* reads ADC */ +static void start_temp_conv(void)  +{ +	ADCSRA |= (1<<ADSC); +} + +/* ADC completion interrupt */ +ISR(ADC_vect)  +{ +	adc_res = ADCW; +	adc_new = 1; +} + +/* ADC results to temperature conversion routine */ +int adc_to_centigrade(uint16_t adc_val) { +	return 0; +} + +/* Initializes TIMER1 */ +static void timer_init(void)  +{ +	TCCR1B = (1 << WGM12) | (1 << CS11); +	OCR1A = 1000; +	TIMSK|=(1<<OCIE1A); +} + +ISR(TIMER1_COMPA_vect) +{ +	serial_send("*\n", 2, 1); +	start_temp_conv(); +} + +int main(void)  { +	char params[12]; + +	serial_init(); +	adc_init(); +	timer_init();  	bridge_init(); -	/* simple demo, just flips polarity every now and then */ + +	sei(); +  	while (1) { -		bridge_on_a(); -		_delay_ms(200); -		bridge_on_b(); -		_delay_ms(200); +		sprintf(params, "%u\n", adc_res); +		serial_send(params, strlen(params), 1); +		//bridge_on_a(); +		_delay_ms(1000);  	}  } - | 
