/
servo.c
58 lines (52 loc) · 1.47 KB
/
servo.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
#include <main.h>
#include <stdint.h>
#include <stdio.h>
#include "TM4C123GH6PM.h" // Device header
#include "inc/hw_ints.h"
#include "inc/hw_nvic.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_types.h"
#include "inc/hw_timer.h"
#include "inc/hw_gpio.h"
#include "inc/hw_pwm.h"
#include "driverlib/pwm.h"
#include "driverlib/interrupt.h"
#include "driverlib/cpu.h"
#include "driverlib/debug.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/timer.h"
#include <string.h>
#include "IO_Expander.h"
#include "Paser.h"
void PWM_Setup()
{
SysCtlPWMClockSet(PWM_SYSCLK_DIV_64);
//
// Configure the PWM generator for count down mode with immediate updates
// to the parameters.
//
PWMGenConfigure(PWM1_BASE, PWM_GEN_3, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
// Set the period. For a 50 KHz frequency, the period = 1/50,000, or 20
// microseconds. For a 20 MHz clock, this translates to 400 clock ticks.
// Use this value to set the period.
//
PWMGenPeriodSet(PWM1_BASE, PWM_GEN_3, MAXPERIOD);
//
// Set the pulse width of PWM1 for a 75% duty cycle.
//
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_6, 0);
PWMPulseWidthSet(PWM1_BASE, PWM_OUT_5, 0);
// 50MHZ is to fast
PWMClockSet(PWM1_BASE,PWM_SYSCLK_DIV_64);
//
// Start the timers in generator 3.
//
PWMGenEnable(PWM1_BASE, PWM_GEN_3);
//
// Enable the outputs.
//
PWMOutputState(PWM1_BASE, PWM_OUT_6_BIT , true);
}