#include #include #include #include #include #include #include "utils.h" #include "main.h" #include "uart.h" #define BUFSIZE 40 #define CURRENT_MAX 30000 // 30 Ampere is max #define POWER_MAX 300 #define SERVO_NEUTRAL 2312 #define SERVO_MIN 2312 #define SERVO_MAX 2312 volatile uint16_t syscounter = 0; // values send over uart from powerboard uint16_t voltage = 0; int16_t current_in = 0; int16_t current_out = 0; uint8_t dumpsw = 0; uint8_t loadsw = 0; uint8_t gensw = 0; uint16_t display = 0; uint16_t power_gen = 0; uint16_t power_load = 0; unsigned char data_count = 0; unsigned char data_in[BUFSIZE]; char command_in[BUFSIZE]; static void timer_init(void) { // clock is 8MHz TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10); // CTC Mode for Timer 1 (16Bit) with prescale of 64 OCR1A = 2312; // Neutralposition ((2500-2312)*0.008ms)=1,5ms) TIMSK = _BV(OCIE1A); TCCR1A = (1< 0;i--) { set_servo(i*10); wait(5); } } int main(void) { ports_init(); timer_init(); uart_init(UART_BAUD_SELECT(19200,F_CPU)); memset(data_in, 0, BUFSIZE); demo_display(); while(1) { work_uart(); if(syscounter >= 10) { uart_putc('a'); // send a to receive values set_servo(power_gen); syscounter = 0; } } return(0); } SIGNAL(TIMER1_COMPA_vect) { syscounter++; OCR1A = 2500-OCR1A; // Das Servosignal wird aus der Differenz von // Periodenlänge (2500*0,008ms=20ms) und letztem // Vergleichswert (OCR1A) gebildet }