@@ -126,6 +126,12 @@ RMTChannel *channelHandle[8] = { 0 };
126126
127127static volatile uint8_t cutoutCounter = 0 ;
128128
129+ // define time values for cutout
130+ #define CUTOUT_TOTAL 486 // usec
131+ #define CUTOUT_BASE_FREQ 2057 // 1000*1000/CUTOUT_TOTAL Hz
132+ #define CUTOUT_PULSE 459 // CUTOUT_TOTAL-27
133+ #define CUTOUT_OFFSET_IN_PROMILLE 944 // CUTOUT_PULSE*1000/CUTOUT_TOTAL // 1-(28/488)
134+ #define CUTOUT_OFFSET_IN_PERCENT 94.4 // CUTOUT_OFFSET_IN_PROMILLE/10.0 // float please
129135// As the DCC packet end marker was moved to the next preamble
130136// this happens at the beginning of that end packet marker (bit).
131137void IRAM_ATTR interrupt (rmt_channel_t channel, void *t) {
@@ -138,10 +144,10 @@ void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) {
138144 // not needed here, we keep it enabled all the time
139145 // MCPWM1.int_ena.timer0_tez_int_ena = 1; // Enable interrupt on TEZ
140146 __digitalWrite (13 /* BRKA*/ , 0 );
141- mcpwm_set_duty_in_us (MCPWM_UNIT_1, MCPWM_TIMER_0, MCPWM_GEN_A, 464 );
147+ mcpwm_set_duty_in_us (MCPWM_UNIT_1, MCPWM_TIMER_0, MCPWM_GEN_A, CUTOUT_PULSE );
142148 mcpwm_sync_config_t sync_conf = {
143149 .sync_sig = MCPWM_SELECT_GPIO_SYNC0,
144- .timer_val = 939 , // in promille of all values
150+ .timer_val = CUTOUT_OFFSET_IN_PROMILLE , // in promille of all values
145151 .count_direction = MCPWM_TIMER_DIRECTION_UP,
146152 };
147153 mcpwm_sync_configure (MCPWM_UNIT_1, MCPWM_TIMER_0, &sync_conf);
@@ -188,9 +194,9 @@ static void IRAM_ATTR mcpwmPulseOn() {
188194 digitalWrite (13 , 1 );
189195
190196 mcpwm_config_t pwm_config = {
191- .frequency = 2024 , // in Hz 1/0.000494 (30+464usec = 494 usec)
192- .cmpr_a = 93.9 , // duty cycle of PWMxA (float in %, 100%-6.1 %)
193- .cmpr_b = 0 , // not used
197+ .frequency = CUTOUT_BASE_FREQ , // calculation see above
198+ .cmpr_a = CUTOUT_OFFSET_IN_PERCENT, // duty cycle of PWMxA (float in %)
199+ .cmpr_b = 0 , // not used
194200 .duty_mode = MCPWM_DUTY_MODE_0,
195201 .counter_mode = MCPWM_UP_COUNTER,
196202 };
@@ -199,7 +205,7 @@ static void IRAM_ATTR mcpwmPulseOn() {
199205
200206 mcpwm_sync_config_t sync_conf = {
201207 .sync_sig = MCPWM_SELECT_GPIO_SYNC0,
202- .timer_val = 939 ,
208+ .timer_val = CUTOUT_OFFSET_IN_PROMILLE, // calculation see above
203209 .count_direction = MCPWM_TIMER_DIRECTION_UP,
204210 };
205211 // default is pos edge trigger, handled by mcpwm_sync_invert_gpio_synchro()
0 commit comments