Divider by 50 with attiny4/5/9/10; at the moment the price of the micros on Digikey is ~$0.44CAD - competing with the logic circuits.
Setting the proper division ratio(between 2 and 256) is the user's job.
And sorry for the poor coding skills.
;Divider by 50 for attiny4/5/9/10 © 2021 Zoltan Soos, GPL3
;Schematics: 5V power supply, PB0 PWM output, PB1 external clock input, PB2&3 NC
;
;Timer count to 49(0x31), output compare at 24(0x18), direct clock(external) source
;
;ADC and AC disabled(PRR=(1<<PRADC); ACSR=(1<<ACD))
;
;Timer/Counter 0 output compare A is used for the divided signal
;
;Fast PWM mode 14(WGM0[3:0]==0b1110)
;
;ICR0H=0x00, ICR0L=0x31(TOP)
;
;OCR0AH=0x00, OCR0AL=0x18(compare match)
;
;
.include "tn10def.inc"
;Register definitions
.def TEMP =r16 ; Scratchpad 1
.def TEMP_1 =r17 ; Scratchpad 2
;End register definitions
.CSEG
.org 0
; Turn off analog comparator
ldi TEMP, (1<<ACD) ;
out ACSR, TEMP ;
; Turn off ADC
ldi TEMP,(1<<PRADC) ;
out PRR, TEMP ;
; Setup I/O Port
ldi TEMP, (1<<DDB0) ; PB0 is Output, the rest Input
out DDRB, TEMP ;
ldi TEMP, (1<<PUEB2|1<<PUEB3) ;
out PUEB, TEMP ; Pull up PB2-3
; Setup timer
ldi TEMP, (1<<COM0A1|1<<WGM01) ;
out TCCR0A,TEMP ; Set up the timer mode
ldi TEMP, (1<<CS00|1<<WGM02|1<<WGM03) ;
out TCCR0B, TEMP ; and clock source
ldi TEMP, 0x31 ; Setting up the division factor
clr TEMP_1 ;
out ICR0H, TEMP_1 ;
out ICR0L, TEMP ;
ldi TEMP, 0x18 ; And the switching point
out OCR0AH, TEMP_1 ;
out OCR0AL, TEMP ;
ldi TEMP, (1<<SE) ; Setup idle mode
out SMCR, TEMP ;
ldi TEMP, 0xD8 ; Unprotect CLKPSR and CLKMSR reg
clr TEMP_1 ; Divide by 1
out CCP, TEMP ;
out CLKPSR, TEMP_1 ;
ldi TEMP_1, (1<<CLKMS1) ; Switch to external clock
out CCP, TEMP ;
out CLKMSR, TEMP_1 ;
main:
sleep ;
rjmp main ;