Skip to content

Commit 1ae4230

Browse files
author
Me No Dev
committed
optimize pwm interrupt handler for better precision
1 parent 5edcaa0 commit 1ae4230

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cores/esp8266/core_esp8266_wiring_pwm.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,19 @@ void ICACHE_RAM_ATTR pwm_timer_isr(){
9494
static uint16_t steps[17];
9595
static uint32_t masks[17];
9696
if(current_step < stepcount){
97-
GPOC = masks[current_step] & 0xFFFF;
98-
if(masks[current_step] & 0x10000) GP16O &= ~1;
97+
T1L = (pwm_steps[current_step+1] * pwm_multiplier);
98+
TEIE |= TEIE1;
99+
if(masks[current_step] & 0xFFFF) GPOC = masks[current_step] & 0xFFFF;
100+
if(masks[current_step] & 0x10000) GP16O = 0;
99101
current_step++;
100-
timer1_write(pwm_steps[current_step] * pwm_multiplier);
101102
} else {
102-
103103
current_step = 0;
104104
stepcount = 0;
105105
if(pwm_mask == 0) return;
106-
GPOS = pwm_mask & 0xFFFF;
107-
if(pwm_mask & 0x10000) GP16O |= 1;
108-
timer1_write(pwm_steps[0] * pwm_multiplier);
106+
T1L = (pwm_steps[current_step+1] * pwm_multiplier);
107+
TEIE |= TEIE1;
108+
if(pwm_mask & 0xFFFF) GPOS = pwm_mask & 0xFFFF;
109+
if(pwm_mask & 0x10000) GP16O = 1;
109110
stepcount = pwm_steps_len;
110111
memcpy(steps, pwm_steps, (stepcount + 1) * 2);
111112
memcpy(masks, pwm_steps_mask, stepcount * 4);

0 commit comments

Comments
 (0)