1 |
// File: Servos.c |
---|
2 |
//------------------------------------------------------------------------------ |
---|
3 |
// Author: Giovanni de Sanctis |
---|
4 |
// Email: info@lateral-technologies.com |
---|
5 |
//------------------------------------------------------------------------------ |
---|
6 |
// Date: Dec 2018 |
---|
7 |
// Controls the 2 servos |
---|
8 |
//------------------------------------------------------------------------------ |
---|
9 |
|
---|
10 |
#include "Servos.h" |
---|
11 |
#include "mcc_generated_files/pin_manager.h" |
---|
12 |
#include "mcc_generated_files/pwm1.h" |
---|
13 |
#include "mcc_generated_files/pwm2.h" |
---|
14 |
#include "mcc_generated_files/pwm3.h" |
---|
15 |
#include "mcc_generated_files/device_config.h" |
---|
16 |
#include "mcc_generated_files/mcc.h" |
---|
17 |
#include "Power.h" |
---|
18 |
|
---|
19 |
|
---|
20 |
void initServos() |
---|
21 |
{ |
---|
22 |
//Initialisation of PWMs with servo parameters (20ms, 1.5ms) is done in the PWM init |
---|
23 |
} |
---|
24 |
|
---|
25 |
//Turns on power to the servos and starts the PWM peripheral |
---|
26 |
void startServos() |
---|
27 |
{ |
---|
28 |
//Skip if already on |
---|
29 |
if (IO_SERVOS_GetValue()) return; |
---|
30 |
|
---|
31 |
setServo1(0); //POS2SERVO(SERVO1_HOME)); |
---|
32 |
setServo2(0); //POS2SERVO(SERVO2_HOME)); |
---|
33 |
IO_SERVOS_SetHigh(); |
---|
34 |
PWM1_Start(); |
---|
35 |
PWM2_Start(); |
---|
36 |
} |
---|
37 |
|
---|
38 |
//Turns off power to the servos and stops the PWM peripheral |
---|
39 |
void stopServos() |
---|
40 |
{ |
---|
41 |
//Skip if already off |
---|
42 |
if (IO_SERVOS_GetValue()==0) return; |
---|
43 |
|
---|
44 |
//Put servos in the home position |
---|
45 |
//homeServos(); |
---|
46 |
|
---|
47 |
//Power off the PWM peripherals |
---|
48 |
PWM1_Stop(); |
---|
49 |
PWM2_Stop(); |
---|
50 |
//Power off the servos |
---|
51 |
IO_SERVOS_SetLow(); |
---|
52 |
} |
---|
53 |
|
---|
54 |
uint8_t isServoOn() |
---|
55 |
{ |
---|
56 |
return IO_SERVOS_GetValue(); |
---|
57 |
} |
---|
58 |
|
---|
59 |
void setServo1(int16_t pos) |
---|
60 |
{ |
---|
61 |
PWM1_DutyCycleSet((uint16_t)pos); |
---|
62 |
PWM1_LoadBufferSet(); |
---|
63 |
} |
---|
64 |
void setServo2(int16_t pos) |
---|
65 |
{ |
---|
66 |
PWM2_DutyCycleSet((uint16_t)pos); |
---|
67 |
PWM2_LoadBufferSet(); |
---|
68 |
} |
---|