Elevator v2.0
Elevator Documenation
Loading...
Searching...
No Matches
servo.h
Go to the documentation of this file.
1
11#ifndef _SERVO_H_
12#define _SERVO_H_
13
14#include <stdio.h>
15#include "freertos/FreeRTOS.h"
16#include "freertos/task.h"
17#include "driver/mcpwm.h"
18
19#define SERVO_PWM_UNIT (mcpwm_unit_t)MCPWM_UNIT_0 // pwm unit
20#define SERVO_PWM_SIGNAL (mcpwm_io_signals_t)(MCPWM0A) // pwm signal
21#define SERVO_GPIO 14 // servo gpio pin
22#define SERVO_FREQ 50 // default frequency for servo
23#define SERVO_TIMER (mcpwm_timer_t)MCPWM_TIMER_0 // default timer
24
25#define SERVO_MIN_PULSEWIDTH_US (1000) // min pulse width
26#define SERVO_MAX_PULSEWIDTH_US (2000) // max pulse width
27#define SERVO_MAX_DEGREE (90) //max degree
28
29#define SERVO_OPEN -90
30#define SERVO_CLOSE 90
31
49typedef struct Servo{
50 mcpwm_timer_t timerNum;
51 mcpwm_unit_t pwmUnit;
52 mcpwm_io_signals_t signal;
53 gpio_num_t gpio;
54 int angle;
56
64void moveServo(Servo *servo, int angle);
70void servoInit(Servo *servo);
71
78void haltServo(Servo *servo);
79
85void startServo(Servo *servo);
86#endif
void startServo(Servo *servo)
startServo will start the time of the mcpwm
Definition: servo.c:69
void haltServo(Servo *servo)
haltServo will stop the timer of the mcpwm
Definition: servo.c:60
void moveServo(Servo *servo, int angle)
moveServo will move the servo motor by angles
Definition: servo.c:28
void servoInit(Servo *servo)
servoInit will initialize servo motor
Definition: servo.c:39
Servo struct for SG90 servo motor.
Definition: servo.h:49
int angle
Definition: servo.h:54
mcpwm_unit_t pwmUnit
Definition: servo.h:51
gpio_num_t gpio
Definition: servo.h:53
mcpwm_io_signals_t signal
Definition: servo.h:52
mcpwm_timer_t timerNum
Definition: servo.h:50