Kim GiJeong
/
try19_pwm_tim20_comple
try19_pwm_tim20_comple
Revision 1:27f1640d930d, committed 2019-08-21
- Comitter:
- GiJeongKim
- Date:
- Wed Aug 21 05:18:06 2019 +0000
- Parent:
- 0:8a1dc1fdba10
- Commit message:
- pwm complementary
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 8a1dc1fdba10 -r 27f1640d930d main.cpp --- a/main.cpp Mon Aug 12 09:15:22 2019 +0000 +++ b/main.cpp Wed Aug 21 05:18:06 2019 +0000 @@ -1,27 +1,30 @@ #include "mbed.h" #include "FastPWM.h" -#define PIN_U PA_10 -#define PIN_V PA_9 -#define PIN_W PA_8 -#define PWM_ARR 0x8CA /// timer autoreload value +#define PIN_A PA_8 // channel 1 +#define PIN_B PA_7 // complementary +#define PWM_ARR 0x8CA /// timer autoreload value 40k loop, 40k pwm -float dtc_u=0.1; -float dtc_v=0.2; -float dtc_w=0.6; +float dtc_a=0.1; +float dtc_b=0.2; void Init_PWM(); +DigitalOut check(PC_9); +DigitalIn a1(PB_7); +DigitalIn a2(PB_6); + extern "C" void TIM1_UP_TIM10_IRQHandler(void) { if (TIM1->SR & TIM_SR_UIF ) { - TIM1->CCR3 = (PWM_ARR)*(1.0f-dtc_u); // Write duty cycles - TIM1->CCR2 = (PWM_ARR)*(1.0f-dtc_v); - TIM1->CCR1 = (PWM_ARR)*(1.0f-dtc_w); // CCR1 = channel 1 + check=1; + TIM1->CCR1 = (PWM_ARR)*(1.0f-dtc_a); // Write duty cycles + check=0; } TIM1->SR = 0x0; // reset the status register } int main(){ + check=1; Init_PWM(); TIM1->CR1 ^= TIM_CR1_UDIS; while(1); @@ -31,18 +34,10 @@ void Init_PWM(){ - RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN; // enable the clock to GPIOC - RCC->APB1ENR |= 0x00000001; // enable TIM2 clock RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // enable TIM1 clock - GPIOC->MODER |= (1 << 10); // set pin 5 to be general purpose output for LED -// gpio->enable = new DigitalOut(ENABLE_PIN); -// gpio->pwm_u = new FastPWM(PIN_U); -// gpio->pwm_v = new FastPWM(PIN_V); -// gpio->pwm_w = new FastPWM(PIN_W); - FastPWM pwm_u(PIN_U); // 단순히 핀 설정용 - FastPWM pwm_v(PIN_V); - FastPWM pwm_w(PIN_W); + FastPWM pwm_a(PIN_A); // 단순히 핀 설정용 + FastPWM pwm_b(PIN_B); //ISR Setup @@ -54,12 +49,16 @@ TIM1->CR1 |= TIM_CR1_ARPE; // autoreload on, TIM1->RCR |= 0x001; // update event once per up/down count of tim1 TIM1->EGR |= TIM_EGR_UG; + + //PWM Setup TIM1->PSC = 0x0; // no prescaler, timer counts up in sync with the peripheral clock TIM1->ARR = PWM_ARR; // set auto reload, 40 khz - TIM1->CCER |= ~(TIM_CCER_CC1NP); // Interupt when low side is on. +// TIM1->CCER |= ~(TIM_CCER_CC1NP); // Interupt when low side is on. TIM1->CR1 |= TIM_CR1_CEN; // enable TIM1 + // for complementary + TIM1->CCER|=0b1111; } \ No newline at end of file