-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwm.c
69 lines (60 loc) · 1.8 KB
/
pwm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "PLL.h"
#include "tm4c123gh6pm.h" // Constant declarations to access port registers using
// symbolic names instead of addresses
void SysTick_Wait10ms(unsigned long delay);
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void WaitForInterrupt(void); // low power mode
void PortA_Init(void) ;
void SysFun(void);
void SysLoad(unsigned long period);
int main(void) { PLL_Init();
SysFun(); // 80 MHz
PortA_Init() ; // initialize output and interrupts
EnableInterrupts();
/*Initialize ports and timers*/
while(1){
unsigned long i,j;
for(i=80000; i<=160000; i+=16000) /*on time starts from 1msec to 2msec with a increment of 0.2msec risein on tim */
{
for(j=0;j<4;j++)
{
GPIO_PORTA_DATA_R |= (0x40);
SysLoad(i);
GPIO_PORTA_DATA_R &= ~(0x40);
SysLoad(1600000-i);
}
}
for(i=160000; i>=80000; i-=16000)
{
for(j=0;j<4;j++)
{
GPIO_PORTA_DATA_R |= (0x40);
SysLoad(i);
GPIO_PORTA_DATA_R &= ~(0x40);
SysLoad(1600000-i);
}
}
}
}
void PortA_Init(void){ unsigned long volatile delay;
/*PORT Initialization*/
SYSCTL_RCGC2_R |= 0x01; // Port A clock
delay = SYSCTL_RCGC2_R; // wait 3-5 bus cycles
GPIO_PORTA_DIR_R |= 0x40; // PA6 output
GPIO_PORTA_AFSEL_R &= ~0x40; // not alternative
GPIO_PORTA_AMSEL_R &= ~0x40; // no analog
GPIO_PORTA_PCTL_R &= ~0x0F000000; // bits for PA6
GPIO_PORTA_DEN_R |= 0x40; // enable PA6
}
void SysLoad(unsigned long period){
NVIC_ST_RELOAD_R = period-1; // number of counts to wait
NVIC_ST_CURRENT_R = 0; // any value written to CURRENT clears
while((NVIC_ST_CTRL_R&0x00010000)==0){ // wait for count flag
}
}
void SysFun(void)
{
NVIC_ST_CTRL_R = 0; // disable SysTick during setup
NVIC_ST_CTRL_R = 0x00000005;
}