如题,有个工程需要用到定时器触发ADC采样多路数据(为了进行FFT),然后弄了好几天,资料看了,论坛也搜了,但是好像就是不行。 以下是我自己的代码,本意是ADC进过TB0触发转换两个通道的数据,但是,仿真的时候只能进第一个中断,求助是什么问题,
- void IntiSysSample(void) //ADC初始化
- {
- //设置ADC的GPIO DEMO是A1/P1.1 A7/P2.4
- GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,GPIO_PIN1,GPIO_TERNARY_MODULE_FUNCTION);
- GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P4,GPIO_PIN2,GPIO_TERNARY_MODULE_FUNCTION);
-
-
- //设置ADCB
- ADC12_B_init( ADC12_B_BASE,
- //ADC12_B_SAMPLEHOLDSOURCE_SC,
- ADC12_B_SAMPLEHOLDSOURCE_3,
- ADC12_B_CLOCKSOURCE_SMCLK,//ADC12_B_CLOCKSOURCE_ADC12OSC, //ADC模块时钟 参见库函数参数
- ADC12_B_CLOCKDIVIDER_1, //分频数
- ADC12_B_CLOCKPREDIVIDER__1, //分频数
- ADC12_B_NOINTCH);
- ADC12_B_enable(ADC12_B_BASE); //使能ADC
-
- ADC12_B_setupSamplingTimer(ADC12_B_BASE,
- ADC12_B_CYCLEHOLD_128_CYCLES, //ADC转换周期根据实际调整
- ADC12_B_CYCLEHOLD_4_CYCLES, //ADC转换周期根据实际调整
- ADC12_B_MULTIPLESAMPLESENABLE//ADC12_B_MULTIPLESAMPLESDISABLE //ADC12_B_MULTIPLESAMPLESDISABLE //ADC12_B_MULTIPLESAMPLESDISABLE 连续转换使能,多通道
- );
-
- ADC12_B_memoryConfigure(ADC12_B_BASE,
- ADC12_B_MEMORY_0,
- ADC12_B_INPUT_A1,
- ADC12_B_VREFPOS_INTBUF_VREFNEG_VSS,
- ADC12_B_NOTENDOFSEQUENCE,//ADC12_B_ENDOFSEQUENCE, //转换结束通道ADC12_B_NOTENDOFSEQUENCE
- ADC12_B_WINDOW_COMPARATOR_DISABLE,
- ADC12_B_DIFFERENTIAL_MODE_DISABLE);
-
- ADC12_B_memoryConfigure(ADC12_B_BASE,
- ADC12_B_MEMORY_1,
- ADC12_B_INPUT_A10,
- ADC12_B_VREFPOS_INTBUF_VREFNEG_VSS,
- ADC12_B_ENDOFSEQUENCE,//ADC12_B_ENDOFSEQUENCE, //转换结束通道ADC12_B_NOTENDOFSEQUENCE
- ADC12_B_WINDOW_COMPARATOR_DISABLE,
- ADC12_B_DIFFERENTIAL_MODE_DISABLE);
- //以下是使用TIMERB的TB0的CCR1触发ADC中断
- //P2.6/TB1 option select Output direction
- //TIMRB的TB0输出,用来触发ADC转换
- //GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN6,GPIO_PRIMARY_MODULE_FUNCTION);
- //Start timer
- TIMER_B_configureUpMode(TIMER_B0_BASE,
- TIMER_B_CLOCKSOURCE_SMCLK,
- TIMER_B_CLOCKSOURCE_DIVIDER_1,
- 511,
- TIMER_B_TBIE_INTERRUPT_DISABLE,
- TIMER_B_CCIE_CCR0_INTERRUPT_DISABLE,
- TIMER_B_DO_CLEAR
- );
- TIMER_B_startCounter(TIMER_B0_BASE,
- TIMER_B_UP_MODE
- );
- //Initialize compare mode to generate PWM1
- TIMER_B_initCompare(TIMER_B0_BASE,
- TIMER_B_CAPTURECOMPARE_REGISTER_1,
- TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE,
- TIMER_B_OUTPUTMODE_RESET_SET,
- 383
- );
- //最后开启ADC转换中断
- ADC12_B_clearInterrupt(ADC12_B_BASE,
- 0,
- ADC12_B_IFG0|ADC12_B_IFG1
- );
- //Enable memory buffer 0 interrupt
- ADC12_B_enableInterrupt(ADC12_B_BASE,
- ADC12_B_IE0|ADC12_B_IE1,
- 0,
- 0);
- __delay_cycles(75); // reference settling ~75us
-
- ADC12_B_startConversion(ADC12_B_BASE,ADC12_B_MEMORY_0,
- // ADC12_B_REPEATED_SINGLECHANNEL
- ADC12_B_REPEATED_SEQOFCHANNELS
- );
- __bis_SR_register(GIE);
- }
复制代码
- #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
- #pragma vector=ADC12_VECTOR
- __interrupt
- #elif defined(__GNUC__)
- __attribute__((interrupt(ADC12_VECTOR)))
- #endif
- void ADC12_ISR(void)
- {
-
- switch (__even_in_range(ADC12IV, 12)) {
- case 0: break; // Vector 0: No interrupt
- case 2: break; // Vector 2: ADC12BMEMx Overflow
- case 4: break; // Vector 4: Conversion time overflow
- case 6: break; // Vector 6: ADC12BHI
- case 8: break; // Vector 8: ADC12BLO
- case 10: break; // Vector 10: ADC12BIN
- case 12: // Vector 12: ADC12BMEM0 Interrupt
- if (ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0) >= 0x6B4)
- {
- //Set P1.0 LED on
- GPIO_setOutputHighOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }
- else {
- //Set P1.0 LED off
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
-
- }
- ADC12IFGR0 &= ~ADC12IFG0;
- // __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
- break; // Clear CPUOFF bit from 0(SR)
- case 14: {
- // __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
- if (ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_1) >= 0x6B4) {
- //Set P1.0 LED on
- GPIO_setOutputHighOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }else {
- //Set P1.0 LED off
- GPIO_setOutputLowOnPin(
- GPIO_PORT_P1,
- GPIO_PIN0
- );
- }
- ADC12IFGR1 &= ~ADC12IFG1;
- }break; // Vector 14: ADC12BMEM1
- case 16: break; // Vector 16: ADC12BMEM2
- case 18: break; // Vector 18: ADC12BMEM3
- case 20: break; // Vector 20: ADC12BMEM4
- case 22: break; // Vector 22: ADC12BMEM5
- case 24: break; // Vector 24: ADC12BMEM6
- case 26: break; // Vector 26: ADC12BMEM7
- case 28: break; // Vector 28: ADC12BMEM8
- case 30: break; // Vector 30: ADC12BMEM9
- case 32: break; // Vector 32: ADC12BMEM10
- case 34: break; // Vector 34: ADC12BMEM11
- case 36: break; // Vector 36: ADC12BMEM12
- case 38: break; // Vector 38: ADC12BMEM13
- case 40: break; // Vector 40: ADC12BMEM14
- case 42: break; // Vector 42: ADC12BMEM15
- case 44: break; // Vector 44: ADC12BMEM16
- case 46: break; // Vector 46: ADC12BMEM17
- case 48: break; // Vector 48: ADC12BMEM18
- case 50: break; // Vector 50: ADC12BMEM19
- case 52: break; // Vector 52: ADC12BMEM20
- case 54: break; // Vector 54: ADC12BMEM21
- case 56: break; // Vector 56: ADC12BMEM22
- case 58: break; // Vector 58: ADC12BMEM23
- case 60: break; // Vector 60: ADC12BMEM24
- case 62: break; // Vector 62: ADC12BMEM25
- case 64: break; // Vector 64: ADC12BMEM26
- case 66: break; // Vector 66: ADC12BMEM27
- case 68: break; // Vector 68: ADC12BMEM28
- case 70: break; // Vector 70: ADC12BMEM29
- case 72: break; // Vector 72: ADC12BMEM30
- case 74: break; // Vector 74: ADC12BMEM31
- case 76: break; // Vector 76: ADC12BRDY
- default: break;
- }
- }
复制代码- void main(void)
- {
- //Stop Watchdog Timer
- WDT_A_hold(WDT_A_BASE);
- SysClockInit();
- //Set P1.0 to output direction
- GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0);
-
- GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN0); //输出高
- PMM_unlockLPM5(); //调用IO口输出时需要此举
- IntiSysSample();
-
- while(1)
- {
- TestADCSplasss();
- }
- }
复制代码
一周热门 更多>