Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include "stm32f4xx_tim.h"
  2. #include "stm32f4xx_gpio.h"
  3. #include "stm32f4xx_rcc.h"
  4. #include "stm32f4xx_conf.h"
  5. //zad1
  6. int main(void)
  7. {
  8. SystemInit();
  9.  
  10. /* GPIOD Periph clock enable */
  11. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  12. RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
  13.  
  14. GPIO_InitTypeDef GPIO_InitStructure;
  15. /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  16. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2| GPIO_Pin_3;
  17. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  18. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  19. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  20. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  21. GPIO_Init(GPIOA, &GPIO_InitStructure);
  22.  
  23. //kanał wyjciowy GPIO
  24. GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5);
  25. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  26. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  27. GPIO_Init(GPIOA, &GPIO_InitStructure);
  28.  
  29. GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5);
  30. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  31. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  32. GPIO_Init(GPIOA, &GPIO_InitStructure);
  33.  
  34. GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5);
  35. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  36. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  37. GPIO_Init(GPIOA, &GPIO_InitStructure);
  38.  
  39.  
  40. //TIM5
  41. TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  42. TIM_TimeBaseStructure.TIM_Period = 99;
  43. TIM_TimeBaseStructure.TIM_Prescaler = 839;
  44. TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  45. TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  46. TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
  47. TIM_Cmd(TIM5, ENABLE);
  48.  
  49. //PWM
  50. TIM_OCInitTypeDef TIM_OCInitStructure;
  51. /* PWM1 Mode configuration: */
  52. TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  53. TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  54. TIM_OCInitStructure.TIM_Pulse = 1000;
  55. TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  56. TIM_OC1Init(TIM5, &TIM_OCInitStructure);
  57. TIM_OC1PreloadConfig(TIM5, TIM_OCPreload_Enable);
  58. TIM_OC2Init(TIM5, &TIM_OCInitStructure);
  59. TIM_OC2PreloadConfig(TIM5, TIM_OCPreload_Enable);
  60. TIM_OC3Init(TIM5, &TIM_OCInitStructure);
  61. TIM_OC3PreloadConfig(TIM5, TIM_OCPreload_Enable);
  62.  
  63. TIM4->CCR1 = 9;
  64. TIM4->CCR2 = 49;
  65. TIM4->CCR3 = 74;
  66.  
  67. for(;;)
  68. {
  69. }
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement