Together with Pulseview, the Raspberry Pico can be turned into a Logic Analyzer.

I demonstrated how to build a simple SUMP logic analyzer with my Arduino logic-analyzer library in my last blog.

But we can do better: Here is an first version of an improved Pico implementation which uses both cores:

#include "Arduino.h"
#include "logic_analyzer.h"
#include "pico/multicore.h"

using namespace logic_analyzer;  

int pinStart=START_PIN;
int numberOfPins=PIN_COUNT;
LogicAnalyzer logicAnalyzer;
Capture capture(MAX_FREQ, MAX_FREQ_THRESHOLD);

// when the status is changed to armed we start the capture
void captureHandler(){
    // we use the led to indicate the capturing
    pinMode(LED_BUILTIN, OUTPUT);

    while(true){
        if (logicAnalyzer.status() == ARMED){
            // start capture
            digitalWrite(LED_BUILTIN, HIGH);
            logicAnalyzer.capture();
            digitalWrite(LED_BUILTIN, LOW);
        }
    }
}

void setup() {
    Serial.begin(SERIAL_SPEED);  
    Serial.setTimeout(SERIAL_TIMEOUT);

    logicAnalyzer.setDescription(DESCRIPTION);
    logicAnalyzer.setCaptureOnArm(false);
    logicAnalyzer.begin(Serial, &capture, MAX_CAPTURE_SIZE, pinStart, numberOfPins);

    // launch the capture handler on core 1
    multicore_launch_core1(captureHandler);
}

void loop() {
    if (Serial) logicAnalyzer.processCommand();
}

The big change to the original Sketch is, that we do the capturing now on the core 1. This is done in the captureHandler() method which is started with the help of the multicore_launch_core1() method. So after this change the stop button in Pulseview is aborting the capturing as expected!

The described sketch is working with the help of pico-arduiono library. Unfortunately it does not work with the standard Arduino implementation because that does not provide the multicore_launch_core1() method.

You can find the example in the examples directory. To build it just execute:

mkdir build
cd build
cmake ..
make

At max speed this implementation captures at around 2.2MHz. In the next version I plan to use the PIO which should allow much higher speeds.

I hope I could demonstrate how easy it is to develop a dedicated custom Arduino based Logic Analyzer for your preferred processor…


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *