/* CPU: ATTiny85 @ 16 MHz(PLL) - Bootloader Fuses: - Low : F1 - High: D7 - Ext : FE B.O.D: Disabled Timer1 Clk: 64 MHz */ #define F_CPU 16000000UL //16MHz PLL Clock Speed //Includes #include #include #include #include #include //GPIO Pins #define SHUTDOWN PB0 #define PWM_OUT PB1 #define FEEDBACK_IN PB3 #define POTI_IN PB4 //ADC ADMUX Registers #define POTI_ADC 00000010 #define FEEDBACK_ADC 00000011 //USI-UART #define TX_PORT PORTB #define TX_PIN PB2 #define TX_DDR DDRB #define TX_DDR_PIN DDB2 //Global Variables static uint8_t pwmVal; volatile uint16_t tx_shift_reg = 0; bool disabled = false; char buffer[100]; //Functions void initADC(void); uint16_t readADC(uint8_t channel); void UART_init(); void UART_tx(char character); void UART_tx_str(char* string); int main(void){ //Setup IO Pins DDRB |= (1< feedbackInput) { //Check if Poti Voltage is bigger then Feedback Voltage if(pwmVal != 180) { //Check if not reached max. PWM Value pwmVal = pwmVal + 1; //Increase PWM by 1 OCR1A = pwmVal; //Set new PWM // sprintf(buffer, "Increase PWM: %d\r\n", pwmVal); // UART_tx_str(buffer); } }else if(potiInput < feedbackInput) { //Check if Poti Voltage is smaller then Feedback Voltage if(pwmVal != 0) { //Check if not reached min. PWM Value pwmVal = pwmVal - 1; //Decrease PWM by 1 OCR1A = pwmVal; //Set new PWM // sprintf(buffer, "Decrease PWM: %d\r\n", pwmVal); // UART_tx_str(buffer); } } } } //Transmit Single Character void UART_tx(char character){ uint16_t local_tx_shift_reg = tx_shift_reg; //if sending the previous character is not yet finished, return //transmission is finished when tx_shift_reg == 0 if(local_tx_shift_reg){return;} local_tx_shift_reg = (character<<1) | (1<<9); tx_shift_reg = local_tx_shift_reg; TCCR0B = (1<>= 1; tx_shift_reg = local_tx_shift_reg; if(!local_tx_shift_reg){ TCCR0B = 0; TCNT0 = 0; } } //Init Internal ADC of CPU void initADC(void) { ADMUX = 0x00; ADCSRA = (1<