Commit 749050d9c32c7908ad518ea2ce85f221f35f6606
authorBastien Scher <contact@bastien-scher.fr>
Wed, 18 Oct 2017 10:15:51 +0000 (12:15 +0200)
committerMichel Pollet <github.com@pollet.net>
Thu, 19 Oct 2017 07:24:29 +0000 (08:24 +0100)
3 files changed:
simavr/cores/sim_mega2560.c
simavr/sim/avr_timer.c
simavr/sim/avr_timer.h

index 2004498af768e43accbfc12d63d05edb5e69bf56..14ab6521527feb7c431b17a00bdc34f32a6c61d5 100644 (file)
@@ -275,7 +275,7 @@ const struct mcu_t {
                         [7] = AVR_TIMER_WGM_FASTPWM10(),
                         // TODO: 8, 9 PWM phase and freq correct ICR & 10, 11
                         [12] = AVR_TIMER_WGM_ICCTC(),
-                        [14] = AVR_TIMER_WGM_ICPWM(),
+                        [14] = AVR_TIMER_WGM_ICFASTPWM(),
                         [15] = AVR_TIMER_WGM_OCPWM(),
                },
                .cs = { AVR_IO_REGBIT(TCCR1B, CS10), AVR_IO_REGBIT(TCCR1B, CS11), AVR_IO_REGBIT(TCCR1B, CS12) },
@@ -401,7 +401,7 @@ const struct mcu_t {
                         //              10
                         //              11
                         [12] = AVR_TIMER_WGM_ICCTC(),
-                        [14] = AVR_TIMER_WGM_ICPWM(),
+                        [14] = AVR_TIMER_WGM_ICFASTPWM(),
                         [15] = AVR_TIMER_WGM_OCPWM(),
                },
                .cs = { AVR_IO_REGBIT(TCCR3B, CS30), AVR_IO_REGBIT(TCCR3B, CS31), AVR_IO_REGBIT(TCCR3B, CS32) },
@@ -478,7 +478,7 @@ const struct mcu_t {
                         [7] = AVR_TIMER_WGM_FASTPWM10(),
                         // TODO: 8, 9 PWM phase and freq correct ICR & 10, 11
                         [12] = AVR_TIMER_WGM_ICCTC(),
-                        [14] = AVR_TIMER_WGM_ICPWM(),
+                        [14] = AVR_TIMER_WGM_ICFASTPWM(),
                         [15] = AVR_TIMER_WGM_OCPWM(),
                },
                .cs = { AVR_IO_REGBIT(TCCR4B, CS40), AVR_IO_REGBIT(TCCR4B, CS41), AVR_IO_REGBIT(TCCR4B, CS42) },
@@ -556,7 +556,7 @@ const struct mcu_t {
                         [7] = AVR_TIMER_WGM_FASTPWM10(),
                         // TODO: 8, 9 PWM phase and freq correct ICR & 10, 11
                         [12] = AVR_TIMER_WGM_ICCTC(),
-                        [14] = AVR_TIMER_WGM_ICPWM(),
+                        [14] = AVR_TIMER_WGM_ICFASTPWM(),
                         [15] = AVR_TIMER_WGM_OCPWM(),
                },
                .cs = { AVR_IO_REGBIT(TCCR5B, CS50), AVR_IO_REGBIT(TCCR5B, CS51), AVR_IO_REGBIT(TCCR5B, CS52) },
index d430aa2d05db61df225fc8ba040c0fbf387e0bec..6be4a2931cb8fb0ab648ed8a7108ca03a761b997 100644 (file)
@@ -575,9 +575,12 @@ avr_timer_reconfigure(
                                _timer_get_ocr(p, AVR_TIMER_COMPA) : _timer_get_icr(p);
                        avr_timer_configure(p, p->cs_div_value, top, reset);
                }       break;
-               case avr_timer_wgm_fast_pwm:
-                       avr_timer_configure(p, p->cs_div_value, p->wgm_op_mode_size, reset);
-                       break;
+               case avr_timer_wgm_fast_pwm: {
+                       uint16_t top =
+                               (p->mode.top == avr_timer_wgm_reg_icr) ? _timer_get_icr(p) :
+                               p->wgm_op_mode_size;
+                       avr_timer_configure(p, p->cs_div_value, top, reset);
+               }       break;
                case avr_timer_wgm_none:
                        avr_timer_configure(p, p->cs_div_value, p->wgm_op_mode_size, reset);
                        break;
index e0c18e0c659543100b46ba5cc796358696b4d648..8e998571e433336c3498d34ebf00b3dbc08edb61 100644 (file)
@@ -104,6 +104,7 @@ typedef struct avr_timer_wgm_t {
 #define AVR_TIMER_WGM_FCPWM10() { .kind = avr_timer_wgm_fc_pwm, .size=10 }
 #define AVR_TIMER_WGM_OCPWM() { .kind = avr_timer_wgm_pwm, .top = avr_timer_wgm_reg_ocra }
 #define AVR_TIMER_WGM_ICPWM() { .kind = avr_timer_wgm_pwm, .top = avr_timer_wgm_reg_icr }
+#define AVR_TIMER_WGM_ICFASTPWM() { .kind = avr_timer_wgm_fast_pwm, .top = avr_timer_wgm_reg_icr }
 
 typedef struct avr_timer_comp_t {
                avr_int_vector_t        interrupt;              // interrupt vector