Hey guys, working on a project here and I need a little help. I've never played with the internal timers before on the tiny85. Anyways, I'm trying to generate a 58khz square wave on pin PB4 with a 50% duty cycle. After some digging I found some code that seems to be able to do this on pin PB1 using timer 0.
#elif defined(IR_USE_TIMER_TINY0)
#define TIMER_RESET
#define TIMER_ENABLE_PWM (TCCR0A |= _BV(COM0B1))
#define TIMER_DISABLE_PWM (TCCR0A &= ~(_BV(COM0B1)))
#define TIMER_CONFIG_KHZ(val) ({ \
const uint8_t pwmval = SYSCLOCK / 2000 / (val); \
TCCR0A = _BV(WGM00); \
TCCR0B = _BV(WGM02) | _BV(CS00); \
OCR0A = pwmval; \
OCR0B = pwmval / 3; \
})
#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000)
#if (TIMER_COUNT_TOP < 256)
#define TIMER_CONFIG_NORMAL() ({ \
TCCR0A = _BV(WGM01); \
TCCR0B = _BV(CS00); \
OCR0A = TIMER_COUNT_TOP; \
TCNT0 = 0; \
})
#else
#define TIMER_CONFIG_NORMAL() ({ \
TCCR0A = _BV(WGM01); \
TCCR0B = _BV(CS01); \
OCR0A = TIMER_COUNT_TOP / 8; \
TCNT0 = 0; \
})
#endif
Here, I would be using TIMER_CONFIG_KHZ, and the two enable and disable functions.
I'm pretty sure in order to port this to pin pb4 I would have to use timer1 which may or may not allow the use of delay() in the regular IDE? I'm also aware that pb4 is controlled by OC1B on the tiny85. But beyond this I'm not really sure what is happening or what needs to happen. Any guidance is appreciated. Thanks!