Skip to content

Commit c5d323a

Browse files
committed
lib/tiam1808/drivers/ehrpwm: Add function to set period directly
1 parent 876b3f3 commit c5d323a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/tiam1808/drivers/ehrpwm.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,38 @@ void EHRPWMPWMOpFreqSet(unsigned int baseAddr,
145145
}
146146

147147

148+
/**
149+
* \brief This API configures the PWM Frequency/Period. The period count
150+
* determines the period of the final output waveform.
151+
* This function loads the precise period value specified.
152+
*
153+
* \param baseAddr Base Address of the PWM Module Registers.
154+
* \param tbPeriod Timebase period.
155+
*
156+
* \param counterDir Direction of the counter(up, down, up-down)
157+
* \param enableShadowWrite Whether write to Period register is to be shadowed
158+
*
159+
* \return None.
160+
*
161+
**/
162+
void EHRPWMPWMOpPeriodSet(unsigned int baseAddr,
163+
unsigned int tbPeriod,
164+
unsigned int counterDir,
165+
bool enableShadowWrite)
166+
{
167+
HWREGH(baseAddr + EHRPWM_TBCTL) = (HWREGH(baseAddr + EHRPWM_TBCTL) &
168+
(~EHRPWM_PRD_LOAD_SHADOW_MASK)) | ((enableShadowWrite <<
169+
EHRPWM_TBCTL_PRDLD_SHIFT) & EHRPWM_PRD_LOAD_SHADOW_MASK);
170+
171+
HWREGH(baseAddr + EHRPWM_TBCTL) = (HWREGH(baseAddr + EHRPWM_TBCTL) &
172+
(~EHRPWM_COUNTER_MODE_MASK)) | ((counterDir <<
173+
EHRPWM_TBCTL_CTRMODE_SHIFT) & EHRPWM_COUNTER_MODE_MASK);
174+
175+
HWREGH(baseAddr + EHRPWM_TBPRD) = (unsigned short)tbPeriod;
176+
177+
}
178+
179+
148180
/**
149181
* \brief This API configures emulation mode. This setting determines
150182
* the behaviour of Timebase during emulation (debugging).

lib/tiam1808/tiam1808/ehrpwm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ void EHRPWMTimebaseClkConfig(unsigned int baseAddr, unsigned int tbClk,
172172
void EHRPWMPWMOpFreqSet(unsigned int baseAddr, unsigned int tbClk,
173173
unsigned int pwmFreq,unsigned int counterDir,
174174
bool enableShadowWrite);
175+
void EHRPWMPWMOpPeriodSet(unsigned int baseAddr, unsigned int tbPeriod,
176+
unsigned int counterDir,
177+
bool enableShadowWrite);
175178
void EHRPWMTBEmulationModeSet(unsigned int baseAddr, unsigned int mode);
176179
void EHRPWMTimebaseSyncEnable(unsigned int baseAddr, unsigned int tbPhsValue,
177180
unsigned int phsCountDir);

0 commit comments

Comments
 (0)