You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 regels
1.2 KiB

  1. /*****************Í·Îļþ*************************/
  2. #include "fsl_common.h"
  3. #include "fsl_port.h"
  4. #include "fsl_gpio.h"
  5. #include "adc_Interrupt.h"
  6. #include "fsl_adc16.h"
  7. uint32_t g_Adc16ConversionValue = 0;
  8. uint32_t g_Adc16Count = 0;
  9. /*****************ADC³õʼ»¯*************************/
  10. void ADC16_InterrputInit() //ADC³õʼ»¯
  11. {
  12. adc16_config_t adc16ConfigStruct;
  13. adc16_channel_config_t adc16ChannelConfigStruct;
  14. EnableIRQ(ADC0_IRQn);
  15. ADC16_GetDefaultConfig(&adc16ConfigStruct);
  16. adc16ConfigStruct.enableContinuousConversion = true;
  17. ADC16_Init(ADC0, &adc16ConfigStruct);
  18. ADC16_EnableHardwareTrigger(ADC0, false); /* Make sure the software trigger is used. */
  19. adc16ChannelConfigStruct.channelNumber = 2u;
  20. adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = true; /* Enable the interrupt. */
  21. ADC16_SetChannelConfig(ADC0, 0u, &adc16ChannelConfigStruct);
  22. }
  23. uint32_t adc_ReturnValue()
  24. {
  25. return g_Adc16ConversionValue;
  26. }
  27. void ADC0_IRQHandler(void)
  28. {
  29. /* Read conversion result to clear the conversion completed flag. */
  30. g_Adc16ConversionValue = ADC16_GetChannelConversionValue(ADC0, 0u);
  31. g_Adc16Count++;
  32. g_Adc16Count %= 1000;
  33. SDK_ISR_EXIT_BARRIER;
  34. }