本文整理汇总了C++中TIM_SetCompare1函数的典型用法代码示例。如果您正苦于以下问题:C++ TIM_SetCompare1函数的具体用法?C++ TIM_SetCompare1怎么用?C++ TIM_SetCompare1使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TIM_SetCompare1函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
}
示例3: tim_update
void tim_update(void){
u16 curr_time_lsb = TIM_GetCounter(TIM2);
u16 curr_time_msb = TIM_GetCounter(TIM3);
u16 next_capture_msb;
u16 next_capture_lsb;
u32 curr_time = curr_time_msb;
curr_time <<= 16;
curr_time |= curr_time_lsb;
u32 next_capture;
if(!tim_was_updated){
tim_last_upd = curr_time;
tim_was_updated = 1;
return;
}
tim_freq = (curr_time - tim_last_upd);
next_capture = tim_freq / 2;
tim_last_upd = curr_time;
next_capture_lsb = next_capture & 0xFFFF;
next_capture_msb = next_capture >> 16;
TIM_SetCompare1(TIM2, curr_time_lsb + next_capture_lsb);
TIM_SetCompare1(TIM3, curr_time_msb + next_capture_msb);
if(next_capture_msb == 0){
TIM_ITConfig(TIM3, TIM_IT_CC1, DISABLE);
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
}else{
TIM_ITConfig(TIM2, TIM_IT_CC1, DISABLE);
TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);
}
}
示例4: TIM2_IRQHandler
/**
* @brief This function handles TIM2 global interrupt request.
* @param None
* @retval None
*/
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
if(line_number < 479)
TIM_SetCompare1(TIM4, 800);
else if(line_number < 524)
TIM_SetCompare1(TIM4, 0);
else if(line_number == 524)
TIM_SetCompare1(TIM4, 800);
line_number++;
if(line_number == 525)
line_number = 0;
if(line_number == 482)
letsgo = 1;
}
if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
toggle = 1;
}
}
示例5: initPins
static void initPins() {
GPIO_InitTypeDef pwm_gpio;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
pwm_gpio.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
pwm_gpio.GPIO_Mode = GPIO_Mode_AF;
pwm_gpio.GPIO_Speed = GPIO_Speed_100MHz;
pwm_gpio.GPIO_OType = GPIO_OType_PP;
pwm_gpio.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &pwm_gpio);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_TIM3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_TIM3);
TIM_SetCompare1(TIM3, 0);
TIM_SetCompare1(TIM3, 0);
GPIO_InitTypeDef gpio;
GPIO_StructInit(&gpio);
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
gpio.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &gpio);
GPIO_ResetBits(GPIOB, GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9);
}
示例6: 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);
}
}
示例7: MOTORS_LMS
void MOTORS_LMS(uint8_t speed) {
if (speed >= 50) {
TIM_SetCompare1(TIM3, (speed-50) * 20);
GPIO_SetBits(GPIOB, GPIO_Pin_6);
GPIO_ResetBits(GPIOB, GPIO_Pin_7);
} else {
TIM_SetCompare1(TIM3, speed * 20);
GPIO_ResetBits(GPIOB, GPIO_Pin_6);
GPIO_SetBits(GPIOB, GPIO_Pin_7);
}
}
示例8: 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;
}
}
示例9: TIM2_IRQHandler
/**
* @brief This function handles TIM2 Handler.
* @ TIM2Öжϴ¦Àí³ÌÐò
* @param None
*/
void TIM2_IRQHandler(void){
if(TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET){
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
//GPIO_WriteBit(GPIOE, GPIO_Pin_3, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOE, GPIO_Pin_3)));
capture = TIM_GetCapture1(TIM2);
if(flag == 0){
TIM_SetCompare1(TIM2, capture + Increment_High);
flag = 1;
}else{
TIM_SetCompare1(TIM2, capture + Increment_Low);
flag = 0;
}
}
}
示例10: 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
}
示例11: 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);
}
示例12: 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);//送入左电机,第二通道,设定电机向后运动
}
}
示例13: 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);
}
}
示例14: 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;
}
}
示例15: batholithResetPwm
void batholithResetPwm(){
TIM_SetCompare2(TIM8,0);
TIM_SetCompare3(TIM8,0);
TIM_SetCompare2(TIM1,0);
TIM_SetCompare1(TIM1,0);
me.isPWMallowed=0;
}