PWM test F767ZI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // F767ZI PWM test  D6/PE_9 TIM1_CH1  or D13/PA_5 TIM2_CH1
00002 
00003 #include "mbed.h"
00004 #define PRREG(z) printf(#z" 0x%x\n",z)
00005 
00006 #if 0
00007 PwmOut pwm(D6);
00008 
00009 int main()
00010 {
00011     printf("D6 PE_9\n");
00012     // specify period first, then everything else
00013    // pwm.period(0.001f);  //  second period
00014    //pwm.write(0.50f);  // 50% duty cycle
00015    
00016 // manual 1 mhz
00017     PRREG(RCC->APB2ENR);
00018     PRREG(GPIOE->AFR[1]);  //alt PE_9
00019     TIM1->PSC = 0;
00020     TIM1->ARR = 216-1;
00021     TIM1->CCR1 = 216/2;
00022     TIM1->CNT = 0;
00023     TIM1->CR1 = 1;  
00024     
00025     PRREG(TIM1->CR1);
00026     PRREG(TIM1->PSC);
00027     PRREG(TIM1->ARR);
00028     PRREG(TIM1->CCR1);
00029     
00030     while (1);         // led flashing
00031 }
00032 #else
00033 PwmOut pwm(D13), led(LED2);
00034 
00035 int main()
00036 {
00037     printf("D13 PA_5\n");
00038     // specify period first, then everything else
00039     //pwm.period(0.001f);  //  second period
00040      //pwm.write(0.50f);  // 50% duty cycle
00041 
00042 // manual 1 mhz
00043     PRREG(RCC->APB1ENR);
00044     PRREG(GPIOA->AFR[0]);  //alt PA_5
00045     TIM2->PSC = 0; 
00046     TIM2->ARR = 108-1;
00047     TIM2->CCR1 = 108/2;
00048     TIM2->CNT = 0;   // need this
00049     TIM2->CR1 =  TIM_CR1_CEN;  
00050 
00051     PRREG(TIM2->CR1);
00052     PRREG(TIM2->PSC);
00053     PRREG(TIM2->ARR);
00054     PRREG(TIM2->CCR1);
00055     
00056     printf("us_ticker\n");
00057     PRREG(TIM5->CR1);  // us_ticker
00058     PRREG(TIM5->PSC);
00059     PRREG(TIM5->ARR);
00060     PRREG(TIM5->CCR1);
00061     PRREG(TIM5->CNT);
00062     
00063     led.period(0.5);
00064     led.write(0.5);
00065     while (1);         // led flashing
00066 }
00067 #endif