2367 views|1 replies

1

Posts

0

Resources
The OP
 

MSP430 seems unable to enter interrupt, no output can be observed [Copy link]

I want to make a program that samples through the MSP430F169 on-chip ADC and outputs through the on-chip DAC. I have referred to some books, but now the DAC can output normally, but the ADC cannot determine whether it has not collected the signal or has not entered the interrupt to output the program. The code is as follows: #include "io430.h" #include "dac12.h" typedef unsigned char uchar; typedef unsigned int uint; //typedef unsigned int result0; #define Num_of_Results 15 static uint results[Num_of_Results]; //Array to save ADC conversion results void ADC_Init(void); /************************Main function****************************/ void main(void) { WDTCTL = WDTPW+WDTHOLD; //Turn off the watchdog/*The following six lines of program turn off all IO ports*/ P1DIR = 0XFF;P1OUT = 0XFF; P2DIR = 0XFF;P2OUT = 0XFF; P3DIR = 0XFF;P3OUT = 0XFF; P4DIR = 0XFF;P4OUT = 0XFF; P5DIR = 0XFF;P5OUT = 0XFF; P6DIR = 0XFF;P6OUT = 0X00; ADC_Init(); InitDac12(); GoDac12(100,0); //Open DAC12 channel 0 GoDac12(100,1); //Open DAC12 channel 1 Dac12Write(0xFFF,1); //Dac12Write(0x0FF,0); while (1) { ADC12CTL0 |= ADC12SC; // Start sampling/conversion ADC12CTL0 |= ENC; __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit __no_operation(); // For debugger } } #pragma vector=ADC_VECTOR __interrupt void ADC12ISR (void) { static uint index = 0; results[index++] = ADC12MEM0; // Move results if(index == Num_of_Results) { uchar i; unsigned long sum = 0; index = 0; for(i = 0; i < Num_of_Results; i++) { sum += results[i]; } sum =sum/Num_of_Results; //Divide by 15 Dac12Write(sum,0); } __bic_SR_register _on_exit(LPM0_bits); } /************************************************ Function name: ADC_Init ********************************************/ void ADC_Init(void) { ADC12CTL0 &= ~ENC; P6SEL |= 0x01; ADC12CTL0 = ADC12ON+SHT0_4+MSC+REFON+REF2_5V; ADC12CTL1 = SHP +CONSEQ_2; ADC12MCTL0 = INCH_0; ADC12IE = 0x01; } /*******************************Configure DAC************************/ #include "io430.h" #include "dac12.h" void InitDac12() { //ADC12CTL0 = REF2_5V + REFON; //Turn on internal reference voltage source, reference voltage is 2.5V //Set DAC12 channel 0 //Full scale is reference voltage, medium speed/current output, 12-bit resolution, Vref is reference voltage, refresh output immediately DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC + DAC12LSEL_1; DAC12_0CTL |= DAC12CALON; //Automatically calibrate DA output //Set DAC12 channel 1 //Full scale is 3 times of reference voltage, medium speed/current output, 12-bit resolution, Vref is reference voltage, refresh output immediately DAC12_1CTL = DAC12IR + DAC12AMP_5 + DAC12ENC +DAC12LSEL_1; DAC12_1CTL |= DAC12CALON; //Automatically calibrate DA output //Wait for calibration to end while(DAC12_0CTL & DAC12CALON == DAC12CALON); while(DAC12_1CTL & DAC12CALON == DAC12CALON); } /************************************************** Turn DAC12 on or off doit: 0--off; 100: run which: turn on or off. 0--DAC0; 1--DAC1; **********************************************/ void GoDac12(unsigned char doit,unsigned char which) { if(doit == 0) //Turn off DAC12 { if(which == 0) DAC12_0CTL &= ~DAC12ENC; else DAC12_1CTL &= ~DAC12ENC; } else if(doit == 100) //Turn on DAC12 { if(which == 0) DAC12_0CTL |= DAC12ENC; else DAC12_1CTL |= DAC12ENC; } } /************************************************** Write output value dat: value to be output, ready to be written to DA data register which: which channel to write to. 0--DAC0; 1--DAC1; **********************************************/ void Dac12Write(unsigned int dat, unsigned char which) { if(which == 0) DAC12_0DAT = dat; else DAC12_1DAT = dat; }

This post is from Microcontroller MCU

Latest reply

Check the configuration again  Details Published on 2019-4-14 19:39
 

1140

Posts

0

Resources
2
 
Check the configuration again
This post is from Microcontroller MCU
 
 

Guess Your Favourite
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list