Post topics, source code that relate to the Arduino Platform

User avatar
By Rofl92
#82621 Hi.
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.

Code: Select all#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:
Code: Select all10101010101010101010101010101010101010101010101010analogWrite enabled

Platform
  • Hardware: [ESP-12E]
  • Core Version: [latest]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]
Settings in IDE
  • 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]
User avatar
By theenggprojects
#83754 You should work on ESP8266 as it's quite easy to control and analogwrite is exactly the same as for Arduino UNO. I have designed projects on it, worked pretty neat.
Last edited by theenggprojects on Sun Feb 28, 2021 4:26 pm, edited 2 times in total.