指定adc通道2

上传人:kms****20 文档编号:40162197 上传时间:2018-05-24 格式:DOC 页数:5 大小:26KB
返回 下载 相关 举报
指定adc通道2_第1页
第1页 / 共5页
指定adc通道2_第2页
第2页 / 共5页
指定adc通道2_第3页
第3页 / 共5页
指定adc通道2_第4页
第4页 / 共5页
指定adc通道2_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《指定adc通道2》由会员分享,可在线阅读,更多相关《指定adc通道2(5页珍藏版)》请在金锄头文库上搜索。

1、指定指定 ADCADC 通道通道 2 22#include “DSP28x_Project.h“ / Device Headerfile and Examples Include File/ Prototype statements for functions found within this file.interrupt void adc_isr(void);/ Global variables used in this example:Uint16 LoopCount;Uint16 ConversionCount;Uint16 Voltage110;Uint16 Voltage210;m

2、ain()/ Step 1. Initialize System Control:/ PLL, WatchDog, enable Peripheral Clocks/ This example function is found in the DSP2833x_SysCtrl.c file.InitSysCtrl();EALLOW;#if (CPU_FRQ_150MHZ) / Default - 150 MHz SYSCLKOUT#define ADC_MODCLK 0x3 / HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz#en

3、difEDIS;/ Step 2. Initialize GPIO:/ This example function is found in the DSP2833x_Gpio.c file and/ illustrates how to set the GPIO to its default state./ InitGpio(); / Skipped for this example/ Step 3. Clear all interrupts and initialize PIE vector table:/ Disable CPU interruptsDINT;/ Initialize th

4、e PIE control registers to their default state./ The default state is all PIE interrupts disabled and flags/ are cleared./ This function is found in the DSP2833x_PieCtrl.c file.InitPieCtrl();/ Disable CPU interrupts and clear all CPU interrupt flags:IER = 0x0000;IFR = 0x0000;/ Initialize the PIE vec

5、tor table with pointers to the shell Interrupt/ Service Routines (ISR)./ This will populate the entire table, even if the interrupt/ is not used in this example. This is useful for debug purposes./ The shell ISR routines are found in DSP2833x_DefaultIsr.c./ This function is found in DSP2833x_PieVect

6、.c.InitPieVectTable();/ Interrupts that are used in this example are re-mapped to/ ISR functions found within this file.EALLOW; / This is needed to write to EALLOW protected registerPieVectTable.ADCINT = EDIS; / This is needed to disable write to EALLOW protected registers/ Step 4. Initialize all th

7、e Device Peripherals:/ This function is found in DSP2833x_InitPeripherals.c/ InitPeripherals(); / Not required for this exampleInitAdc(); / For this example, init the ADCCpuTimer0Regs.TCR.all = 0x4001;/ Step 5. User specific code, enable interrupts:/ Enable ADCINT in PIEPieCtrlRegs.PIEIER1.bit.INTx6

8、 = 1;IER |= M_INT1; / Enable CPU Interrupt 1EINT; / Enable Global interrupt INTMERTM; / Enable Global realtime interrupt DBGMLoopCount = 0;ConversionCount = 0;/ Configure ADCEALLOW;AdcRegs.ADCMAXCONV.all = 0x0001; / Setup 2 convs on SEQ1AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x1; / Setup ADCINA1 as 1st S

9、EQ1 conv.AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x2; / Setup ADCINA2 as 2nd SEQ1 conv.AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;/ Enable SOCA from ePWM to start SEQ1AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; / Enable SEQ1 interrupt (every EOS)EDIS;/ Assumes ePWM1 clock is already enabled in InitSysCtrl();EPwm1Re

10、gs.ETSEL.bit.SOCAEN = 1; / Enable SOC on A groupEPwm1Regs.ETSEL.bit.SOCASEL = 4; / Select SOC from from CPMA on upcountEPwm1Regs.ETPS.bit.SOCAPRD = 1; / Generate pulse on 1st eventEPwm1Regs.CMPA.half.CMPA = 0x0080; / Set compare A valueEPwm1Regs.TBPRD = 0xFFFF; / Set period for ePWM1EPwm1Regs.TBCTL.

11、bit.CTRMODE = 0; / count up and start/ Wait for ADC interruptfor(;)LoopCount+;interrupt void adc_isr(void)Voltage1ConversionCount = (AdcRegs.ADCRESULT0 4);Voltage2ConversionCount = (AdcRegs.ADCRESULT1 4);/ If 40 conversions have been logged, start overif(ConversionCount = 9)ConversionCount = 0;else ConversionCount+;/ Reinitialize for next ADC sequenceAdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; / Reset SEQ1AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; / Clear INT SEQ1 bitPieCtrlRegs.PIEACK.all = PIEACK_GROUP1; / Acknowledge interrupt to PIEreturn;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号