本文整理汇总了C++中pwmout_write函数的典型用法代码示例。如果您正苦于以下问题:C++ pwmout_write函数的具体用法?C++ pwmout_write怎么用?C++ pwmout_write使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pwmout_write函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pwmout_period_us
void pwmout_period_us(pwmout_t* obj, int us)
{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
__HAL_TIM_DISABLE(&TimHandle);
TimHandle.Init.Period = us - 1;
TimHandle.Init.Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 us tick
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
error("Cannot initialize PWM");
}
// Set duty cycle again
pwmout_write(obj, dc);
// Save for future use
obj->period = us;
__HAL_TIM_ENABLE(&TimHandle);
}
示例2: pwmout_init
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC)
error("PwmOut pin mapping failed");
obj->pwm = pwm;
obj->MR = PWM_MATCH[pwm];
// ensure the power is on
LPC_SC->PCONP |= 1 << 6;
// ensure clock to /4
LPC_SC->PCLKSEL0 &= ~(0x3 << 12); // pclk = /4
LPC_PWM1->PR = 0; // no pre-scale
// ensure single PWM mode
LPC_PWM1->MCR = 1 << 1; // reset TC on match 0
// enable the specific PWM output
LPC_PWM1->PCR |= 1 << (8 + pwm);
pwm_clock_mhz = SystemCoreClock / 4000000;
// default to 20ms: standard for servos, and fine for e.g. brightness control
pwmout_period_ms(obj, 20);
pwmout_write (obj, 0);
// Wire pinout
pinmap_pinout(pin, PinMap_PWM);
}
示例3: pwmout_init
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (uint32_t)NC) {
error("PwmOut pin mapping failed");
}
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
unsigned int tpm_n = (pwm >> TPM_SHIFT);
unsigned int ch_n = (pwm & 0xFF);
SIM->SCGC5 |= 1 << (SIM_SCGC5_PORTA_SHIFT + port);
SIM->SCGC6 |= 1 << (SIM_SCGC6_TPM0_SHIFT + tpm_n);
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1); // Clock source: MCGFLLCLK or MCGPLLCLK
TPM_Type *tpm = (TPM_Type *)(TPM0_BASE + 0x1000 * tpm_n);
tpm->SC = TPM_SC_CMOD(1) | TPM_SC_PS(6); // (48)MHz / 64 = (0.75)MHz
tpm->CONTROLS[ch_n].CnSC = (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); // No Interrupts; High True pulses on Edge Aligned PWM
obj->CnV = &tpm->CONTROLS[ch_n].CnV;
obj->MOD = &tpm->MOD;
obj->CNT = &tpm->CNT;
// default to 20ms: standard for servos, and fine for e.g. brightness control
pwmout_period_ms(obj, 20);
pwmout_write(obj, 0);
// Wire pinout
pinmap_pinout(pin, PinMap_PWM);
}
示例4: pwmout_init
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (uint32_t)NC)
error("PwmOut pin mapping failed");
obj->pwm = pwm;
// Timer registers
timer_mr tid = pwm_timer_map[pwm];
LPC_TMR_TypeDef *timer = Timers[tid.timer];
// Disable timer
timer->TCR = 0;
// Power the correspondent timer
LPC_SYSCON->SYSAHBCLKCTRL |= 1 << (tid.timer + 7);
/* Enable PWM function */
timer->PWMC = (1 << 3)|(1 << 2)|(1 << 1)|(1 << 0);
/* Reset Functionality on MR3 controlling the PWM period */
timer->MCR = 1 << 10;
pwm_clock_mhz = SystemCoreClock / 1000000;
// default to 20ms: standard for servos, and fine for e.g. brightness control
pwmout_period_ms(obj, 20);
pwmout_write (obj, 0);
// Wire pinout
pinmap_pinout(pin, PinMap_PWM);
}
示例5: pwmout_period_us
void pwmout_period_us(pwmout_t* obj, int us)
{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
__HAL_TIM_DISABLE(&TimHandle);
// Update the SystemCoreClock variable
SystemCoreClockUpdate();
TimHandle.Init.Period = us - 1;
TimHandle.Init.Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
HAL_TIM_PWM_Init(&TimHandle);
// Set duty cycle again
pwmout_write(obj, dc);
// Save for future use
obj->period = us;
__HAL_TIM_ENABLE(&TimHandle);
}
示例6: pwmout_init
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
if (pwm == (PWMName)NC)
error("PwmOut pin mapping failed");
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
unsigned int ftm_n = (pwm >> TPM_SHIFT);
unsigned int ch_n = (pwm & 0xFF);
SIM->SCGC5 |= 1 << (SIM_SCGC5_PORTA_SHIFT + port);
SIM->SCGC6 |= 1 << (SIM_SCGC6_FTM0_SHIFT + ftm_n);
FTM_Type *ftm = (FTM_Type *)(FTM0_BASE + 0x1000 * ftm_n);
ftm->MODE |= FTM_MODE_WPDIS_MASK; //write protection disabled
ftm->CONF |= FTM_CONF_BDMMODE(3);
ftm->SC = FTM_SC_CLKS(1) | FTM_SC_PS(6); // (48)MHz / 64 = (0.75)MHz
ftm->CONTROLS[ch_n].CnSC = (FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK); /* No Interrupts; High True pulses on Edge Aligned PWM */
ftm->PWMLOAD |= FTM_PWMLOAD_LDOK_MASK; //loading updated values enabled
//ftm->SYNCONF |= FTM_SYNCONF_SWRSTCNT_MASK;
ftm->MODE |= FTM_MODE_INIT_MASK;
obj->CnV = &ftm->CONTROLS[ch_n].CnV;
obj->MOD = &ftm->MOD;
obj->CNT = &ftm->CNT;
obj->SYNC = &ftm->SYNC;
// default to 20ms: standard for servos, and fine for e.g. brightness control
pwmout_period_ms(obj, 20);
pwmout_write (obj, 0);
// Wire pinout
pinmap_pinout(pin, PinMap_PWM);
}
示例7: pwmout_init
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
MBED_ASSERT(pwm != (PWMName)NC);
// power on
CPGSTBCR3 &= ~(1<<0);
obj->pwm = pwm;
if (((uint32_t)PORT[obj->pwm] & 0x00000010) != 0) {
obj->ch = 2;
PWMPWPR_2_BYTE_L = 0x00;
} else {
obj->ch = 1;
PWMPWPR_1_BYTE_L = 0x00;
}
// Wire pinout
pinmap_pinout(pin, PinMap_PWM);
// default to 491us: standard for servos, and fine for e.g. brightness control
pwmout_write(obj, 0);
if ((obj->ch == 2) && (init_period_ch2 == 0)) {
pwmout_period_us(obj, 491);
init_period_ch2 = 1;
}
if ((obj->ch == 1) && (init_period_ch1 == 0)) {
pwmout_period_us(obj, 491);
init_period_ch1 = 1;
}
}
示例8: pwmout_period_us
void pwmout_period_us(pwmout_t* obj, int us)
{
float dc = pwmout_read(obj);
obj->period = us;
// Set duty cycle again
pwmout_write(obj, dc);
}
示例9: pwmout_pulsewidth_us
void pwmout_pulsewidth_us(pwmout_t *obj, int us)
{
float seconds = 0;
float value = 0;
seconds = (float)(us / 1000000.0f);
value = (((seconds / obj->period) * 100.0f) / 100.0f);
pwmout_write(obj, value);
}
示例10: pwmout_write
void AmebaServo::writeMicroseconds(int value)
{
if (value < min) value = min;
if (value > max) value = max;
currentWidth = 180 * (value - min) / (max - min);
pwmout_write( (pwmout_t *)gpio_pin_struct[servoPin], value * 1.0 / 20000);
}
示例11: pwmout_init
void pwmout_init(pwmout_t* obj, PinName pin) {
// determine the channel
PWMName pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
MBED_ASSERT(pwm != (PWMName)NC);
uint32_t clkdiv = 0;
float clkval;
#if defined(TARGET_KL43Z)
if (mcgirc_frequency()) {
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(3); // Clock source: MCGIRCLK
clkval = mcgirc_frequency() / 1000000.0f;
} else {
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1); // Clock source: IRC48M
clkval = CPU_INT_IRC_CLK_HZ / 1000000.0f;
}
#else
if (mcgpllfll_frequency()) {
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(1); // Clock source: MCGFLLCLK or MCGPLLCLK
clkval = mcgpllfll_frequency() / 1000000.0f;
} else {
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(2); // Clock source: ExtOsc
clkval = extosc_frequency() / 1000000.0f;
}
#endif
while (clkval > 1) {
clkdiv++;
clkval /= 2.0;
if (clkdiv == 7)
break;
}
pwm_clock = clkval;
unsigned int port = (unsigned int)pin >> PORT_SHIFT;
unsigned int tpm_n = (pwm >> TPM_SHIFT);
unsigned int ch_n = (pwm & 0xFF);
SIM->SCGC5 |= 1 << (SIM_SCGC5_PORTA_SHIFT + port);
SIM->SCGC6 |= 1 << (SIM_SCGC6_TPM0_SHIFT + tpm_n);
TPM_Type *tpm = (TPM_Type *)(TPM0_BASE + 0x1000 * tpm_n);
tpm->SC = TPM_SC_CMOD(1) | TPM_SC_PS(clkdiv); // (clock)MHz / clkdiv ~= (0.75)MHz
tpm->CONTROLS[ch_n].CnSC = (TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK); /* No Interrupts; High True pulses on Edge Aligned PWM */
obj->CnV = &tpm->CONTROLS[ch_n].CnV;
obj->MOD = &tpm->MOD;
obj->CNT = &tpm->CNT;
// default to 20ms: standard for servos, and fine for e.g. brightness control
pwmout_period_ms(obj, 20);
pwmout_write (obj, 0);
// Wire pinout
pinmap_pinout(pin, PinMap_PWM);
}
示例12: pwmout_free
void pwmout_free(pwmout_t *obj)
{
// Stops and clear count operation
TMRB_SetRunState(obj->channel, TMRB_STOP);
pwmout_write(obj,0);
obj->pin = NC;
obj->channel = NULL;
obj->trailing_timing = 0;
obj->leading_timing = 0;
obj->divisor = 0;
}
示例13: pwmout_pulsewidth_us
void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
float value = 0;
if (obj->ch == 2) {
if (period_ch2 != 0) {
value = (float)us / (float)period_ch2;
}
} else {
if (period_ch1 != 0) {
value = (float)us / (float)period_ch1;
}
}
pwmout_write(obj, value);
}
示例14: main
//int main_app(IN u16 argc, IN u8 *argv[])
void main(void)
{
int i;
for (i=0; i<4; i++) {
pwmout_init(&pwm_led[i], pwm_led_pin[i]);
pwmout_period_us(&pwm_led[i], PWM_PERIOD);
}
while (1) {
#if USE_FLOAT
for (i=0; i<4; i++) {
pwmout_write(&pwm_led[i], pwms[i]);
pwms[i] += steps[i];
if (pwms[i] >= 1.0) {
steps[i] = -PWM_STEP;
pwms[i] = 1.0;
}
if (pwms[i] <= 0.0) {
steps[i] = PWM_STEP;
pwms[i] = 0.0;
}
}
#else
for (i=0; i<4; i++) {
pwmout_pulsewidth_us(&pwm_led[i], pwms[i]);
pwms[i] += steps[i];
if (pwms[i] >= PWM_PERIOD) {
steps[i] = -PWM_STEP;
pwms[i] = PWM_PERIOD;
}
if (pwms[i] <= 0) {
steps[i] = PWM_STEP;
pwms[i] = 0;
}
}
#endif
// wait_ms(20);
// RtlMsleepOS(25);
pwm_delay();
}
}
示例15: pwmout_period_us
void pwmout_period_us(pwmout_t* obj, int us)
{
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
float dc = pwmout_read(obj);
__HAL_TIM_DISABLE(&TimHandle);
SystemCoreClockUpdate();
/* To make it simple, we use to possible prescaler values which lead to:
* pwm unit = 1us, period/pulse can be from 1us to 65535us
* or
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
* Be careful that all the channels of a PWM shares the same prescaler
*/
if (us > 0xFFFF) {
obj->prescaler = 500;
} else {
obj->prescaler = 1;
}
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
if (TimHandle.Init.Prescaler > 0xFFFF)
error("PWM: out of range prescaler");
TimHandle.Init.Period = (us - 1) / obj->prescaler;
if (TimHandle.Init.Period > 0xFFFF)
error("PWM: out of range period");
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
error("Cannot initialize PWM\n");
}
// Save for future use
obj->period = us;
// Set duty cycle again
pwmout_write(obj, dc);
__HAL_TIM_ENABLE(&TimHandle);
}