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: qonly_controller foc-ed_in_the_bot_compact foc-ed_in_the_bot_compact CurrentModeSine ... more
Fork of FastPWM by
Revision 3:3094d3806cfc, committed 2012-07-25
- Comitter:
- Sissors
- Date:
- Wed Jul 25 07:14:39 2012 +0000
- Parent:
- 2:4b8de6ae5885
- Child:
- 4:a7b9f778c4b4
- Commit message:
- Fixed clk_sel, latch registers and constant duty when changing period
Changed in this revision
| FastPWM.cpp | Show annotated file Show diff for this revision Revisions of this file |
| FastPWM.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/FastPWM.cpp Thu Jul 12 19:26:43 2012 +0000
+++ b/FastPWM.cpp Wed Jul 25 07:14:39 2012 +0000
@@ -1,20 +1,35 @@
#include "FastPWM.h"
FastPWM::FastPWM(PinName pin) : PWMObject(pin){
+ //Set clock source
+ LPC_SC->PCLKSEL0|=1<<12;
+
_duty=0;
_period=0.02;
- if (pin==p26||pin==LED1)
+ if (pin==p26||pin==LED1) {
+ PWMUnit=1;
MR=&LPC_PWM1->MR1;
- else if (pin==p25||pin==LED2)
+ }
+ else if (pin==p25||pin==LED2){
+ PWMUnit=2;
MR=&LPC_PWM1->MR2;
- else if (pin==p24||pin==LED3)
+ }
+ else if (pin==p24||pin==LED3){
+ PWMUnit=3;
MR=&LPC_PWM1->MR3;
- else if (pin==p23||pin==LED4)
+ }
+ else if (pin==p23||pin==LED4){
+ PWMUnit=4;
MR=&LPC_PWM1->MR4;
- else if (pin==p22)
+ }
+ else if (pin==p22){
+ PWMUnit=5;
MR=&LPC_PWM1->MR5;
- else if (pin==p21)
+ }
+ else if (pin==p21){
+ PWMUnit=6;
MR=&LPC_PWM1->MR6;
+ }
else
error("No hardware PWM pin\n\r");
@@ -23,8 +38,9 @@
void FastPWM::period(double seconds) {
LPC_PWM1->MR0 = (unsigned int) (seconds * (double)F_CLK);
- pulsewidth(_duty*seconds);
+ LPC_PWM1->LER |= 1;
_period = seconds;
+ pulsewidth(_duty*_period);
}
void FastPWM::period_ms(int ms) {
@@ -41,6 +57,8 @@
void FastPWM::pulsewidth(double seconds) {
*MR=(unsigned int) (seconds * (double)F_CLK);
+ LPC_PWM1->LER |= 1<<PWMUnit;
+ _duty=seconds/_period;
}
void FastPWM::pulsewidth_ms(int ms) {
--- a/FastPWM.h Thu Jul 12 19:26:43 2012 +0000
+++ b/FastPWM.h Wed Jul 25 07:14:39 2012 +0000
@@ -115,6 +115,7 @@
PwmOut PWMObject;
double _duty;
double _period;
+ unsigned int PWMUnit;
__IO uint32_t *MR;
