使用Timer1的两路PWM生成波形,同时映射相对称的波形。作用嘛,当然是无线充电啦!
timer.c
- void timer1_pwm_init()
- {
- TIM1_CR1 |= 0x60; //
- TIM1_CCMR1 |= 0x70; //CH1 output PWM, Mode 2
- TIM1_CCMR2 |= 0x70; //CH2 output PWM, Mode 2
- TIM1_CCER1 |= (0x50|0x05); //CC1P=1,CC1E=1; CC2P=1,CC2E=1
- TIM1_CCER2 |= (0x50|0x05); //CC3P=1,CC3E=1; CC4P=1,CC4E=1
- TIM1_CCR1H = 0;
- TIM1_CCR1L = 0x80; //50%
- TIM1_CCR2H = 0;
- TIM1_CCR2L = 0x80; //50%
- TIM1_BKR |= 0x80; //main output enable
- TIM1_ARRH = 0;
- TIM1_ARRL = 0xff; //Fosc/(TIM1_ARRH<<8+TIM2_ARRL)
- TIM1_PSCR = 0; //Fosc/2^0
- TIM1_CR1 |= 0x01; //Enable timer1
- }