Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Berekenen_motorhoek Encoder System_Identification Motor_PID_set_parameters ... more
Fork of FastPWM by
Diff: Device/FastPWM_LPC_SCT.cpp
- Revision:
- 29:3e4d3b900850
- Child:
- 30:87e38b846651
diff -r 3c8a0d977bc3 -r 3e4d3b900850 Device/FastPWM_LPC_SCT.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Device/FastPWM_LPC_SCT.cpp Sun Mar 13 11:43:18 2016 +0000
@@ -0,0 +1,55 @@
+//For targets which use the SCT
+#if defined(TARGET_LPC81X) || defined(TARGET_LPC82X)
+
+#ifdef TARGET_LPC82X
+#define CTRL_U CTRL
+#endif
+
+#include "FastPWM.h"
+
+void FastPWM::initFastPWM( void ) {
+ //Mbed uses the timer as a single unified 32-bit timer, who are we to argue with this, and it is easier
+ bits = 32;
+
+ //With 32-bit we fix prescaler to 1
+ _pwm.pwm->CTRL_U |= (1 << 2) | (1 << 3);
+ _pwm.pwm->CTRL_U &= ~(0x7F << 5);
+ _pwm.pwm->CTRL_U &= ~(1 << 2);
+
+}
+
+void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
+ #ifdef TARGET_LPC81X
+ _pwm.pwm->MATCHREL[_pwm.pwm_ch + 1].U = ticks;
+ #else
+ _pwm.pwm->MATCHREL[_pwm.pwm_ch + 1] = ticks;
+ #endif
+}
+
+void FastPWM::period_ticks( uint32_t ticks ) {
+ #ifdef TARGET_LPC81X
+ _pwm.pwm->MATCHREL[0].U = ticks;
+ #else
+ _pwm.pwm->MATCHREL[0] = ticks;
+ #endif
+}
+
+uint32_t FastPWM::getPeriod( void ) {
+ #ifdef TARGET_LPC81X
+ return _pwm.pwm->MATCHREL[0].U;
+ #else
+ return _pwm.pwm->MATCHREL[0];
+ #endif
+}
+
+//Maybe implemented later, but needing to change the prescaler for a 32-bit
+//timer used in PWM mode is kinda unlikely.
+//If you really need to do it, rejoice, you can make it run so slow a period is over 40,000 year
+uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
+ //Disable dynamic prescaling
+ dynamicPrescaler = false;
+
+ return 1;
+}
+
+#endif
\ No newline at end of file
