本文整理汇总了C++中TIM_SetCompare2函数的典型用法代码示例。如果您正苦于以下问题:C++ TIM_SetCompare2函数的具体用法?C++ TIM_SetCompare2怎么用?C++ TIM_SetCompare2使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIM_SetCompare2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Motion_Control
void Motion_Control(void)
{
if(PID_main_Speed.Out > 35) //主机方向控制
{
Moter_main_forward;
TIM_SetCompare1(TIM4,PID_main_Speed.Out);
}
else if(PID_main_Speed.Out < -35)
{
Moter_main_back;
TIM_SetCompare1(TIM4,-PID_main_Speed.Out);
}
else
{
Moter_main_stop;
TIM_SetCompare1(TIM4,0);
}
if(PID_101_Speed.Out > 35) //从机101放向控制
{
Moter_101_forward;
TIM_SetCompare2(TIM4,PID_101_Speed.Out);
}
else if(PID_101_Speed.Out < -35)
{
Moter_101_back;
TIM_SetCompare2(TIM4,-PID_101_Speed.Out);
}
else
{
Moter_101_stop;
TIM_SetCompare2(TIM4,0);
}
}
示例2: SWService2
// @brief : Called from TIM5_IRQHandler, whenever TIM5 CH1 generates an interrupt
// or TIM5 generates an update. This function serves two purposes. Firstly,
// it will be used to debounce the switch after it is pressed or released
// (interrupt). Secondly, it is used to notify the user of the maximum hold
// time (update). This is part 2 of the switch service routine.
// @param : none
// @retval: none
void SWService2 (void) {
if (TIM_GetITStatus(TIM_SWITCH, TIM_IT_CC1) != RESET) {
TIM_ClearITPendingBit(TIM_SWITCH, TIM_IT_CC1);
if (SWstate == SW_DEBOUNCE_HIGH) { // previous state is debounce_high.
if (USER_SW) { // SW debounced and remained high (PRESSED / HELD)
SWstate = SW_HIGH;
SWstatus = SW_PRESS;
TIM_SetCompare2(TIM_SWITCH, sw_hold_time[SWstatus]);
bSWFlag = TRUE;
}
else { // SW debounced and went low (RELEASED)
SWstate = SW_DEBOUNCE_LOW;
TIM_SetCounter(TIM_SWITCH, 0); // TIM5->CNT = 0;
}
}
else if (SWstate == SW_DEBOUNCE_LOW) { // previous state is debounce_low
SWstate = SW_LOW;
TIM_Cmd(TIM_SWITCH, DISABLE); // Disabling timer DOESN'T reset the counter
TIM_SetCounter(TIM_SWITCH, 0);
}
}
else if (TIM_GetITStatus(TIM_SWITCH, TIM_IT_CC2) != RESET) {
TIM_ClearITPendingBit(TIM_SWITCH, TIM_IT_CC2);
SWstatus++;
TIM_SetCompare2(TIM_SWITCH, sw_hold_time[SWstatus]);
DispBlink();
}
}
示例3: loop
void loop(void) {
int32_t data[3];
LIS302DL_ReadACC(data);
int32_t x = cround(data[0], 300)/5;
int32_t y = cround(data[1], 300)/5;
TIM_SetCompare1(TIM4, 0);
TIM_SetCompare2(TIM4, 0);
TIM_SetCompare3(TIM4, 0);
TIM_SetCompare4(TIM4, 0);
if ( x > 0 ) {
TIM_SetCompare2(TIM4, x);
}
else {
TIM_SetCompare4(TIM4, -x);
}
if ( y > 0 ) {
TIM_SetCompare1(TIM4, y);
}
else {
TIM_SetCompare3(TIM4, -y);
}
delay(10);
}
示例4: batholithResetPwm
void batholithResetPwm(){
TIM_SetCompare2(TIM8,0);
TIM_SetCompare3(TIM8,0);
TIM_SetCompare2(TIM1,0);
TIM_SetCompare1(TIM1,0);
me.isPWMallowed=0;
}
示例5: setLeftMotor
/* ---------------------------------------------------------------------------*/
void setLeftMotor(int32_t m_speed){
if(m_speed >= 0){
TIM_SetCompare1(TIM4, m_speed);
TIM_SetCompare2(TIM4, 0);
}else{
TIM_SetCompare1(TIM4, 0);
TIM_SetCompare2(TIM4, -m_speed);
}
}
示例6: MOTORS_RMS
void MOTORS_RMS(uint8_t speed) {
if (speed >= 50) {
TIM_SetCompare2(TIM3, (speed-50) * 20);
GPIO_SetBits(GPIOB, GPIO_Pin_8);
GPIO_ResetBits(GPIOB, GPIO_Pin_9);
} else {
TIM_SetCompare2(TIM3, speed * 20);
GPIO_ResetBits(GPIOB, GPIO_Pin_8);
GPIO_SetBits(GPIOB, GPIO_Pin_9);
}
}
示例7: Holder_ChangePulse
void Holder_ChangePulse()
{
switch (holder_state)
{
case HOLDER_STATE_TURNUP:
if (holder_v_pulse + holder_pulse_step > HOLDER_V_PULSE_MAX)
{
holder_v_pulse = HOLDER_V_PULSE_MAX;
}
else
{
holder_v_pulse += holder_pulse_step;
}
TIM_SetCompare1(HOLDER_TIM, holder_v_pulse);
break;
case HOLDER_STATE_TURNDOWN:
if (holder_v_pulse - holder_pulse_step < HOLDER_V_PULSE_MIN)
{
holder_v_pulse = HOLDER_V_PULSE_MIN;
}
else
{
holder_v_pulse -= holder_pulse_step;
}
TIM_SetCompare1(HOLDER_TIM, holder_v_pulse);
break;
case HOLDER_STATE_TURNLEFT:
if (holder_h_pulse + holder_pulse_step > HOLDER_H_PULSE_MAX)
{
holder_h_pulse = HOLDER_H_PULSE_MAX;
}
else
{
holder_h_pulse += holder_pulse_step;
}
TIM_SetCompare2(HOLDER_TIM, holder_h_pulse);
break;
case HOLDER_STATE_TURNRIGHT:
if (holder_h_pulse - holder_pulse_step < HOLDER_H_PULSE_MIN)
{
holder_h_pulse = HOLDER_H_PULSE_MIN;
}
else
{
holder_h_pulse -= holder_pulse_step;
}
TIM_SetCompare2(HOLDER_TIM, holder_h_pulse);
break;
default:
break;
}
}
示例8: turn_to_left
/************************************************************************************************
* 函数名:turn_to_left
* 函数作用:控制小车右转
* 参数:yscs (预设次数) 预设光电传感器输出方波的次数 pwm_x 时分别给左右两个电机输出不同占空比的pwm波
* 库版本 :ST3.5.0
*************************************************************************************************/
void turn_to_left( u16 pwm_1 , u16 pwm_2,u16 yanshi )
{
//yushe_cishu=yscs;
TIM_SetCompare1(TIM4,pwm_1);//设置电机的初始pwn波 1、2是控制右侧的电机,3、4控制左侧的电机。1、3是前进,2、4是后退。
TIM_SetCompare2(TIM4,0);
TIM_SetCompare3(TIM4,0);
TIM_SetCompare4(TIM4,pwm_2);
delay_ms(yanshi);//根据实际情况更改
TIM_SetCompare1(TIM4,0);//设置电机的初始pwn波 1、2是控制右侧的电机,3、4控制左侧的电机。1、3是前进,2、4是后退。
TIM_SetCompare2(TIM4,0);
TIM_SetCompare3(TIM4,0);
TIM_SetCompare4(TIM4,0);
}
示例9: l_actuators_pwm_commit
/* set pulse widths from actuator values, assumed to be in us */
void l_actuators_pwm_commit(void) {
TIM_SetCompare1(TIM3, actuators_pwm_values[0]);
TIM_SetCompare2(TIM3, actuators_pwm_values[1]);
TIM_SetCompare3(TIM3, actuators_pwm_values[2]);
TIM_SetCompare4(TIM3, actuators_pwm_values[3]);
TIM_SETCOMPARE(PWM5_OC)(PWM_5AND6_TIMER, actuators_pwm_values[4]);
TIM_SETCOMPARE(PWM6_OC)(PWM_5AND6_TIMER, actuators_pwm_values[5]);
#ifdef USE_SERVOS_7AND8
TIM_SetCompare1(TIM4, actuators_pwm_values[6]);
TIM_SetCompare2(TIM4, actuators_pwm_values[7]);
#endif
}
示例10: PWM_Set
void PWM_Set(int moto1, int moto2, int moto3, int moto4)
{
PWM_Init(GPIO_Pin_3);
/*output*/
TIM_SetCompare2(TIM8,moto1);
PWM_Init(GPIO_Pin_4);
TIM_SetCompare2(TIM8,moto2);
PWM_Init(GPIO_Pin_5);
TIM_SetCompare2(TIM8,moto3);
PWM_Init(GPIO_Pin_6);
TIM_SetCompare2(TIM8,moto4);
}
示例11: Direction_Dispose
/*差速算法,速度合成*/
void Direction_Dispose(void)//Dispose:处理
{
int Direction_Read;
Direction_Read=ADC_ConvertedValue[1];//读取数据
Direction_Difference=(ADC_Direction-Direction_Read)*0.1;//差=原始数据-现在数据
/*pwm电压调节器,电池电压变化pwm不变*/
// (读出数据/4096)*3.3*21(倍)=实际电压 原始pwm*(32/测量电压)=输出pwm
// ADC_ConvertedValueLocal =(float) ADC_ConvertedValue[2]/4096*3.28*21;
// P=32/ADC_ConvertedValueLocal;
if(int_PWM>0)//判断向前还是向后,如果向前
{
if(Direction_Difference>0)//判断转向数据正数还是负数,如果证书
{
PWM_R=int_PWM-(int_PWM*Direction_Difference/100);//向前的PWM数据-转向值=右//读取PWM信号*(读取的转向/100),意思就是差速信号是转向是PWM的百分比
PWM_L=int_PWM+(int_PWM*Direction_Difference/100);//左边转向值
} //机器向右转
else
{
PWM_R=int_PWM-(int_PWM*Direction_Difference/100);//右边转向值
PWM_L=int_PWM+(int_PWM*Direction_Difference/100);//左边转向值
} //机器向左转
TIM_SetCompare1(TIM1,PWM_L);//送入左电机,第一通道,设定向前运动
TIM_SetCompare1(TIM8,PWM_R);//送入右电机,第一通道,设定向前运动
}
else
{
if(Direction_Difference>0)
{
PWM_R=(-int_PWM)-(int_PWM*Direction_Difference/100);//向前的PWM数据-转向值=右边转向值
PWM_L=(-int_PWM)+(int_PWM*Direction_Difference/100);//左边转向值
} //机器向右转
else
{
PWM_R=(-int_PWM)-(int_PWM*Direction_Difference/100);//右边转向值
PWM_L=(-int_PWM)+(int_PWM*Direction_Difference/100);//左边转向值
} //机器向左转
TIM_SetCompare2(TIM1,PWM_L);//送入左电机,第二通道,设定电机向后运动
TIM_SetCompare2(TIM8,PWM_R);//送入左电机,第二通道,设定电机向后运动
}
}
示例12: TIM4_IRQHandler
/**
* @brief This function handles TIM4 global interrupt request.
* @param None
* @retval None
*/
void TIM4_IRQHandler(void)
{
uint16_t capture = 0;
/* TIM4_CH1 toggling */
if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1 );
capture = TIM_GetCapture1(TIM4);
TIM_SetCompare1(TIM4, capture + Channel1Pulse );
}
/* TIM4_CH2 toggling */
if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);
capture = TIM_GetCapture2(TIM4);
TIM_SetCompare2(TIM4, capture + Channel2Pulse);
}
/* TIM4_CH3 toggling */
if (TIM_GetITStatus(TIM4, TIM_IT_CC3) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC3);
capture = TIM_GetCapture3(TIM4);
TIM_SetCompare3(TIM4, capture + Channel3Pulse);
}
/* TIM4_CH4 toggling */
if (TIM_GetITStatus(TIM4, TIM_IT_CC4) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC4);
capture = TIM_GetCapture4(TIM4);
TIM_SetCompare4(TIM4, capture + Channel4Pulse);
}
/* TIM_Update reset all */
if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
TIM_SetCompare1(TIM4, Channel1Pulse);
TIM_SetCompare2(TIM4, Channel2Pulse);
TIM_SetCompare3(TIM4, Channel3Pulse);
TIM_SetCompare4(TIM4, Channel4Pulse);
}
}
示例13: Move
void Move (uint8_t chan, float angle, servo type)
{
switch(chan)
{
case 1:
TIM_SetCompare1(TIM12, AngleToDuty(angle, type));
break;
case 2:
TIM_SetCompare2(TIM12, AngleToDuty(angle, type));
break;
case 3:
TIM_SetCompare1(TIM3, AngleToDuty(angle, type));
break;
case 4:
TIM_SetCompare2(TIM3, AngleToDuty(angle, type));
break;
case 5:
TIM_SetCompare3(TIM3, AngleToDuty(angle, type));
break;
case 6:
TIM_SetCompare1(TIM4, AngleToDuty(angle, type));
break;
case 7:
TIM_SetCompare2(TIM4, AngleToDuty(angle, type));
break;
case 8:
TIM_SetCompare3(TIM4, AngleToDuty(angle, type));
break;
case 9:
TIM_SetCompare4(TIM4, AngleToDuty(angle, type));
break;
case 10:
TIM_SetCompare1(TIM4, AngleToDuty(angle, type));
break;
default:
break;
}
}
示例14: motorHY_control
//后右电机控制
void motorHY_control(TIM_TypeDef* TMM , uint16_t PWMPulse, u8 Channel, u8 Cmd)
{
//PWM控制
if(Channel==1)
TIM_SetCompare1(TMM, PWMPulse);
else if(Channel==2)
TIM_SetCompare2(TMM, PWMPulse);
else if(Channel==3)
TIM_SetCompare3(TMM, PWMPulse);
else if(Channel==4)
TIM_SetCompare4(TMM, PWMPulse);
//模式控制
if(Cmd==1) //模式0,停止
{
MotorHY_IN1_Reset;
MotorHY_IN2_Reset;
}
if(Cmd==2) //模式1,正转
{
MotorHY_IN1_Set;
MotorHY_IN2_Reset;
}
if(Cmd==3) //模式2,反转
{
MotorHY_IN1_Reset;
MotorHY_IN2_Set;
}
if(Cmd==4) //模式3,刹车
{
MotorHY_IN1_Set;
MotorHY_IN2_Set;
}
}
示例15: pwm_out_set_value
void pwm_out_set_value()
{
TIM_SetCompare1(TIM4, pwm_out[0]);
TIM_SetCompare2(TIM4, pwm_out[1]);
TIM_SetCompare3(TIM4, pwm_out[2]);
TIM_SetCompare4(TIM4, pwm_out[3]);
}