chore(macros/ex02): used homebrew BV macro and fixed ex02 to use timer interupt

This commit is contained in:
Maix0 2026-04-19 15:38:04 +02:00
parent 508ba6e857
commit 29b0d72ff9
17 changed files with 191 additions and 200 deletions

View file

@ -8,30 +8,30 @@
static inline void t0_init_fpwm_3(e_timer_prescaler prescaler) {
// Fast PWM (8-bit): WGM22:0 = 0b011
TCCR0A = _BV(WGM00) | _BV(WGM01);
TCCR0A = BV(WGM00) | BV(WGM01);
// reset to zero -> timer off
TCCR0B &= ~(_BV(CS02) | _BV(CS01) | _BV(CS00));
TCCR0B &= ~(BV(CS02) | BV(CS01) | BV(CS00));
// set the correct prescaler
switch (prescaler) {
case (PRESCALER_1): {
TCCR0B |= (_BV(CS00));
TCCR0B |= (BV(CS00));
break;
}
case (PRESCALER_8): {
TCCR0B |= (_BV(CS01));
TCCR0B |= (BV(CS01));
break;
}
case (PRESCALER_64): {
TCCR0B |= (_BV(CS01) | _BV(CS00));
TCCR0B |= (BV(CS01) | BV(CS00));
break;
}
case (PRESCALER_256): {
TCCR0B |= (_BV(CS02));
TCCR0B |= (BV(CS02));
break;
}
case (PRESCALER_1024): {
TCCR0B |= (_BV(CS02) | _BV(CS00));
TCCR0B |= (BV(CS02) | BV(CS00));
break;
}
case (PRESCALER_OFF): {
@ -49,41 +49,41 @@ static inline void t0_set_ocr(enum e_timer_output output, uint8_t value) {
static inline void t0_set_out_mode(enum e_timer_output output, enum e_timer_output_mode mode) {
if (output & TO_A) {
TCCR0A &= ~(_BV(COM0A1) | _BV(COM0A0));
TCCR0A &= ~(BV(COM0A1) | BV(COM0A0));
switch (mode) {
case (TOM_00): {
break;
}
case (TOM_10): {
TCCR0A |= (_BV(COM0A1));
TCCR0A |= (BV(COM0A1));
break;
}
case (TOM_01): {
TCCR0A |= (_BV(COM0A0));
TCCR0A |= (BV(COM0A0));
break;
}
case (TOM_11): {
TCCR0A |= (_BV(COM0A1) | _BV(COM0A0));
TCCR0A |= (BV(COM0A1) | BV(COM0A0));
break;
}
}
}
if (output & TO_B) {
TCCR0A &= ~(_BV(COM0B1) | _BV(COM0B0));
TCCR0A &= ~(BV(COM0B1) | BV(COM0B0));
switch (mode) {
case (TOM_00): {
break;
}
case (TOM_10): {
TCCR0A |= (_BV(COM0B1));
TCCR0A |= (BV(COM0B1));
break;
}
case (TOM_01): {
TCCR0A |= (_BV(COM0B0));
TCCR0A |= (BV(COM0B0));
break;
}
case (TOM_11): {
TCCR0A |= (_BV(COM0B1) | _BV(COM0B0));
TCCR0A |= (BV(COM0B1) | BV(COM0B0));
break;
}
}
@ -98,15 +98,15 @@ static inline void t0_set_out_mode(enum e_timer_output output, enum e_timer_outp
/*
// OC2B = PD3 → output
DDRD |= _BV(DDD3) | _BV(DDD5) | _BV(DDD6);
DDRD |= BV(DDD3) | BV(DDD5) | BV(DDD6);
// Fast PWM (8-bit): WGM22:0 = 0b011
TCCR0A = _BV(WGM00) | _BV(WGM01);
TCCR0A |= _BV(COM0B1);
TCCR0A = BV(WGM00) | BV(WGM01);
TCCR0A |= BV(COM0B1);
// 50% duty cycle
OCR0B = 128;
// Start timer, prescaler = 64
TCCR0B = _BV(CS02);
TCCR0B = BV(CS02);
*/