TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
ADC

Data Structures

struct  ADC_meas
 Container for ADC measurement results. More...

Functions

void ADC_init (void)
 Initialize the external memory–mapped ADC interface.
void ADC_start_conv (void)
 Start a conversion on the external ADC and wait for completion.
uint8_t ADC_read_ch (void)
 Read the current ADC channel sample.
void ADC_read_all (struct ADC_meas *output)
 Perform a full four-channel ADC conversion and return all results.
void ADC_test (void)
 Internal ADC test routine. (Currently disabled in implementation.).

Detailed Description

Function Documentation

◆ ADC_init()

void ADC_init ( void )

#include <adc.h>

Initialize the external memory–mapped ADC interface.

This prepares communication with the external ADC connected on the XMEM bus. All low-level XMEM configuration must already be handled elsewhere (e.g., via xmem_init()).

Definition at line 12 of file adc.c.

12 {
13
14 // XMEM controls the ADC and is enabled elsewhere (xmem_init())
15 // Do NOT touch DDR/PORTA (PORTA is the external data bus and is handeled
16 // trough writing to and reading to xmem) No need to set up PD6/PD7; XMEM
17 // controls WR/RD automatically when we read or write to memory allocted to
18 // the ADC
19}

Referenced by io_joystick_init().

◆ ADC_read_all()

void ADC_read_all ( struct ADC_meas * output)

#include <adc.h>

Perform a full four-channel ADC conversion and return all results.

Starts a conversion, then reads each channel sequentially with a small delay to satisfy ADC timing requirements.

Parameters
[out]outputPointer to a structure that will receive channel data.

Definition at line 36 of file adc.c.

36 {
37
39
40 volatile uint8_t adc_value[4];
41
42 // Send a pulse then read for each channel
43 for (uint8_t i = 0; i < 4; i++) {
44 _delay_ms(5);
45 adc_value[i] = ADC_read_ch();
46 output->channel[i] = adc_value[i];
47 }
48}
uint8_t ADC_read_ch(void)
Read the current ADC channel sample.
Definition adc.c:30
void ADC_start_conv(void)
Start a conversion on the external ADC and wait for completion.
Definition adc.c:21
uint8_t channel[4]
Definition adc.h:21

Referenced by io_joystick_read_position(), utils_joystick_print_pos(), and utils_joystick_print_raw().

◆ ADC_read_ch()

uint8_t ADC_read_ch ( void )

#include <adc.h>

Read the current ADC channel sample.

Reads a single byte from the ADC's memory-mapped interface.

Returns
The 8-bit ADC result of the currently selected channel.

Definition at line 30 of file adc.c.

30 {
31
32 // Read from any adress in ADC allocated memory adressarea to
33 return *ADC_BASE_ADR;
34}
#define ADC_BASE_ADR
Definition adc.c:10

Referenced by ADC_read_all().

◆ ADC_start_conv()

void ADC_start_conv ( void )

#include <adc.h>

Start a conversion on the external ADC and wait for completion.

Triggers a write strobe through the ADC's memory interface and waits for the BUSY flag (PD4) to clear.

Definition at line 21 of file adc.c.

21 {
22
23 // Write to any adress on ADC to trigger WR
24 *ADC_BASE_ADR = 0x00;
25 // Delay to ensure ADC conversion is done, checking BUSY pin insead.
26 while ((PORTD & PD4)) {
27 }
28}

Referenced by ADC_read_all().

◆ ADC_test()

void ADC_test ( void )

#include <adc.h>

Internal ADC test routine. (Currently disabled in implementation.).

Prints ADC values for channels 0–3 via UART.