led control

This commit is contained in:
Wolfgang Hottgenroth
2018-01-18 15:06:37 +01:00
parent 4ee20b974a
commit 36ce69de93
100 changed files with 8151 additions and 8695 deletions

View File

@ -13,27 +13,36 @@
extern TIM_HandleTypeDef htim3;
void pwmExec(void *handle) {
const int32_t PWM_MAX = 10000;
const int32_t PWM_STEP = 200;
typedef struct {
int32_t value;
int32_t direction;
} tPwmHandle;
tPwmHandle pwmHandle = { .value = 0, .direction = 1 };
void pwmExec(void *handle) {
tPwmHandle *lPwmHandle = (tPwmHandle*) handle;
lPwmHandle->value += (PWM_STEP * lPwmHandle->direction);
if (lPwmHandle->value >= PWM_MAX) {
lPwmHandle->direction = -1;
}
if (lPwmHandle->value <= 0) {
lPwmHandle->direction = 1;
}
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, lPwmHandle->value);
}
void pwmInit() {
// schAdd(pwmExec, NULL, 0, 1000);
schAdd(pwmExec, &pwmHandle, 0, 50);
__HAL_TIM_SET_AUTORELOAD(&htim3, 10000);
__HAL_TIM_SET_AUTORELOAD(&htim3, PWM_MAX);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, 200);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, 0);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, 1000);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, 2000);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_4, 8000);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
}