You are reading a single comment by @CamSwords and its replies. Click here to read the full conversation.
  • Hi Gordon!

    A few of the folks at work have been building a quadcopter flight controller with me using an Espruino. It's fantastic, we've had lots of fun. We've done some interesting things - we've written a gulp deploy tool, we run unit tests using the espruino process on our macs, we have written our own AMD loader, AMD optimiser and a promise library. All of this is very crude.

    Anyone wanting to see the code can do so here:

    https://github.com/camswords/quadcopter/­tree/master/src/main

    We have wired up an input pin to receive a PWM signal from the RC receiver. We have registered a function similar to the following to 'watch' on a falling edge in a repeating way.

    function(event) {
          var dutyCycle = Math.floor((event.time - event.lastTime) * 1000000);
      
          ...
    }
    

    Strangely, when we send the (dutyCycle, event.time, event.lastTime) to my laptop via bluetooth we get output such as the following (forget the strange characters, that is related to my serial / bluetooth solution, not this issue):

    981.33087158203125, 4.910�20849609375, 4.90931987762451171875|
    981.33087158203125, 4.9816s751708984375, 4.98071384429931640625|
    980.377197265625, 5.05308�71484375, 5.052104949951171875|
    981.33087158203125, 5.124489784072265625, 5.123508453369140625|
    981.33087158203125, 5.1780481338506484375, 5.24847507476806640625|
    981.33087158203125, 5.3208665847740625, 5.39130115509033203125|
    53564.0716552734375, 5.445846557�1875, 5.3922824859619140625|
    

    We expect values roughly between 1000 and 2000, as it is recording the length of the duty cycle (1ms to 2ms). Every now and again we get very large values in the time difference. My naiive guess is that this time is calculated by the CPU, not a timer? And code being executed may cause a delay between "event.time" and "event.lastTime"? If that is the case, is there anything I can do to get a timer to populate a register with the duty cycle, and have my 'watch' event fire on change of this value instead?

    I felt the same when writing PWM outputs for each of the propeller motors. We are using digitalPulse with a setInterval every 20ms, but I fear that the PWM signal quality will degrade when other code is executing at the time the signal should be pulsed. Looking at the STM library source (disclaimer: I know very little about this, and microcontrollers in general) my understanding is that I could write to a register and have a timer automatically adjust the duty cycle. I believe there is a TIM_SetCompareX method that does this.

    Does this make any sense? I'd love to hear your feedback. I'm not expecting you to solve these problems for me, I'm happy to jump into the code and send you a patch if it makes sense.

    fyi, we've been reading PWM signals on pin A8 and and sending PWM signals on pins C6, C7, C8 and C9. All of this is done on Espruino running 1v61. I'm happy to run this on a more up-to-date version of Espruino if required.

    Cheers
    Cam

About

Avatar for CamSwords @CamSwords started