#include #include #include #include //#include //#include //#include //tests5 tested and works (at ~950hz). unplug cable to programmer to see pin 4 active. //however... //tests6 DEADEND //never worked right. giving up and using delay. //reference: https://www.avrfreaks.net/forum/sample-project-attiny10 //https://blog.podkalicki.com/attiny13-blinky-with-timer-compa/ //watchdog is too slow and inaccurate to get 6000Hz ISR(TIM0_COMPA_vect) { // Toggle PB2 Hi/Low depending on current state PINB = 1<<2; TIFR0 |= 1< 256? (test) //520 about 950hz, 25us wide pulse //OCR0A = 520; // with one timer, ever 166.667hz we want to count once (3000hz) //OCR0A = 1; //475hz //this goes to 475hz (pulses). doesn't make sense. //// OCR0AH = 0xFF; // //// OCR0AL = 0xFF; //attiny10 output compare broken apparently //this still 960hz, with 100us or so pulse size (high is 100us, low is longer) //OCR0A = 100; //inline asm to load values into 16 bit register //; variables //; For 1 Hz output, the timer delay has to be 1/2 second (1/2 second on / 1/2 second off) //; delay = OCR0A * 1024 * 8 / 8000000 //; for 1/2 second, OCR0A = 488 (0x01E8) //.EQU OCR0AHigh = 0x01 //.EQU OCR0ALow = 0xe8 // in bash type: printf "%x\n" 488 //.EQU OCR0AHigh = 0x02 //.EQU OCR0ALow = 0x08 // ldi r17, OCR0AHigh //; Sets the output compare register value //ldi r16, OCR0ALow //this asm doesn't work (why?) //perhaps OCR0A is really just 8 bits on attiny10...?) ////// asm volatile( ////// "ldi r17, 0x02" ////// "ldi r16, 0x08" ////// "out OCR0AH, r17" ////// "out OCR0AL, r16" ////// ); //this asm works // asm volatile("nop\n\t" //"nop\n\t" //"nop\n\t" //"nop\n\t" //::); TIMSK0 |= _BV(OCIE0A); // enable Timer CTC interrupt // PB2 change to output DDRB = 1<<2; sei(); while(1) { //handled by interrupt } }