Created
December 13, 2023 20:52
-
-
Save wd5gnr/040ed0700f2c741ade9aa5cf8d95f573 to your computer and use it in GitHub Desktop.
Trigger Demo Waveforms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For best results use Normal trigger mode | |
#define CLOCK 6 // ch1 | |
#define DATA 15 // ch2 | |
#define RS232_OUT 0 // D0 -- by default; this symbol is not used | |
#define RS232_IN 1 // not really used | |
#define ANALOG_CLEAR 21 // Discharge analog capacitor fast | |
#define ANALOG_OUT 22 // ch3 | |
#define BAUDRATE 9600 | |
// Pick one and only one of the below | |
#define SETUPHOLD 0 | |
#define TIMEOUT 0 // set to timeout, falling (pin 0) 5ms. | |
// or set to edge 2.2V falling -- mostly stable, but with blinking | |
// Or over, rising 3.94 to 800mV Enter | |
// or duration ch1=0, ch3=0, >2ms | |
// or Nth with 2ms timeout and 100th pulse (or less) | |
// Or pattern with CH1=Rising, Ch3=0 | |
// Or delay A=Ch3/Fall, B=Ch1/Rise, >5mS | |
#define PULSE 0 // set to pulse positive > 4ms 2V level. Zoom on 5th pulse to see short pulse | |
// or... trigger on pulse <500uS to see the 5th pulse (hard to see w/o zoom) | |
// or trigger on duration CH1, >5mS (or <500us) (note can add other channels/conditions) | |
#define ANALOGSLOPE 1 // Slope trigger: falling, 2.93V/50mV/75ms < | |
#define ANALOGRUNT 0 // Runt trigger None, 1.14V, 138msV, positive | |
// RS232 is different so it is all in one core | |
void setup1() | |
{ | |
Serial1.begin(BAUDRATE); | |
} | |
// RS232 loop | |
// RS232 Trigger +, 2V level Data, 72 9600 baud, 8/1/n + decode if you like | |
// Or Duration 2.9V 11mS > CHx=1 | |
// Or edge falling | |
void loop1() | |
{ | |
static int count = 0; | |
Serial1.printf("Hackaday %d\r\n", count++); | |
delay(1000); | |
} | |
// Various digital/analog signal patterns | |
void setup() | |
{ | |
Serial.begin(115200); | |
pinMode(CLOCK, OUTPUT); | |
pinMode(DATA, OUTPUT); | |
analogWriteFreq(1000000); | |
analogWriteRange(0xFFFF); | |
pinMode(ANALOG_CLEAR, INPUT); | |
analogWrite(ANALOG_OUT, 0x8000); | |
Serial.println("Here we go..."); | |
} | |
unsigned int loops = 0; | |
#if SETUPHOLD | |
void loop() // setup 10uS, hold 50uS | |
{ | |
static uint16_t counter = 0; | |
if (counter==10) | |
counter = 0; | |
counter++; | |
digitalWrite(DATA, counter & 1 ); // data | |
if (counter!=3) delayMicroseconds(10); // setup time (setup violation on count 3) | |
digitalWrite(CLOCK, 1); // clock | |
if (counter==5) | |
digitalWrite(DATA, (counter & 1) ? 0 : 1); // hold violation on count 5 | |
delayMicroseconds(100); // hold | |
digitalWrite(CLOCK, 0); // end clock | |
delayMicroseconds(100); // wait a bit | |
} | |
#endif | |
#if ANALOGSLOPE || ANALOGRUNT | |
uint16_t steps[] = {0x100, 0x4000, 0xF000, 0x4000}; | |
void loop() | |
{ | |
static uint16_t counter = 0; | |
static uint16_t subcounter = 4; | |
#if ANALOGRUNT | |
if (counter==2 && --subcounter==0) | |
{ | |
subcounter = 4; | |
counter = 3; // skip peak | |
} | |
#endif | |
analogWrite(22, steps[counter]); | |
if (counter==0) | |
{ | |
if (--subcounter==0) // every so often let the caps discharge naturally | |
{ | |
#if ANALOGSLOPE | |
digitalWrite(ANALOG_CLEAR, 0); | |
pinMode(ANALOG_CLEAR, OUTPUT); | |
subcounter = 4; | |
#endif | |
} | |
delay(150); | |
pinMode(ANALOG_CLEAR, INPUT); | |
} | |
else | |
delay(40); | |
if (++counter>=4) | |
counter = 0; | |
} | |
#endif | |
#if TIMEOUT | |
void loop() | |
{ | |
if (loops%100==0) | |
{ | |
digitalWrite(DATA, 0); | |
delay(10); | |
} | |
loops++; | |
digitalWrite(CLOCK, 1); | |
digitalWrite(DATA, 0); | |
delay(1); | |
digitalWrite(CLOCK, 0); | |
digitalWrite(DATA, 1); | |
delay(1); | |
} | |
#endif | |
#if PULSE | |
void loop() | |
{ | |
loops++; | |
digitalWrite(CLOCK, 1); | |
digitalWrite(DATA, 0); | |
if (loops%100==5) | |
delayMicroseconds(50); | |
else if (loops % 100==0) | |
delay(9); | |
else | |
delay(1); | |
digitalWrite(CLOCK, 0); | |
digitalWrite(DATA, 1); | |
if (loops%100==5) | |
delayMicroseconds(50); | |
else if (loops % 100 == 0) | |
delay(9); | |
else | |
delay(1); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment