/* * fsm-main.c: main() function for SpaghettiMonster. * * Copyright (C) 2017 Selene ToyKeeper * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef FSM_MAIN_C #define FSM_MAIN_C #include "fsm-main.h" #if PWM_CHANNELS == 4 #ifdef AVRXMEGA3 // ATTINY816, 817, etc #error 4-channel PWM not currently set up for the AVR 1-Series #endif // 4th PWM channel requires manually turning the pin on/off via interrupt :( ISR(TIMER1_OVF_vect) { //bitClear(PORTB, 3); PORTB &= 0b11110111; //PORTB |= 0b00001000; } ISR(TIMER1_COMPA_vect) { //if (!bitRead(TIFR,TOV1)) bitSet(PORTB, 3); if (! (TIFR & (1<= 1 DDRB |= (1 << PWM1_PIN); TCCR0B = 0x01; // pre-scaler for timer (1 => 1, 2 => 8, 3 => 64...) TCCR0A = PHASE; #if (PWM1_PIN == PB4) // Second PWM counter is ... weird TCCR1 = _BV (CS10); GTCCR = _BV (COM1B1) | _BV (PWM1B); OCR1C = 255; // Set ceiling value to maximum #endif #endif // tint ramping needs second channel enabled, // despite PWM_CHANNELS being only 1 #if (PWM_CHANNELS >= 2) || defined(USE_TINT_RAMPING) DDRB |= (1 << PWM2_PIN); #if (PWM2_PIN == PB4) // Second PWM counter is ... weird TCCR1 = _BV (CS10); GTCCR = _BV (COM1B1) | _BV (PWM1B); OCR1C = 255; // Set ceiling value to maximum #endif #endif #if PWM_CHANNELS >= 3 DDRB |= (1 << PWM3_PIN); #if (PWM3_PIN == PB4) // Second PWM counter is ... weird TCCR1 = _BV (CS10); GTCCR = _BV (COM1B1) | _BV (PWM1B); OCR1C = 255; // Set ceiling value to maximum #endif #endif #if PWM_CHANNELS >= 4 // 4th PWM channel is ... not actually supported in hardware :( DDRB |= (1 << PWM4_PIN); //OCR1C = 255; // Set ceiling value to maximum TCCR1 = 1<= 1 PWM1_LVL = 0; #endif #if PWM_CHANNELS >= 2 PWM2_LVL = 0; #endif #if PWM_CHANNELS >= 3 PWM3_LVL = 0; #endif #if PWM_CHANNELS >= 4 PWM4_LVL = 255; // inverted :( #endif #endif standby_mode(); } // catch up on interrupts handle_deferred_interrupts(); // turn delays back on, if they were off nice_delay_interrupt = 0; // give the recipe some time slices loop(); } } void handle_deferred_interrupts() { /* if (irq_pcint) { // button pressed or released // nothing to do here // (PCINT only matters during standby) } */ if (irq_adc) { // ADC done measuring adc_deferred(); // irq_adc = 0; // takes care of itself } if (irq_wdt) { // the clock ticked WDT_inner(); // irq_wdt = 0; // takes care of itself } } #endif