I download TeensyDelay reference here https://www.pjrc.com/teensy/td_timing_IntervalTimer.html
Download source https://github.com/luni64/TeensyDelay
Arduino 1.8.9
Board: Teensy 3.5
GOAL:
When PIN 11 detects falling edge, set Pin 6 HIGH at some time in the future. In this case 10 us.
After PIN 6 is set HIGH, 500us later Pin 6 is set LOW.
Basically a one shot pulse.
If I add a small delay 10 - 100 ms delay in the main loop of the not working code below, it kind of works but the signal is not smooth like I want it to be.
I want to trigger timers in the main loop. Why is this code behaving this way? Can someone please explain?
What do I need to do to correct this weird behavior?
#### NOT WORKING ####
#include "TeensyDelay.h"
// Trigger pin
int trigger = 11;
volatile int pulse = 0;
// callback function for channel 0
void callback_A()
{
Serial1.println("Callback A");
digitalWriteFast(6,HIGH);
TeensyDelay::trigger(500,4);
}
// callback function for channel 1
void callback_B()
{
pulse = 0;
Serial1.println("Callback B");
digitalWriteFast(6,LOW);
}
void event()
{
pulse = 1;
}
void setup()
{
pinMode(6, OUTPUT);
pinMode(trigger, INPUT_PULLUP);
Serial1.begin(115200,SERIAL_8N1);
Serial1.println("Timer Debug: ");
TeensyDelay::begin();
TeensyDelay::addDelayChannel(callback_A,0); //setup channel 0
TeensyDelay::addDelayChannel(callback_B,4); //setup channel 1
attachInterrupt(digitalPinToInterrupt(trigger), event, FALLING);
}
void loop()
{
if(pulse)
{
//Serial1.println("Main Loop: ");
TeensyDelay::trigger(10,0);
}
//delay(100);
}
###### Working Code ######
#include "TeensyDelay.h"
// Trigger pin
int trigger = 11;
// callback function for channel 0
void callback_A()
{
Serial1.println("Callback A");
digitalWriteFast(6,HIGH);
TeensyDelay::trigger(500,4);
}
// callback function for channel 1
void callback_B()
{
Serial1.println("Callback B");
digitalWriteFast(6,LOW);
}
void event()
{
TeensyDelay::trigger(10,0);
}
void setup()
{
pinMode(6, OUTPUT);
pinMode(trigger, INPUT_PULLUP);
Serial1.begin(115200,SERIAL_8N1);
Serial1.println("Timer Debug: ");
TeensyDelay::begin();
TeensyDelay::addDelayChannel(callback_A,0); //setup channel 0
TeensyDelay::addDelayChannel(callback_B,4); //setup channel 1
attachInterrupt(digitalPinToInterrupt(trigger), event, FALLING);
}
void loop()
{
}
Scope working
Scope not working
Download source https://github.com/luni64/TeensyDelay
Arduino 1.8.9
Board: Teensy 3.5
GOAL:
When PIN 11 detects falling edge, set Pin 6 HIGH at some time in the future. In this case 10 us.
After PIN 6 is set HIGH, 500us later Pin 6 is set LOW.
Basically a one shot pulse.
If I add a small delay 10 - 100 ms delay in the main loop of the not working code below, it kind of works but the signal is not smooth like I want it to be.
I want to trigger timers in the main loop. Why is this code behaving this way? Can someone please explain?
What do I need to do to correct this weird behavior?
#### NOT WORKING ####
#include "TeensyDelay.h"
// Trigger pin
int trigger = 11;
volatile int pulse = 0;
// callback function for channel 0
void callback_A()
{
Serial1.println("Callback A");
digitalWriteFast(6,HIGH);
TeensyDelay::trigger(500,4);
}
// callback function for channel 1
void callback_B()
{
pulse = 0;
Serial1.println("Callback B");
digitalWriteFast(6,LOW);
}
void event()
{
pulse = 1;
}
void setup()
{
pinMode(6, OUTPUT);
pinMode(trigger, INPUT_PULLUP);
Serial1.begin(115200,SERIAL_8N1);
Serial1.println("Timer Debug: ");
TeensyDelay::begin();
TeensyDelay::addDelayChannel(callback_A,0); //setup channel 0
TeensyDelay::addDelayChannel(callback_B,4); //setup channel 1
attachInterrupt(digitalPinToInterrupt(trigger), event, FALLING);
}
void loop()
{
if(pulse)
{
//Serial1.println("Main Loop: ");
TeensyDelay::trigger(10,0);
}
//delay(100);
}
###### Working Code ######
#include "TeensyDelay.h"
// Trigger pin
int trigger = 11;
// callback function for channel 0
void callback_A()
{
Serial1.println("Callback A");
digitalWriteFast(6,HIGH);
TeensyDelay::trigger(500,4);
}
// callback function for channel 1
void callback_B()
{
Serial1.println("Callback B");
digitalWriteFast(6,LOW);
}
void event()
{
TeensyDelay::trigger(10,0);
}
void setup()
{
pinMode(6, OUTPUT);
pinMode(trigger, INPUT_PULLUP);
Serial1.begin(115200,SERIAL_8N1);
Serial1.println("Timer Debug: ");
TeensyDelay::begin();
TeensyDelay::addDelayChannel(callback_A,0); //setup channel 0
TeensyDelay::addDelayChannel(callback_B,4); //setup channel 1
attachInterrupt(digitalPinToInterrupt(trigger), event, FALLING);
}
void loop()
{
}
Scope working
Scope not working