Hi Paul/All,
I've been playing around with what was suggested in another forum topic here to enable/disable the slew rate on digital pins of a Teensy 3.6 and I can easily do this in a sketch by simply changing the SRE bit in the port configuration register after my call to pinMode as shown here to enable/disable the feature:
I'm doing this on pin 13 as a test since I want to try and implement the same when using this pin as the SCLK line for my SPI1 bus to a TFT. When I setup the sketch as noted above, I can clearly see the effect of this on my oscilloscope (200MHz). With slew rate turned off there is significant over/under shoot on the PWM signal, whereas when slew rate is enabled, this practically disappears (similar to what Paul and others have shown in the links above).
Now I come to my problem, I'm getting some significant EMI issues from my setup when communicating with an FT813 display over SPI due to ringing / higher order harmonics from this over/undershoot with the PWM signal on SCLK and MOSI lines. So, since the sketch above was so successful in reducing (almost eliminating it), I'm trying to do the same when the pin is setup in SPI1 mode (I'm happy to reduce SPI freq a bit if needed as a result). Searching through the core I found how the SPI1 pin setup procedure differs from the normal pinMode() setup procedure, I believe the SPI setup is described in the SPCR1.enable_pins() function of avr_emulation.h (correct?). I don't see any calls to enable slew rate in the code while these pins are being initialized for SPI operation, so I tried adding similar code to that above after calling SPI.begin(), however the pins appear to be operating with slew rate disabled regardless of whether my code tries to enable it or not. I also tried editing the core library to enable the SRE bit during pin configuration but that had no effect either so returned the core to its original state.
I did some searching on the K66 manual to see if I could find more information on it and it looked like it's possible there might be an issue using it while SPI mode is active (possibly due to the K66 using other elements of its internal hardware??). So my question is, do you know if can slew rate can be enabled when SPI1 mode is active? Any help or advice on how to enable it or even to tell me it isn't possible would be greatly appreciated.
Thanks.
I've been playing around with what was suggested in another forum topic here to enable/disable the slew rate on digital pins of a Teensy 3.6 and I can easily do this in a sketch by simply changing the SRE bit in the port configuration register after my call to pinMode as shown here to enable/disable the feature:
Code:
void setup(){
uint8_t pin = 13;
pinMode(pin, OUTPUT);
volatile uint32_t* config = portConfigRegister(pin); // setup pointer
*config |= PORT_PCR_SRE; // disable slew rate
// or to disable slew rate use the following line instead
//*config &= ~PORT_PCR_SRE; // disable slew rate
bool pulse = true;
while (true) {
if (pulse) digitalWriteFast(pin, HIGH);
else digitalWriteFast(pin, LOW);
pulse = !pulse;
}
}
void loop(){
// never reached
}
I'm doing this on pin 13 as a test since I want to try and implement the same when using this pin as the SCLK line for my SPI1 bus to a TFT. When I setup the sketch as noted above, I can clearly see the effect of this on my oscilloscope (200MHz). With slew rate turned off there is significant over/under shoot on the PWM signal, whereas when slew rate is enabled, this practically disappears (similar to what Paul and others have shown in the links above).
Now I come to my problem, I'm getting some significant EMI issues from my setup when communicating with an FT813 display over SPI due to ringing / higher order harmonics from this over/undershoot with the PWM signal on SCLK and MOSI lines. So, since the sketch above was so successful in reducing (almost eliminating it), I'm trying to do the same when the pin is setup in SPI1 mode (I'm happy to reduce SPI freq a bit if needed as a result). Searching through the core I found how the SPI1 pin setup procedure differs from the normal pinMode() setup procedure, I believe the SPI setup is described in the SPCR1.enable_pins() function of avr_emulation.h (correct?). I don't see any calls to enable slew rate in the code while these pins are being initialized for SPI operation, so I tried adding similar code to that above after calling SPI.begin(), however the pins appear to be operating with slew rate disabled regardless of whether my code tries to enable it or not. I also tried editing the core library to enable the SRE bit during pin configuration but that had no effect either so returned the core to its original state.
I did some searching on the K66 manual to see if I could find more information on it and it looked like it's possible there might be an issue using it while SPI mode is active (possibly due to the K66 using other elements of its internal hardware??). So my question is, do you know if can slew rate can be enabled when SPI1 mode is active? Any help or advice on how to enable it or even to tell me it isn't possible would be greatly appreciated.
Thanks.