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.
Fork of FastPWM by
FastPWM_LPC_SCT.cpp
00001 //For targets which use the SCT 00002 #if defined(TARGET_LPC81X) || defined(TARGET_LPC82X) 00003 00004 #ifdef TARGET_LPC82X 00005 #define CTRL_U CTRL 00006 #endif 00007 00008 #include "FastPWM.h" 00009 00010 void FastPWM::initFastPWM( void ) { 00011 //Mbed uses the timer as a single unified 32-bit timer, who are we to argue with this, and it is easier 00012 bits = 32; 00013 00014 #ifdef TARGET_LPC82X 00015 //The mbed lib uses the PWM peripheral slightly different, which is irritating. This sets it bck to the LPC81X 00016 _pwm.pwm->EVENT[_pwm.pwm_ch + 1].CTRL = (1 << 12) | (_pwm.pwm_ch + 1); // Event_n on Match_n 00017 _pwm.pwm->EVENT[_pwm.pwm_ch + 1].STATE = 0xFFFFFFFF; // All states 00018 _pwm.pwm->OUT[_pwm.pwm_ch].SET = (1 << 0); // All PWM channels are SET on Event_0 00019 _pwm.pwm->OUT[_pwm.pwm_ch].CLR = (1 << (_pwm.pwm_ch + 1)); // PWM ch is CLRed on Event_(ch+1) 00020 #endif 00021 00022 //With 32-bit we fix prescaler to 1 00023 _pwm.pwm->CTRL_U |= (1 << 2) | (1 << 3); 00024 _pwm.pwm->CTRL_U &= ~(0x7F << 5); 00025 _pwm.pwm->CTRL_U &= ~(1 << 2); 00026 00027 } 00028 00029 void FastPWM::pulsewidth_ticks( uint32_t ticks ) { 00030 #ifdef TARGET_LPC81X 00031 _pwm.pwm->MATCHREL[_pwm.pwm_ch + 1].U = ticks; 00032 #else 00033 _pwm.pwm->MATCHREL[_pwm.pwm_ch + 1] = ticks; 00034 #endif 00035 } 00036 00037 void FastPWM::period_ticks( uint32_t ticks ) { 00038 #ifdef TARGET_LPC81X 00039 _pwm.pwm->MATCHREL[0].U = ticks; 00040 #else 00041 _pwm.pwm->MATCHREL[0] = ticks; 00042 #endif 00043 } 00044 00045 uint32_t FastPWM::getPeriod( void ) { 00046 #ifdef TARGET_LPC81X 00047 return _pwm.pwm->MATCHREL[0].U; 00048 #else 00049 return _pwm.pwm->MATCHREL[0]; 00050 #endif 00051 } 00052 00053 //Maybe implemented later, but needing to change the prescaler for a 32-bit 00054 //timer used in PWM mode is kinda unlikely. 00055 //If you really need to do it, rejoice, you can make it run so slow a period is over 40,000 year 00056 uint32_t FastPWM::setPrescaler(uint32_t reqScale) { 00057 //Disable dynamic prescaling 00058 dynamicPrescaler = false; 00059 00060 return 1; 00061 } 00062 00063 #endif
Generated on Tue Jul 12 2022 22:43:48 by
1.7.2
