GwakSeongJong
Member
Teensy 4.1 digitalWrite, digitalWriteFast Problem
[Environment]
1. I want to create a 2MHz clock.
2. The signals of 'CLOCK_H' and 'CLOCK_L' are inverted.
[Problem]
1. The waveform is broken.
What is the reason?
Green Waveform: CLOCK_H ~ CLOCK_L Voltage
Teensy4.1 seems to have a digitalWriteFast, digitalWrite problem.
Is there a solution?
[Environment]
1. I want to create a 2MHz clock.
2. The signals of 'CLOCK_H' and 'CLOCK_L' are inverted.
[Problem]
1. The waveform is broken.
What is the reason?
Green Waveform: CLOCK_H ~ CLOCK_L Voltage
Code:
#define CLOCK_H 1
#define CLOCK_L 2
volatile long TIMER_CLOCK1 = 0;
const volatile long PERIOD_1 = 100;
long delay_value_ns1=180;
long delay_value_ns2=180;
void setup() {
pinMode(CLOCK_H,OUTPUT); pinMode(CLOCK_L,OUTPUT);
Serial.begin(115200);
digitalWriteFast(CLOCK_H, LOW); digitalWriteFast(CLOCK_L, HIGH);
}
void loop() {
if(TIMER_CLOCK1 < millis()){
TIMER_CLOCK1 = millis() + PERIOD_1;
boolean f1 = true;
for (int i = 0; i <28; i++) {
if(f1){
digitalWriteFast(CLOCK_H, HIGH); digitalWriteFast(CLOCK_L, LOW);
f1=false;
delayNanoseconds(delay_value_ns1);
}else{
digitalWriteFast(CLOCK_H, LOW); digitalWriteFast(CLOCK_L, HIGH);
f1=true;
delayNanoseconds(delay_value_ns2);
}
}
digitalWriteFast(CLOCK_H, LOW); digitalWriteFast(CLOCK_L, HIGH);
}
}
Teensy4.1 seems to have a digitalWriteFast, digitalWrite problem.
Is there a solution?