This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
PWM.h
147 lines (133 loc) · 5.22 KB
/
PWM.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* File: PWM.h
* Author: Chris Hajduk
*
* Created on August 21, 2014, 11:45 PM
*/
#ifndef PWM_H
#define PWM_H
#ifdef __cplusplus
extern "C" {
#endif
// Includes
#include "main.h"
// Definitions
#define NUM_CHANNELS 2
#define MAX_PWM 1024
#define MIN_PWM -1024
// Function Prototypes
/*****************************************************************************
* Function: void initPWM(char inputChannels, char outputChannels);
*
* Preconditions: None.
*
* Overview: Initializes the PWM ports. For instance if inputChannels = 0b00100101
* then channels 1,3, and 6 will be initialized.
*
* Input: char inputChannels -> The inputs to be initialized. Each bit represents
* a channel.
*
* Output: None.
*
*****************************************************************************/
void initPWM(char inputChannels, char outputChannels);
/*****************************************************************************
* Function: void PWMInputCalibration(unsigned int channel, float signalScaleFactor, unsigned int signalOffset);
*
* Preconditions: None.
*
* Overview: Calibrates the input range and trim of the device.
*
* Input: unsigned int channel -> The channel to calibrate.
* float signalScaleFactor -> The scale factor to increase or decrease the range by.
* For instance, if the target range is from -1024 to 1024,
* the scale factor would be 1024/(half the detected input range)
* unsigned int signalOffset -> Compensation for a non-zero offset on the input. This is
* known as trim.
*
* Output: None.
*
*****************************************************************************/
void PWMInputCalibration(unsigned int channel, float signalScaleFactor, unsigned int signalOffset);
/*****************************************************************************
* Function: void PWMdOutputCalibration(unsigned int channel, float signalScaleFactor, unsigned int signalOffset);
*
* Preconditions: None.
*
* Overview: Calibrates the output range and trim of the device.
*
* Input: unsigned int channel -> The channel to calibrate.
* float signalScaleFactor -> The scale factor to increase or decrease the range by.
* For instance, if the range is from -1024 to 1024,
* the scale factor would be (half the desired output range)/1024
* unsigned int signalOffset -> Compensation for a non-zero offset on the input. This is
* known as trim.
*
* Output: None.
*
*****************************************************************************/
void PWMOutputCalibration(unsigned int channel, float signalScaleFactor, unsigned int signalOffset);
/*****************************************************************************
* Function: int getPWM(unsigned int channel);
*
* Preconditions: The PWM inputs must have been initialized for valid data.
*
* Overview: Retrieves input (via controller) through the input capture pins on
* the device.
*
* Input: unsigned int channel -> The channel to collect the data from.
*
* Output: int -> The input signal of the channel. Determined by the scaling
* factor range (usually 1024).
*
*****************************************************************************/
int getPWM(unsigned int channel);
/*****************************************************************************
* Function: int* getPWMArray();
*
* Preconditions: The PWM inputs must have been initialized for valid data.
*
* Overview: Retrieves input (via controller) through the input capture pins on
* the device.
*
* Input: None.
*
* Output: int* -> A pointer to the values of the array, which represent the
* inputs of each channel. (usuall ranging between +-1024)
*
*****************************************************************************/
int* getPWMArray();
/*****************************************************************************
* Function: void setPWM(unsigned int channel, int pwm);
*
* Preconditions: The PWM outputs must have been initialized for valid output.
*
Overview: Sets the output through the output compare pins on the device.
*
* Input: unsigned int channel -> The channel that is being set.
* int pwm -> The value (usually between +-1024) that is to be set to the
* output compare pins.
*
* Output: None.
*
*****************************************************************************/
void setPWM(unsigned int channel, int pwm);
/*****************************************************************************
* Function: void setPWMArray(int* ocArray);
*
* Preconditions: The PWM outputs must have been initialized for valid output.
*
Overview: Sets the output through the output compare pins on the device
* according to the values indicated in the ocArray.
*
* Input: int* ocArray -> An array containing the values for each corresponding
* channel.
*
* Output: None.
*
*****************************************************************************/
void setPWMArray(int* ocArray);
#ifdef __cplusplus
}
#endif
#endif /* PWM_H */