[ST NUCLEO-U575ZI-Q Review] + Multi-channel ADC data acquisition
[Copy link]
In the rheological analyzer, the detection of temperature, pressure, torque and speed is involved. The temperature and pressure both require ADC for data collection, while the speed detection requires pulse counting per unit time. As for the torque detection, ADC can be used for data collection, or it can be realized by pulse counting per unit time.
Therefore, it can be seen that multi-channel ADC data acquisition is very important.
The routines provided by the manufacturer include a single-channel ADC data acquisition example, which uses channel 9 and occupies pin PA4.
Figure 1 Pin Function
So how do we open more data collection channels?
Through data query, other data acquisition channels are shown in Figure 2. For this purpose, channel 7 and channel 8 corresponding to pins PA2 and PA3 are selected for use, thus making up 3 data acquisition channels.
Figure 2 Other acquisition channels
By adding a serial digital tube module, the collected data can be displayed in real time.
The initialization function of acquisition channel 9 is:
static void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.GainCompensation = 0;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc1.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc1.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc1.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_391CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
The main program for data collection and display is:
int main(void)
{
uint16_t u;
HAL_Init();
SystemClock_Config();
SystemPower_Config();
MX_GPIO_Init();
MX_ICACHE_Init();
MX_ADC1_Init();
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
app_MAX7219();
Init_MAX7219();
Write_Max7219(1,0);
Write_Max7219(2,0);
Write_Max7219(3,0);
Write_Max7219(4,0);
Write_Max7219(5,15);
Write_Max7219(6,15);
Write_Max7219(7,15);
Write_Max7219(8,15);
while (1)
{
if (HAL_ADC_Start_IT(&hadc1) != HAL_OK)
{
Error_Handler();
}
while (ubAdcGrpRegularUnitaryConvStatus != 1);
ubAdcGrpRegularUnitaryConvStatus = 0;
u=uhADCxConvertedData_Voltage_mVolt;
Write_Max7219(1,u%10);
Write_Max7219(2,u%100/10);
Write_Max7219(3,u%1000/100);
Write_Max7219(4,u/1000);
HAL_Delay(500);
}
}
After the program is compiled and downloaded, its running effects are shown in Figures 3 to 5.
Figure 3 Random signal acquisition results
Figure 4 Collection results when grounding
Figure 5: Acquisition results when connected to VCC
This completes the data acquisition of the specified channel and converts the acquisition result into power (mV) for display. If you are acquiring data from multiple channels, you only need to rotate the acquisition channel during the acquisition process.
Taking the specified data acquisition channel 7 as an example, the statement is:
sConfig.Channel = ADC_CHANNEL_7;
It can be replaced with ADC_CHANNEL_8 and ADC_CHANNEL_9 to change the detection channel.
In the rheological analyzer, the detection of temperature, pressure and torque is achieved by obtaining 4~20mA current signals through the corresponding transmitters, and then converting them into 0~5V voltage signals through the current/voltage conversion module and connecting them to the three data acquisition channels. Of course, corresponding numerical conversion processing is required to display the corresponding physical quantity values, which will not be introduced in detail here.
|