mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
adc data test
This commit is contained in:
@@ -30,18 +30,18 @@ extern "C" {
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#define ADC_TIMES 100
|
||||
#define ADC_CHANELS 4
|
||||
#define ADC_TIMES 10
|
||||
#define ADC_CHANELS 5
|
||||
|
||||
typedef struct {
|
||||
uint8_t header[5];
|
||||
// 0x55, 0xAA header
|
||||
// 0x64 adc times, 0x05 adc channels (so data lenth is times * channels * 2 bytes)
|
||||
// 0x0A adc times, 0x05 adc channels (so data lenth is times * channels * 2 bytes)
|
||||
// and 1byte for direct & unit, 0x0? for positive, 0x1? for negative, 0x?0 for LOW, 0x?1 for MID, 0x?2 for HIGH.
|
||||
uint16_t data[ADC_TIMES][ADC_CHANELS]; // ADC 数据(真正要采集的地方)
|
||||
uint16_t data[ADC_TIMES][ADC_CHANELS]; // ADC 数据 ()
|
||||
} __attribute__((packed)) ADC_Packet;
|
||||
|
||||
extern ADC_Packet adc_packet1, adc_packet2;
|
||||
extern ADC_Packet adc_packet;
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
ADC_Packet adc_packet1, adc_packet2;
|
||||
ADC_Packet adc_packet;
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
@@ -54,7 +54,7 @@ void MX_ADC1_Init(void)
|
||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
|
||||
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.NbrOfConversion = 4;
|
||||
hadc1.Init.NbrOfConversion = 5;
|
||||
hadc1.Init.DMAContinuousRequests = ENABLE;
|
||||
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK)
|
||||
@@ -98,6 +98,15 @@ void MX_ADC1_Init(void)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_9;
|
||||
sConfig.Rank = 5;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
__HAL_DMA_ENABLE_IT(&hdma_adc1, DMA_IT_TC); /*开启DMA传输完成中断*/
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
@@ -123,13 +132,14 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
||||
PA6 ------> ADC1_IN6
|
||||
PA7 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
@@ -175,10 +185,11 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
||||
PA6 ------> ADC1_IN6
|
||||
PA7 ------> ADC1_IN7
|
||||
PB0 ------> ADC1_IN8
|
||||
PB1 ------> ADC1_IN9
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
||||
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0);
|
||||
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_0|GPIO_PIN_1);
|
||||
|
||||
/* ADC1 DMA DeInit */
|
||||
HAL_DMA_DeInit(adcHandle->DMA_Handle);
|
||||
|
||||
@@ -205,10 +205,10 @@ void DMA2_Stream0_IRQHandler(void)
|
||||
if(__HAL_DMA_GET_FLAG(&hdma_adc1, DMA_FLAG_TCIF0_4)) {
|
||||
__HAL_DMA_CLEAR_FLAG(&hdma_adc1, DMA_FLAG_TCIF0_4);
|
||||
HAL_ADC_Stop_DMA(&hadc1);
|
||||
// 填充帧头
|
||||
adc_packet1.header[4] = 0x10;
|
||||
HAL_UART_Transmit_DMA(&huart6, (uint8_t *)&adc_packet1, sizeof(adc_packet1));
|
||||
// HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buf1, ADC_TIMES * ADC_CHANELS);
|
||||
// 填充模式位
|
||||
adc_packet.header[4] = 0x10;
|
||||
HAL_UART_Transmit_DMA(&huart6, (uint8_t *)&adc_packet, sizeof(adc_packet));
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_packet.data, ADC_TIMES * ADC_CHANELS);
|
||||
}
|
||||
/* USER CODE END DMA2_Stream0_IRQn 0 */
|
||||
HAL_DMA_IRQHandler(&hdma_adc1);
|
||||
|
||||
@@ -49,18 +49,13 @@ void HardwareInitTask(void *argument)
|
||||
// HAL_UART_Transmit_DMA(&huart6,(uint8_t *)"power-pico\r\n",13);
|
||||
|
||||
// ADC
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_packet1.data, ADC_TIMES * ADC_CHANELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_packet.data, ADC_TIMES * ADC_CHANELS); /*启动ADC的DMA传输,配合定时器触发ADC转换 12位的ADC对应0-4095 */
|
||||
HAL_TIM_Base_Start(&htim2); /*开启定时器,用溢出时间来触发ADC*/
|
||||
|
||||
adc_packet1.header[0] = 0x55;
|
||||
adc_packet1.header[1] = 0xAA;
|
||||
adc_packet1.header[2] = ADC_TIMES;
|
||||
adc_packet1.header[3] = ADC_CHANELS;
|
||||
|
||||
adc_packet2.header[0] = 0x55;
|
||||
adc_packet2.header[1] = 0xAA;
|
||||
adc_packet1.header[2] = ADC_TIMES;
|
||||
adc_packet1.header[3] = ADC_CHANELS;
|
||||
adc_packet.header[0] = 0x55;
|
||||
adc_packet.header[1] = 0xAA;
|
||||
adc_packet.header[2] = ADC_TIMES;
|
||||
adc_packet.header[3] = ADC_CHANELS;
|
||||
|
||||
// gate, for current flow route selection, high current by default
|
||||
Gate_Port_Init();
|
||||
|
||||
Reference in New Issue
Block a user