chore(macros/ex02): used homebrew BV macro and fixed ex02 to use timer interupt
This commit is contained in:
parent
508ba6e857
commit
29b0d72ff9
17 changed files with 191 additions and 200 deletions
|
|
@ -8,30 +8,30 @@
|
|||
|
||||
static inline void t2_init_fpwm_3(e_timer_prescaler prescaler) {
|
||||
// Fast PWM (8-bit): WGM22:0 = 0b011
|
||||
TCCR2A = _BV(WGM20) | _BV(WGM21);
|
||||
TCCR2A = BV(WGM20) | BV(WGM21);
|
||||
|
||||
// reset to zero -> timer off
|
||||
TCCR2B &= ~(_BV(CS22) | _BV(CS21) | _BV(CS20));
|
||||
TCCR2B &= ~(BV(CS22) | BV(CS21) | BV(CS20));
|
||||
// set the correct prescaler
|
||||
switch (prescaler) {
|
||||
case (PRESCALER_1): {
|
||||
TCCR2B |= (_BV(CS20));
|
||||
TCCR2B |= (BV(CS20));
|
||||
break;
|
||||
}
|
||||
case (PRESCALER_8): {
|
||||
TCCR2B |= (_BV(CS21));
|
||||
TCCR2B |= (BV(CS21));
|
||||
break;
|
||||
}
|
||||
case (PRESCALER_64): {
|
||||
TCCR2B |= (_BV(CS21) | _BV(CS20));
|
||||
TCCR2B |= (BV(CS21) | BV(CS20));
|
||||
break;
|
||||
}
|
||||
case (PRESCALER_256): {
|
||||
TCCR2B |= (_BV(CS22));
|
||||
TCCR2B |= (BV(CS22));
|
||||
break;
|
||||
}
|
||||
case (PRESCALER_1024): {
|
||||
TCCR2B |= (_BV(CS22) | _BV(CS20));
|
||||
TCCR2B |= (BV(CS22) | BV(CS20));
|
||||
break;
|
||||
}
|
||||
case (PRESCALER_OFF): {
|
||||
|
|
@ -49,41 +49,41 @@ static inline void t2_set_ocr(enum e_timer_output output, uint8_t value) {
|
|||
|
||||
static inline void t2_set_out_mode(enum e_timer_output output, enum e_timer_output_mode mode) {
|
||||
if (output & TO_A) {
|
||||
TCCR2A &= ~(_BV(COM2A1) | _BV(COM2A0));
|
||||
TCCR2A &= ~(BV(COM2A1) | BV(COM2A0));
|
||||
switch (mode) {
|
||||
case (TOM_00): {
|
||||
break;
|
||||
}
|
||||
case (TOM_10): {
|
||||
TCCR2A |= (_BV(COM2A1));
|
||||
TCCR2A |= (BV(COM2A1));
|
||||
break;
|
||||
}
|
||||
case (TOM_01): {
|
||||
TCCR2A |= (_BV(COM2A0));
|
||||
TCCR2A |= (BV(COM2A0));
|
||||
break;
|
||||
}
|
||||
case (TOM_11): {
|
||||
TCCR2A |= (_BV(COM2A1) | _BV(COM2A0));
|
||||
TCCR2A |= (BV(COM2A1) | BV(COM2A0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (output & TO_B) {
|
||||
TCCR2A &= ~(_BV(COM2B1) | _BV(COM2B0));
|
||||
TCCR2A &= ~(BV(COM2B1) | BV(COM2B0));
|
||||
switch (mode) {
|
||||
case (TOM_00): {
|
||||
break;
|
||||
}
|
||||
case (TOM_10): {
|
||||
TCCR2A |= (_BV(COM2B1));
|
||||
TCCR2A |= (BV(COM2B1));
|
||||
break;
|
||||
}
|
||||
case (TOM_01): {
|
||||
TCCR2A |= (_BV(COM2B0));
|
||||
TCCR2A |= (BV(COM2B0));
|
||||
break;
|
||||
}
|
||||
case (TOM_11): {
|
||||
TCCR2A |= (_BV(COM2B1) | _BV(COM2B0));
|
||||
TCCR2A |= (BV(COM2B1) | BV(COM2B0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -98,15 +98,15 @@ static inline void t2_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
|
||||
TCCR2A = _BV(GM20) | _BV(GM21);
|
||||
TCCR2A |= _BV(COM2B1);
|
||||
TCCR2A = BV(GM20) | BV(GM21);
|
||||
TCCR2A |= BV(COM2B1);
|
||||
|
||||
// 50% duty cycle
|
||||
OCR0B = 128;
|
||||
|
||||
// Start timer, prescaler = 64
|
||||
TCCR2B = _BV(CS22);
|
||||
TCCR2B = BV(CS22);
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue