TI中文支持网
TI专业的中文技术问题搜集分享网站

求助,关于用到两个通道采样的问题

用的是430F5529开发板

我用一路通道对外部输入的信号进行采样,寄存器设置如下

P6SEL |= BIT7;// Enable A/D channel A7ADC12CTL0 = ADC12ON+ADC12SHT0_2+ADC12MSC;// Turn on ADC12, set sampling time, set multiple sample conversionADC12CTL1 = ADC12CONSEQ_2+ADC12SHP+ADC12CSTARTADD_7;// Use sampling timer, set mode,Repeat-single-channelADC12MCTL7 = ADC12INCH_7;				//channel = A7ADC12IE = BIT7;// Enable ADC12IFG.7ADC12CTL0 |= ADC12ENC;// Enable conversionsADC12CTL0 |= ADC12SC;// Start conversion
ADC12中断中的内容如下:
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{switch(__even_in_range(ADC12IV,34)){case  0: break;// Vector  0:  No interruptcase  2: break;// Vector  2:  ADC overflowcase  4: break;// Vector  4:  ADC timing overflowcase  6: break;		// Vector  6:  ADC12IFG0case  8: break;// Vector  8:  ADC12IFG1case 10: break;// Vector 10:  ADC12IFG2case 12: break;// Vector 12:  ADC12IFG3case 14: break;// Vector 14:  ADC12IFG4case 16: break;// Vector 16:  ADC12IFG5case 18: break;// Vector 18:  ADC12IFG6case 20: results[index] = ADC12MEM7;// Move resultsindex++;// Increment results index, modulo; Set Breakpoint1 hereif (index == 408){ADC12IE = 0x00;// Disable ADC12IFG.7flag=1;index = 0;}							// Vector 20:  ADC12IFG7case 22: break;// Vector 22:  ADC12IFG8case 24: break;// Vector 24:  ADC12IFG9case 26: break;// Vector 26:  ADC12IFG10case 28: break;// Vector 28:  ADC12IFG11case 30: break;// Vector 30:  ADC12IFG12case 32: break;// Vector 32:  ADC12IFG13case 34: break;// Vector 34:  ADC12IFG14default: break;}
}

另外我想用TI提供的齿轮电位计的程序来调节,关于齿轮电位计的程序如下:

#include "msp430.h"
#include "HAL_Wheel.h"

#define WHEEL_PORT_DIR P8DIR
#define WHEEL_PORT_OUT P8OUT
#define WHEEL_ENABLE  BIT0
#define ADC_PORT_SEL  P6SEL
#define ADC_INPUT_A5  BIT5

uint16_t positionData;
uint16_t positionDataOld;

/***************************************************************************//**
 * @briefSet up the wheel
 * @paramNone
 * @return  None
 ******************************************************************************/

void Wheel_init(void)
{WHEEL_PORT_DIR |= WHEEL_ENABLE;WHEEL_PORT_OUT |= WHEEL_ENABLE;// Enable wheelADC12CTL0 = ADC12SHT02 + ADC12ON;// Sampling time, ADC12 onADC12CTL1 = ADC12SHP;// Use sampling timerADC12MCTL0 = ADC12INCH_5;// Use A5 (wheel) as inputADC12CTL0 |= ADC12ENC;// Enable conversionsADC_PORT_SEL |= ADC_INPUT_A5;// P6.5 ADC option select (A5)
}

/***************************************************************************//**
 * @briefDetermine the wheel's position
 * @paramNone
 * @return  Wheel position (0~7)
 ******************************************************************************/

uint8_t Wheel_getPosition(void)
{uint8_t position = 0;Wheel_getValue();//determine which position the wheel is inif (positionData > 0x0806)position = 7 - (positionData - 0x0806) / 260;  //scale the data for 8 different positionselseposition = positionData / 260;return position;
}

/***************************************************************************//**
 * @briefDetermine the raw voltage value across the potentiometer
 * @paramNone
 * @return  Value
 ******************************************************************************/

uint16_t Wheel_getValue(void)
{//measure ADC valueADC12IE = 0x01;// Enable interruptADC12CTL0 |= ADC12SC;// Start sampling/conversion__bis_SR_register(LPM0_bits + GIE);// LPM0, ADC12_ISR will force exitADC12IE = 0x00;// Disable interrupt//add hysteresis on wheel to remove fluctuationsif (positionData > positionDataOld)if ((positionData - positionDataOld) > 10)positionDataOld = positionData;//use new data if change is beyond// fluctuation thresholdelsepositionData = positionDataOld;//use old data if change is not beyond// fluctuation thresholdelseif ((positionDataOld - positionData) > 10)positionDataOld = positionData;//use new data if change is beyond// fluctuation thresholdelsepositionData = positionDataOld;//use old data if change is not beyond// fluctuation thresholdreturn positionData;
}

/***************************************************************************//**
 * @briefDisable wheel
 * @paramNone
 * @return  none
 ******************************************************************************/

void Wheel_disable(void)
{WHEEL_PORT_OUT &= ~WHEEL_ENABLE;//disable wheelADC12CTL0 &= ~ADC12ENC;// Disable conversionsADC12CTL0 &= ~ADC12ON;// ADC12 off
}

/***************************************************************************//**
 * @briefEnable wheel
 * @paramNone
 * @return  none
 ******************************************************************************/

void Wheel_enable(void)
{WHEEL_PORT_OUT |= WHEEL_ENABLE;//disable wheelADC12CTL0 |= ADC12ON;// ADC12 onADC12CTL0 |= ADC12ENC;// Enable conversions
}

/***************************************************************************//**
 * @brief Handles ADC interrupts.
 *
 *Stores result of single ADC conversion for reading position of the scroll wheel.
 * @param  none
 * @return none
 ******************************************************************************/

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{switch (__even_in_range(ADC12IV, ADC12IV_ADC12IFG15)){// Vector  ADC12IV_NONE:  No interruptcase  ADC12IV_NONE:break;// Vector  ADC12IV_ADC12OVIFG:  ADC overflowcase  ADC12IV_ADC12OVIFG:break;// Vector  ADC12IV_ADC12TOVIFG:  ADC timing overflowcase  ADC12IV_ADC12TOVIFG:break;// Vector  ADC12IV_ADC12IFG0: ADC12IFG0:case  ADC12IV_ADC12IFG0:positionData = ADC12MEM0;// ADC12MEM = A0 > 0.5AVcc?__bic_SR_register_on_exit(LPM0_bits);// Exit active CPUbreak;// Vector  ADC12IV_ADC12IFG1:  ADC12IFG1case  ADC12IV_ADC12IFG1:break;// Vector ADC12IV_ADC12IFG2:  ADC12IFG2case ADC12IV_ADC12IFG2:break;// Vector ADC12IV_ADC12IFG3:  ADC12IFG3case ADC12IV_ADC12IFG3:break;// Vector ADC12IV_ADC12IFG4:  ADC12IFG4case ADC12IV_ADC12IFG4:break;// Vector ADC12IV_ADC12IFG5:  ADC12IFG5case ADC12IV_ADC12IFG5:break;// Vector ADC12IV_ADC12IFG6:  ADC12IFG6case ADC12IV_ADC12IFG6:break;// Vector ADC12IV_ADC12IFG7:  ADC12IFG7case ADC12IV_ADC12IFG7:break;// Vector ADC12IV_ADC12IFG8:  ADC12IFG8case ADC12IV_ADC12IFG8:break;// Vector ADC12IV_ADC12IFG9:  ADC12IFG9case ADC12IV_ADC12IFG9:break;// Vector ADC12IV_ADC12IFG10:  ADC12IFG10case ADC12IV_ADC12IFG10:break;// Vector ADC12IV_ADC12IFG11:  ADC12IFG11case ADC12IV_ADC12IFG11:break;// Vector ADC12IV_ADC12IFG12:  ADC12IFG12case ADC12IV_ADC12IFG12:break;// Vector ADC12IV_ADC12IFG13:  ADC12IFG13case ADC12IV_ADC12IFG13:break;// Vector ADC12IV_ADC12IFG14:  ADC12IFG14case ADC12IV_ADC12IFG14:break;// Vector ADC12IV_ADC12IFG15:  ADC12IFG15case ADC12IV_ADC12IFG15:break;default:break;}
}

我尝试了很多方法,经常就是齿轮电位计采样不了,这两个AD如何才能融合在一起?

kqian0327:

你好,

请问两个不同通道的采样率不一样还是什么情况?

按我的理解,如果你需要采两个通道你可以选择单次触发多次采样不就ok了?

还是你的应用比较特殊?

xinyi chen:

回复 kqian0327:

你好,

采样率不一样,也不同时进行,齿轮电位计不是一直采。

单次触发多次采样怎么设置?

赞(0)
未经允许不得转载:TI中文支持网 » 求助,关于用到两个通道采样的问题
分享到: 更多 (0)