|
|
|
@ -18,9 +18,11 @@ void timer_init_tiny26(void)
|
|
|
|
OCR1C = 0xff;/* unused */
|
|
|
|
OCR1C = 0xff;/* unused */
|
|
|
|
|
|
|
|
|
|
|
|
/* output pin: OC1A = PB1 = 1 or OC1B = PB3 = 2 */
|
|
|
|
/* output pin: OC1A = PB1 = 1 or OC1B = PB3 = 2 */
|
|
|
|
OCR1A = 0;
|
|
|
|
OCR1B = 0;
|
|
|
|
|
|
|
|
cnt_to_next = 1;/* overflows to next sample */
|
|
|
|
|
|
|
|
|
|
|
|
TCCR1A = (1 << COM1B1) | (1 << PWM1B);/* pwm enable, not inverted */
|
|
|
|
TCCR1A = (1 << COM1B1) | (1 << PWM1B);/* pwm enable, not inverted */
|
|
|
|
TCCR1B = (1 << CS10);/* fast pwm, no prescaler */
|
|
|
|
TCCR1B = (1 << CS11) | (1 << CS10);/* fast pwm, prescaler / 2 */
|
|
|
|
DDRB |= (1 << PB3);
|
|
|
|
DDRB |= (1 << PB3);
|
|
|
|
|
|
|
|
|
|
|
|
TIMSK = 1 << TOIE1;/* interrupt on overflow */
|
|
|
|
TIMSK = 1 << TOIE1;/* interrupt on overflow */
|
|
|
|
@ -50,21 +52,21 @@ uint32_t length;/* remaining samples */
|
|
|
|
|
|
|
|
|
|
|
|
ISR(TIMER1_OVF1_vect){
|
|
|
|
ISR(TIMER1_OVF1_vect){
|
|
|
|
// next try: simplistic, not too much looking at speed
|
|
|
|
// next try: simplistic, not too much looking at speed
|
|
|
|
uint16_t next;
|
|
|
|
uint16_t next = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if(--cnt_to_next){
|
|
|
|
if(!--cnt_to_next){
|
|
|
|
ringbuf_get(&rb, &next);
|
|
|
|
ringbuf_get(&rb, &next);
|
|
|
|
OCR1A = next>>8;
|
|
|
|
OCR1B = next>>8;
|
|
|
|
cnt_to_ocr_incr = 7-(next & 0x7);
|
|
|
|
cnt_to_ocr_incr = 8 - (next & 0x7);
|
|
|
|
cnt_to_next = 7;
|
|
|
|
cnt_to_next = 8;
|
|
|
|
if(!--length)
|
|
|
|
if(!--length)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* shut down */
|
|
|
|
/* shut down */
|
|
|
|
PORTA &= ~(1 << PA7);
|
|
|
|
PORTA &= ~(1 << PA7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if(--cnt_to_ocr_incr){
|
|
|
|
if(!--cnt_to_ocr_incr){
|
|
|
|
OCR1A += 1;
|
|
|
|
OCR1B += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|