FASTPWM

Dependents:   OV7670_make

Committer:
Sissors
Date:
Sun Mar 13 11:43:18 2016 +0000
Revision:
29:3e4d3b900850
Parent:
4:a7b9f778c4b4
Added LPC81x/LPC82x support

Who changed what in which revision?

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