void
PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut,
uint32_t ui32Width)
{
uint32_t ui32GenBase, ui32Reg;
PWMPulseWidthSet(uint32_t ui32Base, uint32_t ui32PWMOut,
uint32_t ui32Width)
{
uint32_t ui32GenBase, ui32Reg;
//
// Check the arguments.
//
ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
ASSERT(_PWMOutValid(ui32PWMOut));
// Check the arguments.
//
ASSERT((ui32Base == PWM0_BASE) || (ui32Base == PWM1_BASE));
ASSERT(_PWMOutValid(ui32PWMOut));
//
// Compute the generator's base address.
//
ui32GenBase = PWM_OUT_BADDR(ui32Base, ui32PWMOut);
// Compute the generator's base address.
//
ui32GenBase = PWM_OUT_BADDR(ui32Base, ui32PWMOut);
//
// If the counter is in up/down count mode, divide the width by two.
//
if(HWREG(ui32GenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
{
ui32Width /= 2;
}
// If the counter is in up/down count mode, divide the width by two.
//
if(HWREG(ui32GenBase + PWM_O_X_CTL) & PWM_X_CTL_MODE)
{
ui32Width /= 2;
}
//
// Get the period.
//
ui32Reg = HWREG(ui32GenBase + PWM_O_X_LOAD);
// Get the period.
//
ui32Reg = HWREG(ui32GenBase + PWM_O_X_LOAD);
//
// Make sure the width is not too large.
//
ASSERT(ui32Width < ui32Reg);
// Make sure the width is not too large.
//
ASSERT(ui32Width < ui32Reg);
//
// Compute the compare value.
//
ui32Reg = ui32Reg – ui32Width;
// Compute the compare value.
//
ui32Reg = ui32Reg – ui32Width;
//
// Write to the appropriate registers.
//
if(PWM_IS_OUTPUT_ODD(ui32PWMOut))
{
HWREG(ui32GenBase + PWM_O_X_CMPB) = ui32Reg;
}
else
{
HWREG(ui32GenBase + PWM_O_X_CMPA) = ui32Reg;
}
}
// Write to the appropriate registers.
//
if(PWM_IS_OUTPUT_ODD(ui32PWMOut))
{
HWREG(ui32GenBase + PWM_O_X_CMPB) = ui32Reg;
}
else
{
HWREG(ui32GenBase + PWM_O_X_CMPA) = ui32Reg;
}
}
Susan Yang:
请问您现在使用的是什么芯片呢?
user5362661:
回复 Susan Yang:
不好意思,是tm4c123gh6pm
xyz549040622:
老实说,我都不会太关注这些底层的东西,除非真的是程序调不通了。