完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我用的芯片是MSP430FR5994,使用的是库函数 void Ad_init(void)
int main(void)
// ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0, ADC12_B_SINGLECHANNEL);
// __delay_cycles(5000);
// GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN0);
} /*
*/ // param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_SC;
/*
ADC12_B_enable(ADC12_B_BASE); } //*****************************************************************************
/
*/ /*
/
// Timer_A_startCounter( TIMER_A0_BASE, TIMER_A_UP_MODE ); } TIME 我实验了 COMPARE PWM 各种方式,而且P0.1 信号也出来了,但是AD的中断就是进不去 |
|
相关推荐
2个回答
|
|
//***************************************************************************** // * main.c // ****************************************************************************** int main(void) { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer PMM_unlockLPM5(); CS_init(); IO_Init(); Timer_Init(); Ad_init(); while(1) { // ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0, ADC12_B_SINGLECHANNEL); //LPM0, ADC12_A_ISR will force exit __bis_SR_register(LPM0_bits + GIE); //for Debugger __no_operation(); GPIO_setOutputLowOnPin(GPIO_PORT_P2,GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0); } return 0; } //***************************************************************************** // * main.c // ****************************************************************************** void CS_init() { // Set PJ.4 and PJ.5 as Secondary Module Function Input, LFXT. /* Initializes Clock System DCO = 8MHz */ CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3); CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 ); CS_initClockSignal(CS_ACLK, CS_VLOCLK_SELECT, CS_CLOCK_DIVIDER_1); } //***************************************************************************** // * main.c // ****************************************************************************** void Ad_init(void) { ADC12_B_initParam param1 = {0}; ADC12_B_configureMemoryParam param = {0}; GPIO_setAsPeripheralModuleFunctionOutputPin( GPIO_PORT_P3, GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3, GPIO_TERNARY_MODULE_FUNCTION ); // param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_SC; param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_1; param1.clockSourceSelect=ADC12_B_CLOCKSOURCE_MCLK; param1.clockSourceDivider=ADC12_B_CLOCKDIVIDER_1; param1.clockSourcePredivider=ADC12_B_CLOCKPREDIVIDER__1; param1.internalChannelMap=ADC12_B_NOINTCH; ADC12_B_init(ADC12_B_BASE,¶m1); ADC12_B_setupSamplingTimer(ADC12_B_BASE, ADC12_B_CYCLEHOLD_64_CYCLES, ADC12_B_CYCLEHOLD_4_CYCLES, ADC12_B_MULTIPLESAMPLESENABLE); param.memoryBufferControlIndex = ADC12_B_MEMORY_0; param.inputSourceSelect = ADC12_B_INPUT_A12; param.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS; param.endOfSequence = ADC12_B_NOTENDOFSEQUENCE; param.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE; param.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE; ADC12_B_configureMemory(ADC12_B_BASE ,¶m); ADC12_B_clearInterrupt(ADC12_B_BASE,ADC12IFG0,0); ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12IE0,0,0); ADC12_B_enable(ADC12_B_BASE); } //***************************************************************************** // * main.c // ****************************************************************************** void Timer_Init(void) { /* Timer_A_initUpModeParam htim = {0}; htim.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; // // htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_2; // htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32; // htim.timerPeriod = TIMER_PERIOD - 1; // htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE; // // htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; // htim.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE; // htim.timerClear = TIMER_A_DO_CLEAR; // htim.timerClear = TIMER_A_SKIP_CLEAR; // htim.startTimer = false; // Timer_A_initUpMode(TIMER_A0_BASE, &htim); */ /* Timer_A_initContinuousModeParam initContParam = {0}; Timer_A_initUpModeParam Param={0}; initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; initContParam.timerInterruptEnable_TAIE=TIMER_A_TAIE_INTERRUPT_ENABLE; initContParam.timerClear=TIMER_A_DO_CLEAR; initContParam.startTimer = true; Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam); */ /* //Start timer in continuous mode sourced by SMCLK Timer_A_initContinuousModeParam initContParam = {0}; initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; initContParam.timerClear = TIMER_A_DO_CLEAR; initContParam.startTimer = false; Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam); //Initiaze compare mode Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_0 ); */ /* Timer_A_initCompareModeParam initCompParam = {0}; initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE; // initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE; initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_TOGGLE; // initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET; initCompParam.compareValue = 10; Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam); */ Timer_A_outputPWMParam htim1 = {0}; htim1.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; htim1.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32; htim1.timerPeriod = TIMER_PERIOD - 1; htim1.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; htim1.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET; htim1.dutyCycle = TIMER_PERIOD / 2 ; Timer_A_outputPWM(TIMER_A0_BASE, &htim1); // Timer_A_startCounter( TIMER_A0_BASE, TIMER_A_UP_MODE ); } //***************************************************************************** // * main.c // ****************************************************************************** void IO_Init(void) { GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); GPIO_setAsOutputPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); // GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN0); GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7); // GPIO_setAsInputPin(GPIO_PORT_P1,GPIO_PIN0); GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,GPIO_PIN0,GPIO_PRIMARY_MODULE_FUNCTION); } 刚才代码贴错了 |
|
|
|
//***************************************************************************** // * main.c // ****************************************************************************** #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 g_usAdcData[0]= ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0); __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU break; // Clear CPUOFF bit from 0(SR) case 14: 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; } } //****************************************************************************** // //This is the TIMER1_A3 interrupt vector service routine. // //****************************************************************************** #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=TIMER0_A1_VECTOR __interrupt #elif defined(__GNUC__) __attribute__((interrupt(TIMER0_A1_VECTOR))) #endif void TIMER0_A1_ISR (void) { switch(TA0IV) { case TA0IV_NONE: break; case TA0IV_TACCR1: GPIO_toggleOutputOnPin( GPIO_PORT_P2, GPIO_PIN1 ); break; case TA0IV_TACCR2: break; case TA0IV_5: break; case TA0IV_6: break; case TA0IV_TAIFG: //Toggle P1.0 GPIO_toggleOutputOnPin( GPIO_PORT_P2, GPIO_PIN1 ); break; default: break; } } |
|
|
|
只有小组成员才能发言,加入小组>>
2916个成员聚集在这个小组
加入小组2667 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
2972 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2260 浏览 1 评论
4687 浏览 1 评论
2473 浏览 1 评论
929浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
2972浏览 2评论
2668浏览 1评论
1061浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-20 02:09 , Processed in 1.245283 second(s), Total 79, Slave 63 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号