AVRly - AVR Development Resources
main.c File Reference

Example main routine demonstrating the mcp48x2 DAC driver. More...

#include <util/delay.h>
#include "mcp48x2_dac.h"

Go to the source code of this file.

Macros

#define DELAY_TIME_1   1000
 
#define CHANNEL_A_VOLTAGE_1   1000
 
#define CHANNEL_B_VOLTAGE_1   2000
 
#define CHANNEL_A_VOLTAGE_2   3300
 
#define CHANNEL_B_VOLTAGE_2   1650
 

Functions

int main ()
 Main routine of application. More...
 

Variables

dac_config_t dac_config
 Instantiation of config object for DAC. More...
 

Detailed Description

Example main routine demonstrating the mcp48x2 DAC driver.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Author
Jason Duffy
Date
1st March 2022

Definition in file main.c.

Macro Definition Documentation

◆ DELAY_TIME_1

#define DELAY_TIME_1   1000

Definition at line 36 of file main.c.

◆ CHANNEL_A_VOLTAGE_1

#define CHANNEL_A_VOLTAGE_1   1000

Definition at line 38 of file main.c.

◆ CHANNEL_B_VOLTAGE_1

#define CHANNEL_B_VOLTAGE_1   2000

Definition at line 39 of file main.c.

◆ CHANNEL_A_VOLTAGE_2

#define CHANNEL_A_VOLTAGE_2   3300

Definition at line 41 of file main.c.

◆ CHANNEL_B_VOLTAGE_2

#define CHANNEL_B_VOLTAGE_2   1650

Definition at line 42 of file main.c.

Function Documentation

◆ main()

int main ( )

Main routine of application.

Definition at line 65 of file main.c.

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}
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
dac_config_t dac_config
Instantiation of config object for DAC.
Definition: main.c:48

Variable Documentation

◆ dac_config

dac_config_t dac_config
Initial value:
=
{
.model = mcp4812,
.sync_manually = false,
.channel_a.gain_low = false,
.channel_a.active = true,
.channel_a.level = 0,
.channel_b.gain_low = false,
.channel_b.active = true,
.channel_b.level = 0,
}

Instantiation of config object for DAC.

Definition at line 48 of file main.c.