Skip to content

Commit c9f315b

Browse files
committed
Set PWM frequency to 732.4Hz
1 parent f221d1f commit c9f315b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CHANGELOG

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SAMD CORE
44
* Added snprintf_P to avr/pgmspace.h stub. Thanks @jantje
55
* Another small fix to String iterators. Thanks @Ivan-Perez @Chris--A
66
* Fixed glitch in PWM generation that may happen when calling analogWrite()
7+
* PWM frequency is now 732.4Hz (before it was 187500.0Hz)
78

89
SAMD CORE 1.6.6 2016.05.19
910

cores/arduino/wiring_analog.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ void analogWrite(uint32_t pin, uint32_t value)
256256
// Disable TCx
257257
TCx->COUNT8.CTRLA.bit.ENABLE = 0;
258258
syncTC_8(TCx);
259-
// Set Timer counter Mode to 8 bits, normal PWM
260-
TCx->COUNT8.CTRLA.reg |= TC_CTRLA_MODE_COUNT8 | TC_CTRLA_WAVEGEN_NPWM;
259+
// Set Timer counter Mode to 8 bits, normal PWM, prescaler 1/256
260+
TCx->COUNT8.CTRLA.reg |= TC_CTRLA_MODE_COUNT8 | TC_CTRLA_WAVEGEN_NPWM | TC_CTRLA_PRESCALER_DIV256;
261261
syncTC_8(TCx);
262262
// Set the initial value
263263
TCx->COUNT8.CC[tcChannel].reg = (uint8_t) value;
@@ -274,6 +274,9 @@ void analogWrite(uint32_t pin, uint32_t value)
274274
// Disable TCCx
275275
TCCx->CTRLA.bit.ENABLE = 0;
276276
syncTCC(TCCx);
277+
// Set prescaler to 1/256
278+
TCCx->CTRLA.reg |= TCC_CTRLA_PRESCALER_DIV256;
279+
syncTCC(TCCx);
277280
// Set TCx as normal PWM
278281
TCCx->WAVE.reg |= TCC_WAVE_WAVEGEN_NPWM;
279282
syncTCC(TCCx);

0 commit comments

Comments
 (0)