Created
February 24, 2021 04:21
-
-
Save raspberrypisig/a18cf29a6046f3ea100b088cc5a5d2c6 to your computer and use it in GitHub Desktop.
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
#include "Adafruit_ZeroTimer.h" | |
// Adafruit Zerotimer library uses A5(PB9) as waveform output for TC4 Channel 1 | |
// Wio Terminal uses D1 | |
// This can be seen here: | |
// https://github.com/Seeed-Studio/ArduinoCore-samd/blob/bcc92a8edfd324989e41080bb3521ddfbee4dc2e/variants/wio_terminal/variant.cpp#L31 | |
// So need to replace A5 with D1 here: | |
// https://github.com/adafruit/Adafruit_ZeroTimer/blob/e8e9eb3556326eea3ff3a28266d578c971d2d4d0/Adafruit_ZeroTimer.cpp#L337 | |
Adafruit_ZeroTimer zt4 = Adafruit_ZeroTimer(4); | |
void setup() { | |
Serial.begin(115200); | |
//delay(10000); | |
pinMode(D1, OUTPUT); | |
zt4.enable(false); | |
zt4.configure(TC_CLOCK_PRESCALER_DIV1, // prescaler | |
TC_COUNTER_SIZE_16BIT, // bit width of timer/counter | |
TC_WAVE_GENERATION_MATCH_PWM // frequency or PWM mode | |
); | |
if (! zt4.PWMout(true, 1, D1)) { | |
Serial.println("Failed to configure PWM output"); | |
} | |
else { | |
Serial.println("PWM output configured"); | |
} | |
// 10kHz 50% duty cycle square wave | |
zt4.setPeriodMatch(4799, 4799/2, 1); | |
zt4.enable(true); | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment