Potmeter FastPWM.h

Dependencies:   mbed

Committer:
vd
Date:
Tue Sep 19 16:52:01 2017 +0000
Revision:
0:16be67f4d9ac
Potmeter FastPWM.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vd 0:16be67f4d9ac 1 #ifdef TARGET_LPC176X
vd 0:16be67f4d9ac 2
vd 0:16be67f4d9ac 3 #include "FastPWM.h"
vd 0:16be67f4d9ac 4
vd 0:16be67f4d9ac 5 void FastPWM::initFastPWM( void ) {
vd 0:16be67f4d9ac 6 //Set clock source
vd 0:16be67f4d9ac 7 LPC_SC->PCLKSEL0|=1<<12;
vd 0:16be67f4d9ac 8 bits = 32;
vd 0:16be67f4d9ac 9 }
vd 0:16be67f4d9ac 10
vd 0:16be67f4d9ac 11 void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
vd 0:16be67f4d9ac 12 *(_pwm.MR) = ticks;
vd 0:16be67f4d9ac 13 LPC_PWM1->LER |= 1 << _pwm.pwm;
vd 0:16be67f4d9ac 14 }
vd 0:16be67f4d9ac 15
vd 0:16be67f4d9ac 16 void FastPWM::period_ticks( uint32_t ticks ) {
vd 0:16be67f4d9ac 17 LPC_PWM1->MR0 = ticks;
vd 0:16be67f4d9ac 18 LPC_PWM1->LER |= 1 << 0;
vd 0:16be67f4d9ac 19 }
vd 0:16be67f4d9ac 20
vd 0:16be67f4d9ac 21 uint32_t FastPWM::getPeriod( void ) {
vd 0:16be67f4d9ac 22 return LPC_PWM1->MR0;
vd 0:16be67f4d9ac 23 }
vd 0:16be67f4d9ac 24
vd 0:16be67f4d9ac 25 //Maybe implemented later, but needing to change the prescaler for a 32-bit
vd 0:16be67f4d9ac 26 //timer used in PWM mode is kinda unlikely.
vd 0:16be67f4d9ac 27 //If you really need to do it, rejoice, you can make it run so slow a period is over 40,000 year
vd 0:16be67f4d9ac 28 uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
vd 0:16be67f4d9ac 29 //Disable dynamic prescaling
vd 0:16be67f4d9ac 30 dynamicPrescaler = false;
vd 0:16be67f4d9ac 31
vd 0:16be67f4d9ac 32 return 1;
vd 0:16be67f4d9ac 33 }
vd 0:16be67f4d9ac 34 #endif