Until reading this, I didn't realize the pins were configured to be slow. I went into C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 and changed two files, core_pins.h and pins_teensy.c as a rude hack to add:
Code:
void pinModeFast(uint8_t pin, uint8_t mode); // for high drive strength (fast slew rate)
void pinModeFast(uint8_t pin, uint8_t mode)
{
volatile uint32_t *config;
if (pin >= CORE_NUM_DIGITAL) return;
config = portConfigRegister(pin);
if (mode == OUTPUT) {
#ifdef KINETISK
*portModeRegister(pin) = 1;
#else
*portModeRegister(pin) |= digitalPinToBitMask(pin); // TODO: atomic
#endif
*config = PORT_PCR_DSE | PORT_PCR_MUX(1); // SRE bit = 0 for fast slew rate
} else {
#ifdef KINETISK
*portModeRegister(pin) = 0;
#else
*portModeRegister(pin) &= ~digitalPinToBitMask(pin);
#endif
if (mode == INPUT) {
*config = PORT_PCR_MUX(1);
} else {
*config = PORT_PCR_MUX(1) | PORT_PCR_PE | PORT_PCR_PS; // pullup
}
}
}
and tried this code:
Code:
const int LED1 = 0; // output pin
void setup() {
pinModeFast(LED1, OUTPUT); // high slew rate setting
}
void loop() {
digitalWriteFast(LED1, HIGH);
delayMicroseconds(10);
digitalWriteFast(LED1, LOW);
delayMicroseconds(10);
}
Previously, when using the normal pinMode() call I got 7 ns risetime. With the high slew rate enabled I get sub-nanosecond risetimes, maybe around 0.85 ns but my 500 MHz scope/probe is not accurate at those levels. At any rate, it is quite a difference.
"Before" (default slew rate)
"After" (fast slew rate)
short ground wire probe