The timer1 works fine until i use the function analogWrite(pin, state).
What could be the problem?
If analogWrite() uses a timer1, how do I work with the analogWrite() and the timer1 at the same time? The Ticker library is not suitable for solving my problems, I need a hardware timer.
#define PIN_LED 2
bool b = false;
void ICACHE_RAM_ATTR timer_callback(void){
b=!b;
Serial.print(b);
wdt_reset();
}
void setup() {
pinMode(PIN_LED, OUTPUT);
Serial.begin(115200);
timer1_disable();
timer1_attachInterrupt(timer_callback);
timer1_isr_init();
timer1_enable(TIM_DIV16, TIM_EDGE, TIM_LOOP);
timer1_write(100000);
delay(1000);
analogWrite(PIN_LED, 512);
Serial.print("analogWrite enabled");
//Set up ESP watchdog
ESP.wdtDisable();
ESP.wdtEnable(WDTO_8S);
}
void loop() {
}
DEBUG:
10101010101010101010101010101010101010101010101010analogWrite enabled
Platform
- Hardware: [ESP-12E]
- Core Version: [latest]
- Development Env: [Arduino IDE]
- Operating System: [Windows]
- Module: [Nodemcu]
- Flash Size: [4MB/3MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [921600]