summaryrefslogtreecommitdiff
path: root/project/Core/Src/adc_dac_demo.c
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-08-31 13:25:35 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-08-31 13:25:35 -0400
commit0ff718e7cd7159c30636aa323a666ac1af684f63 (patch)
tree247e13a76a15d3f826ba949a5a4d82b79a35e652 /project/Core/Src/adc_dac_demo.c
parent0f2ea7deaf0cba2f0ca07f6611c5a9e87d531f5b (diff)
download340-repo-Sowgro-0ff718e7cd7159c30636aa323a666ac1af684f63.tar.gz
340-repo-Sowgro-0ff718e7cd7159c30636aa323a666ac1af684f63.tar.bz2
340-repo-Sowgro-0ff718e7cd7159c30636aa323a666ac1af684f63.zip
Setup project
Diffstat (limited to 'project/Core/Src/adc_dac_demo.c')
-rw-r--r--project/Core/Src/adc_dac_demo.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/project/Core/Src/adc_dac_demo.c b/project/Core/Src/adc_dac_demo.c
new file mode 100644
index 0000000..5deff83
--- /dev/null
+++ b/project/Core/Src/adc_dac_demo.c
@@ -0,0 +1,48 @@
+/*
+ * adc_example.c
+ *
+ * Created on: Apr 13, 2022
+ * Author: bruce
+ */
+
+#include "adc.h"
+#include "dac.h"
+#include "adc_demo.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++;
+ }
+
+ }
+}
+