/*
* 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
// 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;
#endif
#if PWM_CHANNELS >= 2
DDRB |= (1 << PWM2_PIN);
#endif
#if PWM_CHANNELS >= 3
// Second PWM counter is ... weird
DDRB |= (1 << PWM3_PIN);
TCCR1 = _BV (CS10);
GTCCR = _BV (COM1B1) | _BV (PWM1B);
OCR1C = 255; // Set ceiling value to maximum
#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
go_to_standby = 0;
standby_mode();
}
// give the recipe some time slices
loop();
}
}
#endif