PWM触发
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2019 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
//***********************************************************************************************************
// Website: http://www.nuvoton.com
// E-Mail : MicroC-8bit@nuvoton.com
//***********************************************************************************************************
//***********************************************************************************************************
// File Function: ML51 ADC GPIO tirg demo code
//***********************************************************************************************************
#include "ML51.h"
/******************************************************************************
* FUNCTION_PURPOSE: ADC interrupt Service Routine
******************************************************************************/
void ADC_ISR (void) interrupt 11
{
clr_ADCCON0_ADCF; //clear ADC interrupt flag
printf ("\n PWM trig ADC = 0x%bx",ADCRH);
}
/******************************************************************************
The main C function. Program execution starts
here after stack initialization.
******************************************************************************/
void main ()
{
MFP_P31_UART0_TXD;
P31_QUASI_MODE;
UART_Open(24000000,UART0_Timer1,115200);
ENABLE_UART0_PRINTF;
/*-------------------------------------------------------------------------------
ADC trig by PWM channel 0 falling edge
Step 1: Setting P2.5 as PWM0 channel 0 output
Step 2: Enable ADC channel 1 P2.4 input hardware trigger by PWM0 channel0 and FALLING EDGE trig
Step 3: Enable ADC AIN0
--------------------------------------------------------------------------------*/
// PWM initial setting
MFP_P25_PWM0_CH0; //setting P2.5 multi function pin as GPIO
P25_PUSHPULL_MODE; //setting P2.5 GPIO as output mode
PWM0_ConfigOutputChannel(0,Independent,EdgeAligned,0x6FF,10); //setting PWM0 channel 0 output
PWM0_RUN();
// ADC initial setting
ADC_EnableHWTrigger(ADC_HWT_PWM0CH0, ADC_HWT_FALLINGEDGE,0); //Enable ADC hardware trigger by PWM0 channel 0 FALLING EDGE trig
ADC_Open(ADC_SINGLE,1); //Enable ADC AIN0
ADC_Interrupt(Enable,ADC_INT_SINGLE); //Enable ADC interrupt
ENABLE_GLOBAL_INTERRUPT; //Enable global interrupt
/* find ADC result in ADC interrupt*/
while(1); // Wait GPIO trig and ADC interrupt to check result
}
|