Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
AnalogOutput.h File Reference
#include "Output.h"
#include "../Utils/Constants.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
Include dependency graph for AnalogOutput.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AnalogOutput
 

Macros

#define TORQUE_LOW_MARGIN   2.0
 

Functions

void initAnalogOutput (AnalogOutput *analogoutput, const char *name, int hz, int channel)
 Initializes an analog output. More...
 
int writeAnalogOutputData (AnalogOutput *output, float data)
 Writes data to the analog output. More...
 

Variables

uint32_t dac1_buffer [DAC1_BUFFER_SIZE]
 
uint32_t dac2_buffer [DAC2_BUFFER_SIZE]
 

Macro Definition Documentation

◆ TORQUE_LOW_MARGIN

#define TORQUE_LOW_MARGIN   2.0

Function Documentation

◆ initAnalogOutput()

void initAnalogOutput ( AnalogOutput analogoutput,
const char *  name,
int  hz,
int  channel 
)

Initializes an analog output.

Parameters
outputPointer to the AnalogOutput structure to initialize
nameName of the output (string)
hzSampling frequency in Hertz
channelADC channel number for the output (0-16)

This function initializes the base output properties, sets the ADC channel, and configures the corresponding GPIO pin based on the channel number.

Definition at line 11 of file AnalogOutput.c.

11 {
12 initOutput(&analogOutput->output, name, hz, o_ANALOG);
13 analogOutput->channel = channel;
14 analogOutput->buffer_index = 0;
15}
@ o_ANALOG
Definition: Output.h:10
void initOutput(Output *output, const char *name, int hz, OutputType type)
Initializes an output with the given parameters.
Definition: Output.c:4
Here is the call graph for this function:

◆ writeAnalogOutputData()

int writeAnalogOutputData ( AnalogOutput output,
float  data 
)

Writes data to the analog output.

Parameters
outputPointer to the AnalogOutput structure.
dataData to write to the output.
Returns
int _SUCCESS or _FAILURE.

Definition at line 17 of file AnalogOutput.c.

17 {
18 #ifdef DEBUGn
19 printf("Writing data to analog output %s: %f\n", output->output.updateable.name, data);
20 #endif
21
22 if (output->channel == 1) {
23 // Write data to DAC1
24 dac1_buffer[output->buffer_index] = (int)data;
25 output->buffer_index = (output->buffer_index + 1) % DAC1_BUFFER_SIZE;
26 } else if (output->channel == 2) {
27 // Write data to DAC2
28 dac2_buffer[output->buffer_index] = (int)data;
29 output->buffer_index = (output->buffer_index + 1) % DAC2_BUFFER_SIZE;
30 } else {
31
32 #ifdef DEBUGn
33 printf("Invalid channel number for analog output %s\n", output->output.updateable.name);
34 #endif
35
36 return _FAILURE;
37 }
38 return _SUCCESS;
39}
uint32_t dac2_buffer[DAC2_BUFFER_SIZE]
Definition: main.c:117
uint32_t dac1_buffer[DAC1_BUFFER_SIZE]
Definition: main.c:116
#define _FAILURE
Definition: Common.h:6
#define _SUCCESS
Definition: Common.h:5
#define DAC1_BUFFER_SIZE
Definition: Constants.h:9
#define DAC2_BUFFER_SIZE
Definition: Constants.h:10
Output output
Definition: AnalogOutput.h:12
Updateable updateable
Definition: Output.h:15
char name[MAX_NAME_LENGTH]
Definition: Updateable.h:24

Variable Documentation

◆ dac1_buffer

uint32_t dac1_buffer[DAC1_BUFFER_SIZE]
extern

Definition at line 116 of file main.c.

◆ dac2_buffer

uint32_t dac2_buffer[DAC2_BUFFER_SIZE]
extern

Definition at line 117 of file main.c.