Skip to content

Commit 860f33f

Browse files
committed
Fix spell errors and add more comments
1 parent 817efd6 commit 860f33f

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

DCCRMT.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* © 2021-2024, Harald Barth.
2+
* © 2021-2026, Harald Barth.
33
*
44
* This file is part of DCC-EX
55
*
@@ -126,6 +126,8 @@ RMTChannel *channelHandle[8] = { 0 };
126126

127127
static volatile uint8_t cutoutCounter = 0;
128128

129+
// As the DCC packet end marker was moved to the next preamble
130+
// this happens at the beginning of that end packet marker (bit).
129131
void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) {
130132
RMTChannel *tt = channelHandle[channel];
131133
if (tt) tt->RMTinterrupt();
@@ -146,8 +148,8 @@ void IRAM_ATTR interrupt(rmt_channel_t channel, void *t) {
146148
}
147149
}
148150

149-
150-
static void IRAM_ATTR mvpwmIsrHandler(void* arg) {
151+
// This intrrupt is called on sync which is configured on mcpwmPulseOn()
152+
static void IRAM_ATTR mcpwmIsrHandler(void* arg) {
151153
if (MCPWM0.int_st.timer0_tez_int_st) {
152154
MCPWM0.int_clr.timer0_tez_int_clr = 1;
153155
if (cutoutCounter == 1) {
@@ -172,7 +174,13 @@ static void IRAM_ATTR mvpwmIsrHandler(void* arg) {
172174
}
173175
}
174176

175-
static void IRAM_ATTR mvpwmPulseOn() {
177+
178+
// Configure MCPWM unit 0.
179+
// https://docs.espressif.com/projects/esp-idf/en/v4.4/esp32/api-reference/peripherals/mcpwm.html
180+
// Connect Operator 0 output A PWM0A to pin XXX (this should go to brake then)
181+
// Connect Timer0 input sync 0 SYNC0 from pin YYY (this should connect to RMT channel 0 output
182+
// pin through the mux)
183+
static void IRAM_ATTR mcpwmPulseOn() {
176184

177185
// for debug
178186
//gpio_set_direction((gpio_num_t)13, GPIO_MODE_OUTPUT);
@@ -194,6 +202,8 @@ static void IRAM_ATTR mvpwmPulseOn() {
194202
.timer_val = 939,
195203
.count_direction = MCPWM_TIMER_DIRECTION_UP,
196204
};
205+
// default is pos edge trigger, handled by mcpwm_sync_invert_gpio_synchro()
206+
// if neg edge needed
197207
mcpwm_sync_configure(MCPWM_UNIT_0, MCPWM_TIMER_0, &sync_conf);
198208
mcpwm_gpio_init(MCPWM_UNIT_0, MCPWM_SYNC_0, 5 /*DIRA*/);
199209
}
@@ -289,10 +299,10 @@ RMTChannel::RMTChannel(pinpair pins, bool isMain) {
289299
//rmt_write_items(channel, preamble, preambleLen, false);
290300
RMTprefill();
291301
dataReady = false;
292-
// test with mvpwm
293-
mvpwmPulseOn();
302+
// test with mcpwm
303+
mcpwmPulseOn();
294304
ESP_ERROR_CHECK(mcpwm_isr_register(
295-
MCPWM_UNIT_0, mvpwmIsrHandler, NULL,
305+
MCPWM_UNIT_0, mcpwmIsrHandler, NULL,
296306
ESP_INTR_FLAG_LOWMED|
297307
ESP_INTR_FLAG_SHARED,
298308
/*ESP_INTR_FLAG_IRAM,*/

0 commit comments

Comments
 (0)