diff Small_CPU/Src/scheduler.c @ 554:3328189786e7

Added external ADC interface functionality (MCP3424): Added communication protocoll to read data from external ADC. At the moment 16bit and 18bit resolutions are supported. External data will be read and forwarded depending on the conversion time of the ADC.
author Ideenmodellierer
date Thu, 12 Nov 2020 19:46:03 +0100
parents 9eeab3fead8f
children 5149cd644fbc
line wrap: on
line diff
--- a/Small_CPU/Src/scheduler.c	Sun Nov 08 18:49:54 2020 +0100
+++ b/Small_CPU/Src/scheduler.c	Thu Nov 12 19:46:03 2020 +0100
@@ -41,6 +41,7 @@
 #include "stm32f4xx_hal_rtc_ex.h"
 #include "decom.h"
 #include "tm_stm32f4_otp.h"
+#include "externalInterface.h"
 
 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */
 /* #define RESTORE_LAST_KNOWN_DATE */
@@ -88,6 +89,7 @@
 void copyVpmCrushingData(void);
 void copyDeviceData(void);
 void copyPICdata(void);
+void copyExtADCdata();
 static void schedule_update_timer_helper(int8_t thisSeconds);
 uint32_t time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow);
 
@@ -454,6 +456,7 @@
 {
 	uint32_t ticksdiff = 0; 
 	uint32_t lasttick = 0;
+	uint8_t extAdcChannel = 0;
 	uint8_t counterAscentRate = 0;
 	float lastPressure_bar = 0.0f;
 	global.dataSendToMaster.mode = MODE_DIVE;
@@ -491,6 +494,13 @@
 				Scheduler.counterSPIdata100msec++;
 			}
 			schedule_check_resync();
+
+			extAdcChannel = externalInterface_ReadAndSwitch();
+			if(extAdcChannel != EXTERNAL_ADC_NO_DATA)
+			{
+				externalInterface_CalculateADCValue(extAdcChannel);
+				copyExtADCdata();
+			}
 		}
 
 		//Evaluate pressure at 20 ms, 120 ms, 220 ms,....
@@ -754,6 +764,7 @@
 
 	uint32_t ticksdiff = 0; 
 	uint32_t lasttick = 0;
+	uint8_t extAdcChannel = 0;
 	Scheduler.tickstart = HAL_GetTick();
 	Scheduler.counterSPIdata100msec = 0;
 	Scheduler.counterCompass100msec = 0;
@@ -784,6 +795,12 @@
 				Scheduler.counterSPIdata100msec++;
 			}
 			schedule_check_resync();
+			extAdcChannel = externalInterface_ReadAndSwitch();
+			if(extAdcChannel != EXTERNAL_ADC_NO_DATA)
+			{
+				externalInterface_CalculateADCValue(extAdcChannel);
+				copyExtADCdata();
+			}
 		}
 
 		/* Evaluate pressure at 20 ms, 120 ms, 220 ms,... duration ~22ms] */
@@ -1606,6 +1623,19 @@
 	global.dataSendToMaster.boolPICdata = boolPICdata;
 }
 
+void copyExtADCdata()
+{
+	float value;
+
+	uint8_t channel = 0;
+
+	for(channel = 0; channel < MAX_ADC_CHANNEL; channel++)
+	{
+		value = getExternalInterfaceChannel(channel);
+		global.dataSendToMaster.data[0].extADC_voltage[channel] = value;
+	}
+}
+
 
 typedef enum 
 {