Skip to content

Commit 5c75754

Browse files
authored
Merge pull request #393 from vintagepc/Timer_PWM2
Support 3rd PWM pin on timers with OCRxC
2 parents 4cd9f83 + 574c005 commit 5c75754

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

simavr/sim/avr_timer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ avr_timer_write_ocr(
624624
avr_timer_reconfigure(timer, 0); // if OCRA is the top, reconfigure needed
625625
}
626626
avr_raise_irq(timer->io.irq + TIMER_IRQ_OUT_PWM1, _timer_get_ocr(timer, AVR_TIMER_COMPB));
627+
if (sizeof(timer->comp)>2)
628+
avr_raise_irq(timer->io.irq + TIMER_IRQ_OUT_PWM2, _timer_get_ocr(timer, AVR_TIMER_COMPC));
627629
break;
628630
case avr_timer_wgm_fast_pwm:
629631
if (oldv != _timer_get_comp_ocr(avr, comp))
@@ -632,6 +634,9 @@ avr_timer_write_ocr(
632634
_timer_get_ocr(timer, AVR_TIMER_COMPA));
633635
avr_raise_irq(timer->io.irq + TIMER_IRQ_OUT_PWM1,
634636
_timer_get_ocr(timer, AVR_TIMER_COMPB));
637+
if (sizeof(timer->comp)>2)
638+
avr_raise_irq(timer->io.irq + TIMER_IRQ_OUT_PWM2,
639+
_timer_get_ocr(timer, AVR_TIMER_COMPC));
635640
break;
636641
default:
637642
AVR_LOG(avr, LOG_WARNING, "TIMER: %s-%c mode %d UNSUPPORTED\n",
@@ -851,6 +856,7 @@ avr_timer_reset(
851856
static const char * irq_names[TIMER_IRQ_COUNT] = {
852857
[TIMER_IRQ_OUT_PWM0] = "8>pwm0",
853858
[TIMER_IRQ_OUT_PWM1] = "8>pwm1",
859+
[TIMER_IRQ_OUT_PWM2] = "8>pwm2",
854860
[TIMER_IRQ_IN_ICP] = "<icp",
855861
[TIMER_IRQ_OUT_COMP + 0] = ">compa",
856862
[TIMER_IRQ_OUT_COMP + 1] = ">compb",
@@ -883,6 +889,7 @@ avr_timer_init(
883889
// pwm value it makes sense not to bother.
884890
p->io.irq[TIMER_IRQ_OUT_PWM0].flags |= IRQ_FLAG_FILTERED;
885891
p->io.irq[TIMER_IRQ_OUT_PWM1].flags |= IRQ_FLAG_FILTERED;
892+
p->io.irq[TIMER_IRQ_OUT_PWM2].flags |= IRQ_FLAG_FILTERED;
886893

887894
if (p->wgm[0].reg) // these are not present on older AVRs
888895
avr_register_io_write(avr, p->wgm[0].reg, avr_timer_write, p);

simavr/sim/avr_timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ enum {
3939
enum {
4040
TIMER_IRQ_OUT_PWM0 = 0,
4141
TIMER_IRQ_OUT_PWM1,
42+
TIMER_IRQ_OUT_PWM2,
4243
TIMER_IRQ_IN_ICP, // input capture
4344
TIMER_IRQ_OUT_COMP, // comparator pins output IRQ
4445

@@ -71,7 +72,7 @@ enum {
7172
avr_timer_com_toggle, // Toggle OCnx on compare match
7273
avr_timer_com_clear, // clear OCnx on compare match
7374
avr_timer_com_set, // set OCnx on compare match
74-
75+
7576
};
7677

7778
enum {

0 commit comments

Comments
 (0)