Advertisement
Guest User

Untitled

a guest
Aug 19th, 2016
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "..//tm4c123gh6pm.h"
  2. #include "PWM1.h"
  3.  
  4. // ***************** Timer0_Init ****************
  5. // Activate TIMER0 interrupts to run user task periodically
  6. // Inputs:  task is a pointer to a user function
  7. //          period in units (1/clockfreq)
  8. // Outputs: none
  9. #define RED_LED         0x2
  10. #define BLUE_LED        0x4
  11. #define GREEN_LED       0x8
  12.  
  13. #define TAPWMIE         (1 << 9)
  14. #define TAAMS           (1 << 3)
  15. #define TACMR           0x02
  16. #define TAMR                (1 << 1)
  17. #define TAWPML          (1 << 6)
  18. #define TAPLO         (1 << 11)
  19. #define TAWOT               (1 << 6)
  20. #define TAMIE               (1 << 5)
  21. //Interrupts defines
  22.  //GPTM Timer A Match Interrupt Mask
  23. #define TATOIM          (1 << 0) //GPTM Timer A Time-Out Interrupt Mask
  24. #define TAMIM               (1 << 4)
  25.  
  26. extern void DisableInterrupts(void); // Disable interrupts
  27. extern void EnableInterrupts(void);  // Enable interrupts
  28. extern void WaitForInterrupt(void);  // low power mode
  29.  
  30.  
  31. static const unsigned long LED[] = {RED_LED , BLUE_LED, GREEN_LED, 0x0};
  32. void configureInterruptPWM()
  33. {
  34.   NVIC_PRI5_R       = (NVIC_PRI5_R&0xFFFFFF00) | 0x00000000; // 8) priority 4
  35.   NVIC_EN0_R            = (1<<19);           // 9) enable IRQ 19 in NVIC
  36. }
  37.  
  38. volatile unsigned long ledNR = 0;
  39.  
  40. void nextLED(void)
  41. {
  42.         ledNR++;
  43. }
  44. void previousLED(void)
  45. {
  46.         ledNR--;
  47. }
  48. void PWM1_Init(unsigned long longSignal){
  49.     configureInterruptPWM();
  50.    
  51.   SYSCTL_RCGCTIMER_R |= 0x01;   // 0) activate TIMER0  
  52.   TIMER0_CTL_R &= ~0x00000001;    // 1) disable TIMER0A during setup   
  53.        
  54.   TIMER0_CFG_R           = 0x00;                                        // 2) configure for 32-bit mode
  55.     TIMER0_TAMR_R      = 0x02 | TAMIE;   // 3) configure for periodic mode, default down-count settings;
  56.   TIMER0_TAPR_R          = 0x0;      
  57.     TIMER0_TAPMR_R       = 0x0001;        
  58.     TIMER0_TAILR_R       = 0x0ffff;
  59.     TIMER0_TAMATCHR_R  = 0xf;
  60.   TIMER0_ICR_R           = TIMER_ICR_TAMCINT | TIMER_ICR_TATOCINT;    // 6) clear TIMER0A timeout flag
  61.     TIMER0_IMR_R             = TATOIM | TAMIM;
  62.    
  63.   TIMER0_CTL_R |= 0x00000001;    // 10) enable TIMER0A 
  64. }
  65.  
  66. void Timer0A_Handler(void)
  67. {  
  68.     //Timeout
  69.     unsigned long myLed = ledNR & 3;
  70.     if (TIMER0_RIS_R & 0x1)
  71.     {
  72.         NVIC_EN0_R = (1<<30);
  73.         TIMER0_ICR_R = TIMER_ICR_TATOCINT;// acknowledge TIMER1A timeout
  74.         DisableInterrupts();
  75.         GPIO_PORTF_DATA_R |= LED[myLed];
  76.         EnableInterrupts();
  77.         //GPIO_PORTF_DATA_R |= LED[0];
  78.         //GPIO_PORTF_DATA_R |= LED[1];
  79.     }   //Match
  80.     else if (TIMER0_RIS_R & (1 << 4))
  81.     {
  82.         TIMER0_ICR_R = TIMER_ICR_TAMCINT;
  83.         DisableInterrupts();
  84.         GPIO_PORTF_DATA_R &= ~(LED[myLed]);
  85.         EnableInterrupts();
  86.         //GPIO_PORTF_DATA_R &= ~(LED[0]);
  87.         //GPIO_PORTF_DATA_R &= ~(LED[1]);
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement