【iCore4 双核心板_ARM】例程九:ADC实验——电源监控

实验原理:  

  STM32内部集成三个12位ADC,iCore1S的所有电源经过电阻分压或者直接

接入STM32的ADC的输出通道内,输入电流经过高端电流检测芯片ZXCT1009F

输入到ADC的输入通道内,从而实现电源监控功能。

核心代码:

int main(void)
{

  /* USER CODE BEGIN 1 */
  int i;
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC3_Init();
  MX_USART6_UART_Init();

  /* USER CODE BEGIN 2 */
  usart6.initialize(115200);
    LED_GREEN_ON;
    usart6.printf("\x0c");                                                                                             
    usart6.printf("\033[1;32;40m");                                     
    usart6.printf(" Hello, I am iCore4!\r\n");    
    
  /* USER CODE END 2 */

 
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
        LED_GREEN_ON;
        HAL_Delay(500);
        LED_GREEN_OFF;
 
        for(i = 0;i < 5;i ++){
            my_adc.read(i);
        }
      
        usart6.printf(" ");
        usart6.printf("[I] %3.0fmA , ",my_adc.value[0] / 2* 1000.);
        usart6.printf("[V] %4.2fV, ",my_adc.value[1] * 6.);
        usart6.printf("[3.3V] %4.2fV, ",my_adc.value[2] * 2.);
        usart6.printf("[2.5V] %4.2fV,",my_adc.value[3] * 2.);
        usart6.printf("[1.2V] %4.2fV\r",my_adc.value[4]);

  }
  /* USER CODE END 3 */

}

源代码下载链接:

链接:http://pan.baidu.com/s/1co5BdG 密码:1x87

iCore4链接:

 

posted @ 2017-08-18 09:51  XiaomaGee  阅读(615)  评论(0编辑  收藏  举报