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

I demonstrated how to build a simple SUMP logic analyzer with [my ‘logic-analyzer’ library] in my last blog, (https://github.com/pschatzmann/logic-analyzer). Of cause the described sketch is also working for the ESP32. But we can do better!

Here is an improved implementation which uses both cores:

#include "Arduino.h"
#include "logic_analyzer.h"
#include "esp_int_wdt.h"

#ifndef LED_BUILTIN
#define LED_BUILTIN 13 // pin number is specific to your esp32 board
#endif

using namespace logic_analyzer;  

int pinStart=START_PIN;
int numberOfPins=PIN_COUNT;

LogicAnalyzer logicAnalyzer;
Capture capture(MAX_FREQ, MAX_FREQ_THRESHOLD);
TaskHandle_t task;

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

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

void setup() {
    // Setup Serial
    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
    int stack = 10000;
    int priority = 1;
    int core = 0;
    xTaskCreatePinnedToCore(captureHandler, "CaptureTask", stack, nullptr, priority, &task, core); 

}

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

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

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


1 Comment

;-) · 24. September 2021 at 18:02

nice!

Leave a Reply

Avatar placeholder

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