Esp8266 micros() vs pwm

Hi , not sure on what category to use for this topic, so using this one...

I have program a ESP8266 digital output (gpio2) on a clock that I generated using the micros() function. This part worked fine until ,
I have programmed an other output (gpio12) where I can adjust duty cycle and frequency. gpio 12 Frequency is controlled thrue analogWriteFreq(240).
I do get the 240 Hz expected on gpio12 but this makes my gpio2 output frequency down to 120 Hz, regardless of the micros i had originally set up.

Does analogWriteFreq affect micros() ??

tks

please show your code

Hi,

here is the code with comments,hope it is clear.

tks

/* program generating a clock ( main ) at adjustable frequency
esp8266 gpio 2 configured as digital output where a scope is attached
Frequency reading shows 1000Hz for a MCp of 500 , OK.
*** MainClock frequency changes when I use gpio12 with adjustable pwm freq
not sure why
*/

bool MC; //main Clock pulse
long MCp = 500;// MainClock pulse period in uS ( note total period is *2 )
unsigned long last_MCu = 0;// store last MainClock micros
unsigned long MCu = 0; // MainClcok micros
int clockPin = 2;

const int pwmPin = 12; // D6 ou GPIO 12 , PWM
int dutyCycle = 200;

void setup() {
pinMode(clockPin, OUTPUT);
delay(100);
}

void loop() {

// generating the MasterClock
MCu = micros();
if(MCu-last_MCu >= MCp){ last_MCu =MCu; MC= !MC;}
digitalWrite(clockPin,MC);

// setting up an other output pin, gpio12, to get a 240 hz pwm signal
// enabling these two lines makes my 1000Hz mainclock running at 120Hz, why
analogWriteFreq(240);
analogWrite(pwmPin, dutyCycle);

}

Try with analogWriteFreq(240); in setup() , just in case.

Thank you ZX80 for the reply.
I had already tried this before posting.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.