-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoft_pwm.h
101 lines (84 loc) · 1.84 KB
/
soft_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
/**
* @file soft_pwm.h
* @author Julian Bustamante N
* @brief software pwm driver
* @version 0.1.0
* @date 2021-04-09
*
* @copyright Copyright (c) 2021
* @note
* minimun time for tick : 1ms
frequency 0 -15.2590 KHz ( T: 0 - 65.535 sg)
Duty cicle 0 -100 %
*/
#ifndef __SOFT_PWM_H_
#define __SOFT_PWM_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h> // uint8_t
//SFPWM_
//void escribir_pin(uint8_t pinvalue ){
// LATbits.RA0 = pinvalue;
//}
#define SFPWM_MAX_COUNTER 65535 /*!< MAXIMO VALOR TMR1*/
#define SFPWM_MAX_PERCENTAGE 100 /*!< MAXIMO VALOR*/
/**
* @brief pointer to function
* @param uint8_t output pin value
* @return void
**/
typedef void (*write_pin_fcn)(uint8_t ) ;
typedef struct {
volatile uint16_t count;
uint16_t dutyc;
write_pin_fcn write_pin;
uint16_t Tcomparar;
float frequency;
float basetime;
float period;
}SFPWM_private_t;
typedef struct {
uint8_t statepin;
SFPWM_private_t private;
}SFPWM_data_t;
/**
* @brief
*
* @param obj pointer to object pwm data
* @param _write_pin
* @param basetiming
* @param freq
*/
void SFPWM_Init(SFPWM_data_t *obj, write_pin_fcn _write_pin, float basetiming ,float freq );
/**
* @brief
*
* @param obj
*/
void SFPWM_Update(SFPWM_data_t *obj);
/**
* @brief
*
* @param obj pointer to object pwm data
* @return uint16_t pwm count ramp
*/
uint16_t SFPWM_GetCount(SFPWM_data_t *obj);
/**
* @brief get state pin
*
* @param obj pointer to object pwm data
* @return uint16_t 0 or 1
*/
uint16_t SFPWM_GetStatePin(SFPWM_data_t *obj);
/**
* @brief set duty cicle 0-100
*
* @param obj
* @param duty
*/
void SFPWM_SetDuty(SFPWM_data_t *obj , uint16_t duty);
#ifdef __cplusplus
}
#endif
#endif