FASTPWM
Device/FastPWM_LPC_SCT.cpp@29:3e4d3b900850, 2016-03-13 (annotated)
- Committer:
- Sissors
- Date:
- Sun Mar 13 11:43:18 2016 +0000
- Revision:
- 29:3e4d3b900850
- Child:
- 30:87e38b846651
Added LPC81x/LPC82x support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 29:3e4d3b900850 | 1 | //For targets which use the SCT |
Sissors | 29:3e4d3b900850 | 2 | #if defined(TARGET_LPC81X) || defined(TARGET_LPC82X) |
Sissors | 29:3e4d3b900850 | 3 | |
Sissors | 29:3e4d3b900850 | 4 | #ifdef TARGET_LPC82X |
Sissors | 29:3e4d3b900850 | 5 | #define CTRL_U CTRL |
Sissors | 29:3e4d3b900850 | 6 | #endif |
Sissors | 29:3e4d3b900850 | 7 | |
Sissors | 29:3e4d3b900850 | 8 | #include "FastPWM.h" |
Sissors | 29:3e4d3b900850 | 9 | |
Sissors | 29:3e4d3b900850 | 10 | void FastPWM::initFastPWM( void ) { |
Sissors | 29:3e4d3b900850 | 11 | //Mbed uses the timer as a single unified 32-bit timer, who are we to argue with this, and it is easier |
Sissors | 29:3e4d3b900850 | 12 | bits = 32; |
Sissors | 29:3e4d3b900850 | 13 | |
Sissors | 29:3e4d3b900850 | 14 | //With 32-bit we fix prescaler to 1 |
Sissors | 29:3e4d3b900850 | 15 | _pwm.pwm->CTRL_U |= (1 << 2) | (1 << 3); |
Sissors | 29:3e4d3b900850 | 16 | _pwm.pwm->CTRL_U &= ~(0x7F << 5); |
Sissors | 29:3e4d3b900850 | 17 | _pwm.pwm->CTRL_U &= ~(1 << 2); |
Sissors | 29:3e4d3b900850 | 18 | |
Sissors | 29:3e4d3b900850 | 19 | } |
Sissors | 29:3e4d3b900850 | 20 | |
Sissors | 29:3e4d3b900850 | 21 | void FastPWM::pulsewidth_ticks( uint32_t ticks ) { |
Sissors | 29:3e4d3b900850 | 22 | #ifdef TARGET_LPC81X |
Sissors | 29:3e4d3b900850 | 23 | _pwm.pwm->MATCHREL[_pwm.pwm_ch + 1].U = ticks; |
Sissors | 29:3e4d3b900850 | 24 | #else |
Sissors | 29:3e4d3b900850 | 25 | _pwm.pwm->MATCHREL[_pwm.pwm_ch + 1] = ticks; |
Sissors | 29:3e4d3b900850 | 26 | #endif |
Sissors | 29:3e4d3b900850 | 27 | } |
Sissors | 29:3e4d3b900850 | 28 | |
Sissors | 29:3e4d3b900850 | 29 | void FastPWM::period_ticks( uint32_t ticks ) { |
Sissors | 29:3e4d3b900850 | 30 | #ifdef TARGET_LPC81X |
Sissors | 29:3e4d3b900850 | 31 | _pwm.pwm->MATCHREL[0].U = ticks; |
Sissors | 29:3e4d3b900850 | 32 | #else |
Sissors | 29:3e4d3b900850 | 33 | _pwm.pwm->MATCHREL[0] = ticks; |
Sissors | 29:3e4d3b900850 | 34 | #endif |
Sissors | 29:3e4d3b900850 | 35 | } |
Sissors | 29:3e4d3b900850 | 36 | |
Sissors | 29:3e4d3b900850 | 37 | uint32_t FastPWM::getPeriod( void ) { |
Sissors | 29:3e4d3b900850 | 38 | #ifdef TARGET_LPC81X |
Sissors | 29:3e4d3b900850 | 39 | return _pwm.pwm->MATCHREL[0].U; |
Sissors | 29:3e4d3b900850 | 40 | #else |
Sissors | 29:3e4d3b900850 | 41 | return _pwm.pwm->MATCHREL[0]; |
Sissors | 29:3e4d3b900850 | 42 | #endif |
Sissors | 29:3e4d3b900850 | 43 | } |
Sissors | 29:3e4d3b900850 | 44 | |
Sissors | 29:3e4d3b900850 | 45 | //Maybe implemented later, but needing to change the prescaler for a 32-bit |
Sissors | 29:3e4d3b900850 | 46 | //timer used in PWM mode is kinda unlikely. |
Sissors | 29:3e4d3b900850 | 47 | //If you really need to do it, rejoice, you can make it run so slow a period is over 40,000 year |
Sissors | 29:3e4d3b900850 | 48 | uint32_t FastPWM::setPrescaler(uint32_t reqScale) { |
Sissors | 29:3e4d3b900850 | 49 | //Disable dynamic prescaling |
Sissors | 29:3e4d3b900850 | 50 | dynamicPrescaler = false; |
Sissors | 29:3e4d3b900850 | 51 | |
Sissors | 29:3e4d3b900850 | 52 | return 1; |
Sissors | 29:3e4d3b900850 | 53 | } |
Sissors | 29:3e4d3b900850 | 54 | |
Sissors | 29:3e4d3b900850 | 55 | #endif |