blob: 46b10f56e623690b9b7661727b5d3a38a50e487c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/*
* adc_example.c
*
* Created on: Apr 13, 2022
* Author: bruce
*/
#include "adc.h"
#include "dac.h"
#include "adc_demo.h"
#include "systick.h"
uint8_t one_second_elapsed = FALSE;
uint32_t counter = 0;
/***
* Demo uses the ADC to read the values set by the DAC.
*
* For the project, you will not use the ADC.
*/
void run_adc_dac_demo()
{
uint16_t counter = 0;
// printf ("Start!\n\r");
init_systick();
DAC_Init ();
ADC_Init ();
DAC_Start ();
uint32_t adc_value = 0;
while (1)
{
if (one_second_elapsed /*&& (old_adc_value != new_adc_value)*/) {
ADC_Start ();
adc_value = ADC_Read_Value_Blocking ();
// printf ("ADC read: 0x%x\n\r", (unsigned int)adc_value);
// Rediculous way to eliminate warning. Delete this line when printf is working.
adc_value = adc_value;
// Let power count up in a cycle. This is to make reading it more interesting.
DAC_Set_Value ((counter) % 0x1000);
counter++;
}
}
}
|