wip
This commit is contained in:
@@ -14,7 +14,8 @@ extern TIM_HandleTypeDef htim1;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
|
||||
extern volatile uint8_t rtramp[4];
|
||||
extern uint8_t mrampstart[4];
|
||||
bool IsPwmRunning(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_TIM_ChannelStateTypeDef chState = HAL_TIM_GetChannelState(htim, Channel);
|
||||
@@ -242,3 +243,41 @@ void SetMotPerc(uint8_t mot,uint8_t dir,uint8_t perc){
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint8_t ramp(uint8_t mot,uint8_t dir,uint8_t percStart,uint8_t percEnd,uint8_t tr,uint8_t mode){
|
||||
static uint8_t memrtramp[4];
|
||||
uint16_t delta;
|
||||
switch(mode){
|
||||
case RAMPINIT:
|
||||
memrtramp[mot-1]=percStart=tr;
|
||||
SetMotPerc(mot,dir,mrampstart[mot-1]);
|
||||
return DONE;
|
||||
case RAMPRUN:
|
||||
if(memrtramp[mot-1]!=rtramp[mot-1]){
|
||||
memrtramp[mot-1]=rtramp[mot-1];
|
||||
if(rtramp[mot-1]){
|
||||
if(mrampstart[mot-1]>percEnd){
|
||||
delta=mrampstart[mot-1]-percEnd;
|
||||
delta=delta*(uint16_t)(tr-rtramp[mot-1]);
|
||||
delta=delta/tr;
|
||||
SetMotPerc(mot,dir,mrampstart[mot-1]-delta);
|
||||
return RUNNING;
|
||||
}else if(mrampstart[mot-1]<percEnd){
|
||||
delta=percEnd-mrampstart[mot-1];
|
||||
delta=delta*(uint16_t)(tr-rtramp[mot-1]);
|
||||
delta=delta/tr;
|
||||
SetMotPerc(mot,dir,mrampstart[mot-1]+delta);
|
||||
return RUNNING;
|
||||
}else{
|
||||
SetMotPerc(mot,dir,percEnd);
|
||||
return DONE;
|
||||
}
|
||||
}else{
|
||||
SetMotPerc(mot,dir,percEnd);
|
||||
return DONE;
|
||||
}
|
||||
}else return RUNNING;
|
||||
break;
|
||||
}
|
||||
return DONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user