interrupt void adc_isr(void);
// Global variables used in this example:
Uint16 LoopCount;
Uint16 ConversionCount;
Uint16 Frequence;//5,10,15,20,25,30,35,40,45,50Hz:
Uint16 Voltage; //30,49,66,88,110,154,176,180,220v:
void DSP281x_ADCIO(void)
{
InitAdc(); // For this example, init the ADC
// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
LoopCount = 0;
ConversionCount = 0;
// Configure ADC:start/stop mode
AdcRegs.ADCMAXCONV.all = 0x0000; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCTRL2.bit.EXT_SOC_SEQ1 = 1; // Enable EXTSOC to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Wait for ADC interrupt
while(1)
{
LoopCount++;
}
}
interrupt void adc_isr(void) // interrupt :Keyword
{
Frequence =(Uint16)((AdcRegs.ADCRESULT0 >>6)/81.6);//Input the Frequence
Voltage =(Uint16)(4.4*Frequence);//Acorrding with VVVF curve get the voltage
// If 40 conversions have been logged, start over
if(ConversionCount == 1)
{
ConversionCount = 0;
}
else ConversionCount++;
// Reinitialize for next ADC sequence
AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE
return;
}
|