Espruino Wifi/Pico PWM differences

Posted on
  • Hello :)

    I'm having a bit of trouble with the Espruino Wifi pwm pins. My aim is to control my TV via infrared.

    Running the code below with the same LED on a Pico has a 100% success rate of powering on my TV, however the Wifi is only able to work 3/10 times.

    As far as I can tell from the board pinout, A5 and A6 have the same features for both the pico and wifi.

    Both boards are running 1v87.

    function on() {
      var command = new Float32Array(
        [
          3.502,
          1.75,
          0.502
          ...etc
        ]
      );
    
      emit(command, A5, A6);
    }
    
    function emit(command, pinOne, pinTwo) {
      analogWrite(pinOne,0.9,{freq:35000});
      digitalPulse(pinTwo, 1, command);
      digitalPulse(pinTwo, 1, 0);
      analogWrite(pinOne,0,{freq:35000});
    }
    

    Is it possible that the faster cpu in the wifi is breaking the PWM timings?

  • I had some fun with ESP8266 and 422mHz sockets a few months back, but it did work. I planned to try infrared on ESP8266 so am interested to see how you go on.

    Re the cpu - you can test at the slower clock speed for yourself with this command: E.setClock(80);

  • great idea!

    Just tried setting the wifi to the system clock speed as the pico with

    console.log(E.setClock({M:8, N:336, P:4, Q:7, PCLK1:2, PCLK2:4}));
    
    prints 84000000
    

    but unfortunately it made no difference.

  • Sorry to hear.

    One other thought, if you turn off the Wifi does this help? That's also an obvious difference to the Pico - the wifi module for Espruino Wifi includes a turnOff method. I'm wondering about power consumption of the ESP8266 basically.

    I also have both the Wifi and the Pico, so maybe I try this too.

  • Some ideas to try:
    Scope the LED pin to see if the frequency is correct.
    Use the Pico to receive the code and the EWiFi to send,
    Use the EWiFI to receive the code and the PICO to send, see if the data is sent and is correct.
    Try a visible LED and slow down the pulses to .5 Hz to see if it flashes analogWrite(pinOne,0.5,{freq:0.5}); Alternately use an IR sensor to look at the IR LED. (Some digital cameras can see IR, Iphone Android etc).
    I'm fiddling with a Pico and a DHT22 to control a window AC based on the room humidity using the IR remote signals.

  • I'll take a look at this in the next few hours. Seems strange though as it's basically the same chip as on the Pico (albeit with more memory and a higher clock speed) - about all I can think is the higher clock speed might be throwing off the PWM timings, but I'll check this.

    The only other thing I can think is that the WiFi's timing is actually more accurate - because it has an external low speed oscillator. If you recorded the IR signal on the Pico then the WiFi might replay it at a very slightly different speed. There shouldn't be more than 2% in it, but I guess that could be enough.

  • to make things stranger~, I generated the pwm data directly from https://github.com/z3t0/Arduino-IRremote­ instead of recording it. The same data and frequency also work correctly on an Arduino mega 2560.

    I'll try recording with the wifi. Maybe it's time to invest in a scope :)

    thanks for all the help!

  • Actually I just spotted - you're running PWM at 35000 Hz? Most things I've seen expect 38000 or 40000

    Having just tested on a scope, the PWM itself works great. However, digitalPulse is producing wildly varying pulse widths. It looks like a problem with the Wifi's firmware.

    The quick hack for this is to short out one of the little white capacitors by the crystal. That'll force it to use the internal oscillator, which fixes the problem (I just tested this and it works great).

    In the mean time I'll try and get a fix in the firmware - the Espruino boards use a relatively complicated arrangement to allow them to get high-res timing that is in sync with the real-time clock, and it looks like that's playing up.

  • I thought the same thing, but for some reason panasonic tvs use 35000 according to https://github.com/z3t0/Arduino-IRremote­/blob/master/ir_Panasonic.cpp#L24 (or I've completely misunderstood!)

    that's great news that's you've found an issue, thanks for taking the time to look into this

  • Ok, should be fixed now! Just do an advanced flash with the URL of the _wifi.bin image listed here: http://www.espruino.com/binaries/git/com­mits/master/

    Easiest way to test is just do: analogWrite(LED1,0.5,{freq:10,soft:true}­) - on the old image you should see the speed of flashing varying every second, but on the new image it should be stable.

  • perfect! the latest commit has completely fixed my issue, consider this issue solved.

    thanks all!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Espruino Wifi/Pico PWM differences

Posted by Avatar for Adam @Adam

Actions