You are reading a single comment by @user135646 and its replies. Click here to read the full conversation.
  • Finally got around to this, and results are excellent. Getting <0.3us jitter.
    The examples definitely came in handy, although there's a bit of guesswork involved in sending the right values to the right places.

    A working example is included below though that uses a button on D17 to start / stop a train of pulses.

    var ll = require("NRF52LL");
    // 100Hz pulses of 20us width, but triggered by button press.
    // Set up D20 as output
    digitalWrite(D20, 0);
    // Create a task for the pin
    var t0 = ll.gpiote(7, {type:"task",pin:D20});
    // Create a timer using timer 2 that counts to 10000
    // and has capture-compares at 20 and 10000 counts.
    var tmr = ll.timer(2, {cc:[20, 10000],cc1clear:1});
    // User a PPI to trigger the events.
    ll.ppiEnable(0, tmr.eCompare[0], t0.tClr);
    ll.ppiEnable(1, tmr.eCompare[1], t0.tSet);
    //Button stuff to start/stop pulses.
    let btn = false;
    function checkBtn(){
        if (digitalRead(D17) == 1) {
            if (btn==false){
                // Manually start timer
                poke32(tmr.tStart,1);
                while(digitalRead(D17)){}
                btn=true;
            }
            else{
                // stop the timer.
                poke32(tmr.tStop,1);
                while(digitalRead(D17)){}
                digitalWrite(D20, 0);
                btn=false;
            }
        }
    }
    setInterval(checkBtn, 10);
    

    edit - added 'var ll = require("NRF52LL");' at top of example

About

Avatar for user135646 @user135646 started