AVRly - AVR Development Resources
main.c
Go to the documentation of this file.
1/******************************************************************************
2 @copyright Copyright © 2022 by Jason Duffy.
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21******************************************************************************/
22
23/**
24 * @file main.c
25 * @ingroup mcp48x2
26 * @author Jason Duffy
27 * @date 1st March 2022
28 * @brief Example main routine demonstrating the mcp48x2 DAC driver.
29 * @bug No known bugs.
30 */
31
32#include <util/delay.h>
33#include "mcp48x2_dac.h"
34
35// Edit these values to modify the demo behaviour.
36#define DELAY_TIME_1 1000
37
38#define CHANNEL_A_VOLTAGE_1 1000
39#define CHANNEL_B_VOLTAGE_1 2000
40
41#define CHANNEL_A_VOLTAGE_2 3300
42#define CHANNEL_B_VOLTAGE_2 1650
43
44
45/**
46 * Instantiation of config object for DAC.
47 */
49{
50 .model = mcp4812,
51 .sync_manually = false,
52
53 .channel_a.gain_low = false,
54 .channel_a.active = true,
55 .channel_a.level = 0,
56
57 .channel_b.gain_low = false,
58 .channel_b.active = true,
59 .channel_b.level = 0,
60};
61
62/**
63 * Main routine of application.
64 */
65int main()
66{
67 // Initialisation of DAC is called here.
69
70 // Loop forever.
71 while (1)
72 {
73 // Set initial voltage levels.
74 dac_set_voltage(DAC_CHANNEL_A, CHANNEL_A_VOLTAGE_1);
75 dac_set_voltage(DAC_CHANNEL_B, CHANNEL_B_VOLTAGE_1);
76
77 // Wait a short time.
78 _delay_ms(DELAY_TIME_1);
79
80 // Set secondary voltage levels.
81 dac_set_voltage(DAC_CHANNEL_A, CHANNEL_A_VOLTAGE_2);
82 dac_set_voltage(DAC_CHANNEL_B, CHANNEL_B_VOLTAGE_2);
83
84 // Wait a short time.
85 _delay_ms(DELAY_TIME_1);
86 }
87
88 return 0;
89}
int main()
Main routine to be executed on the MCU.
Definition: main.c:45
void dac_set_voltage(bool channel_a, uint16_t millivolts)
Sends a new millivolts value to be output on DAC (Along with config settings).
Definition: mcp48x2_dac.c:145
void init_dac(dac_config_t *p_config)
Initialisation routine (run once at startup).
Definition: mcp48x2_dac.c:89
Driver for the MCP4812 10 bit DAC (digital to analog converter) chip.
dac_config_t dac_config
Instantiation of config object for DAC.
Definition: main.c:48
Config struct for DAC.
Definition: mcp48x2_dac.h:76