hztov 2.0.0.0
hztov.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef HZTOV_H
36#define HZTOV_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_pwm.h"
55#include "drv_analog_in.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define HZTOV_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69 cfg.vo = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS )
77#define HZTOV_RETVAL uint8_t
78
79#define HZTOV_OK 0x00
80#define HZTOV_INIT_ERROR 0xFF
87#define HZTOV_DEF_FREQ 5000
94#define HZTOV_ENABLE 1
95#define HZTOV_DISABLE 0
96
103#define HZTOV_MAX_FREQ 10000
104#define HZTOV_MIN_FREQ 1000
105
108 // End group macro
109// --------------------------------------------------------------- PUBLIC TYPES
118typedef uint16_t hztov_data_t;
119
123typedef struct
124{
125 // Output pins
126
127 digital_out_t en;
128
129 // Modules
130
131 pwm_t pwm;
132 analog_in_t adc;
133
134 // ctx variable
135
136 uint32_t pwm_freq;
137
138} hztov_t;
139
143typedef struct
144{
145 // Communication gpio pins
146
147 pin_name_t pwm;
148 pin_name_t vo;
149
150 // Additional gpio pins
151
152 pin_name_t en;
153
154 // static variable
155
156 analog_in_resolution_t resolution; // Resolution
157 float vref; // VRef
158 uint32_t dev_pwm_freq;
160
161 // End types group
162// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163
169#ifdef __cplusplus
170extern "C"{
171#endif
172
182
191
201
211
220void hztov_set_enable ( hztov_t *ctx, uint8_t state );
221
231void hztov_set_duty_cycle ( hztov_t *ctx, float duty_cycle );
232
241
250
259void hztov_set_input_frequency ( hztov_t *ctx, uint16_t freq );
260
261#ifdef __cplusplus
262}
263#endif
264#endif // _HZTOV_H_
265
266 // End public_function group
268
269// ------------------------------------------------------------------------- END
#define HZTOV_RETVAL
Definition hztov.h:77
void hztov_cfg_setup(hztov_cfg_t *cfg)
Config Object Initialization function.
float hztov_read_voltage(hztov_t *ctx)
Read voltage function.
HZTOV_RETVAL hztov_init(hztov_t *ctx, hztov_cfg_t *cfg)
Initialization function.
void hztov_set_duty_cycle(hztov_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void hztov_pwm_start(hztov_t *ctx)
Start PWM module.
void hztov_set_enable(hztov_t *ctx, uint8_t state)
Set enable pin state.
void hztov_pwm_stop(hztov_t *ctx)
Stop PWM module.
hztov_data_t hztov_generic_read(hztov_t *ctx)
Generic read function.
void hztov_set_input_frequency(hztov_t *ctx, uint16_t freq)
Changing the output voltage function.
uint16_t hztov_data_t
Analog data type.
Definition hztov.h:118
Click configuration structure definition.
Definition hztov.h:144
analog_in_resolution_t resolution
Definition hztov.h:156
float vref
Definition hztov.h:157
uint32_t dev_pwm_freq
Definition hztov.h:158
pin_name_t en
Definition hztov.h:152
pin_name_t vo
Definition hztov.h:148
pin_name_t pwm
Definition hztov.h:147
Click ctx object definition.
Definition hztov.h:124
uint32_t pwm_freq
Definition hztov.h:136
digital_out_t en
Definition hztov.h:127
analog_in_t adc
Definition hztov.h:132
pwm_t pwm
Definition hztov.h:131