-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathload.c
More file actions
29 lines (24 loc) · 744 Bytes
/
Copy pathload.c
File metadata and controls
29 lines (24 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "load.h"
// use PC1/TIM1_CH1, PE5, PC2
void LOAD_init(void) {
TIM1->PSCRH = 0;
TIM1->PSCRL = 0;
TIM1->ARRH = (uint8_t)(LOAD_MAX >> 8); // FIXME increase frequency? don't lose accuracy
TIM1->ARRL = (uint8_t)LOAD_MAX;
TIM1->BKR = TIM1_BKR_MOE;
TIM1->CCMR1 = TIM1_CCMR1_OC1M_PWM1 | TIM1_CCMR1_OC1PE;
TIM1->CCER1 = TIM1_CCER1_CC1E;
TIM1->CCR1H = 0;
TIM1->CCR1L = 0;
TIM1->CR2 |= TIM1_CR2_CCPC;
TIM1->CR1 |= TIM1_CR1_CEN;
LOAD_stop();
GPIOE->DDR |= GPIO_DDR_5; // output
GPIOE->CR1 |= GPIO_CR1_5; // pull-push
GPIOC->CR1 |= GPIO_CR1_2; // pull-up
}
void LOAD_set(uint16_t v) {
TIM1->CCR1H = v >> 8;
TIM1->CCR1L = v & 0xFF;
TIM1->EGR |= TIM1_EGR_COMG;
}