PWM test F767ZI
main.cpp@0:0393a9702467, 4 months ago (annotated)
- Committer:
- manitou
- Date:
- Tue Nov 08 13:13:20 2022 +0000
- Revision:
- 0:0393a9702467
pwmtst F767ZI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
manitou | 0:0393a9702467 | 1 | // F767ZI PWM test D6/PE_9 TIM1_CH1 or D13/PA_5 TIM2_CH1 |
manitou | 0:0393a9702467 | 2 | |
manitou | 0:0393a9702467 | 3 | #include "mbed.h" |
manitou | 0:0393a9702467 | 4 | #define PRREG(z) printf(#z" 0x%x\n",z) |
manitou | 0:0393a9702467 | 5 | |
manitou | 0:0393a9702467 | 6 | #if 0 |
manitou | 0:0393a9702467 | 7 | PwmOut pwm(D6); |
manitou | 0:0393a9702467 | 8 | |
manitou | 0:0393a9702467 | 9 | int main() |
manitou | 0:0393a9702467 | 10 | { |
manitou | 0:0393a9702467 | 11 | printf("D6 PE_9\n"); |
manitou | 0:0393a9702467 | 12 | // specify period first, then everything else |
manitou | 0:0393a9702467 | 13 | // pwm.period(0.001f); // second period |
manitou | 0:0393a9702467 | 14 | //pwm.write(0.50f); // 50% duty cycle |
manitou | 0:0393a9702467 | 15 | |
manitou | 0:0393a9702467 | 16 | // manual 1 mhz |
manitou | 0:0393a9702467 | 17 | PRREG(RCC->APB2ENR); |
manitou | 0:0393a9702467 | 18 | PRREG(GPIOE->AFR[1]); //alt PE_9 |
manitou | 0:0393a9702467 | 19 | TIM1->PSC = 0; |
manitou | 0:0393a9702467 | 20 | TIM1->ARR = 216-1; |
manitou | 0:0393a9702467 | 21 | TIM1->CCR1 = 216/2; |
manitou | 0:0393a9702467 | 22 | TIM1->CNT = 0; |
manitou | 0:0393a9702467 | 23 | TIM1->CR1 = 1; |
manitou | 0:0393a9702467 | 24 | |
manitou | 0:0393a9702467 | 25 | PRREG(TIM1->CR1); |
manitou | 0:0393a9702467 | 26 | PRREG(TIM1->PSC); |
manitou | 0:0393a9702467 | 27 | PRREG(TIM1->ARR); |
manitou | 0:0393a9702467 | 28 | PRREG(TIM1->CCR1); |
manitou | 0:0393a9702467 | 29 | |
manitou | 0:0393a9702467 | 30 | while (1); // led flashing |
manitou | 0:0393a9702467 | 31 | } |
manitou | 0:0393a9702467 | 32 | #else |
manitou | 0:0393a9702467 | 33 | PwmOut pwm(D13), led(LED2); |
manitou | 0:0393a9702467 | 34 | |
manitou | 0:0393a9702467 | 35 | int main() |
manitou | 0:0393a9702467 | 36 | { |
manitou | 0:0393a9702467 | 37 | printf("D13 PA_5\n"); |
manitou | 0:0393a9702467 | 38 | // specify period first, then everything else |
manitou | 0:0393a9702467 | 39 | //pwm.period(0.001f); // second period |
manitou | 0:0393a9702467 | 40 | //pwm.write(0.50f); // 50% duty cycle |
manitou | 0:0393a9702467 | 41 | |
manitou | 0:0393a9702467 | 42 | // manual 1 mhz |
manitou | 0:0393a9702467 | 43 | PRREG(RCC->APB1ENR); |
manitou | 0:0393a9702467 | 44 | PRREG(GPIOA->AFR[0]); //alt PA_5 |
manitou | 0:0393a9702467 | 45 | TIM2->PSC = 0; |
manitou | 0:0393a9702467 | 46 | TIM2->ARR = 108-1; |
manitou | 0:0393a9702467 | 47 | TIM2->CCR1 = 108/2; |
manitou | 0:0393a9702467 | 48 | TIM2->CNT = 0; // need this |
manitou | 0:0393a9702467 | 49 | TIM2->CR1 = TIM_CR1_CEN; |
manitou | 0:0393a9702467 | 50 | |
manitou | 0:0393a9702467 | 51 | PRREG(TIM2->CR1); |
manitou | 0:0393a9702467 | 52 | PRREG(TIM2->PSC); |
manitou | 0:0393a9702467 | 53 | PRREG(TIM2->ARR); |
manitou | 0:0393a9702467 | 54 | PRREG(TIM2->CCR1); |
manitou | 0:0393a9702467 | 55 | |
manitou | 0:0393a9702467 | 56 | printf("us_ticker\n"); |
manitou | 0:0393a9702467 | 57 | PRREG(TIM5->CR1); // us_ticker |
manitou | 0:0393a9702467 | 58 | PRREG(TIM5->PSC); |
manitou | 0:0393a9702467 | 59 | PRREG(TIM5->ARR); |
manitou | 0:0393a9702467 | 60 | PRREG(TIM5->CCR1); |
manitou | 0:0393a9702467 | 61 | PRREG(TIM5->CNT); |
manitou | 0:0393a9702467 | 62 | |
manitou | 0:0393a9702467 | 63 | led.period(0.5); |
manitou | 0:0393a9702467 | 64 | led.write(0.5); |
manitou | 0:0393a9702467 | 65 | while (1); // led flashing |
manitou | 0:0393a9702467 | 66 | } |
manitou | 0:0393a9702467 | 67 | #endif |