123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "io_atmega2560.h"
- enum class States : uint8_t {
- ZERO = 0,
- RISE = 1,
- ONE = 2,
- FALL = 3
- };
- static States stateTable[4*2] = {
- States::ZERO, States::RISE,
- States::FALL, States::ONE,
- States::FALL, States::ONE,
- States::ZERO, States::RISE
- };
- static States state = States::ZERO;
- static uint8_t outer = 0;
- static uint8_t inner = 0;
- static uint8_t pwm = 0;
- extern unsigned char soft_pwm_bed;
- #if 1
- static const uint8_t innerMax = 16;
- static const uint8_t innerShift = 4;
- #else
- static const uint8_t innerMax = 8;
- static const uint8_t innerShift = 5;
- #endif
- ISR(TIMER0_OVF_vect)
- {
- if( inner ){
- switch(state){
- case States::ZERO:
- OCR0B = 255;
-
-
- break;
- case States::RISE:
- OCR0B = (innerMax - inner) << innerShift;
- TCCR0A &= ~(1 << COM0B0);
- break;
- case States::ONE:
- OCR0B = 255;
-
- TCCR0A &= ~(1 << COM0B0);
- break;
- case States::FALL:
- OCR0B = (innerMax - inner) << innerShift;
-
- TCCR0A |= (1 << COM0B0);
- break;
- }
- --inner;
- } else {
- if( ! outer ){
-
- pwm = soft_pwm_bed << 1;
- }
- if( pwm > outer || pwm >= 254 ){
-
- state = stateTable[ uint8_t(state) * 2 + 1 ];
- } else {
-
- state = stateTable[ uint8_t(state) * 2 + 0 ];
- }
- ++outer;
- inner = innerMax;
- }
- }
|