USB HID Joystick & Problem in ADC4

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

USB HID Joystick & Problem in ADC4

958件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketfuel on Wed Jul 23 09:10:59 MST 2014
Hello everyone, I am new working with LPC1769 and Xpresso board Rev C. I succesfully developed an USB HID Joystick with 8 axis & 32 buttons working fine but I have a problem only with ADC4. I test every single ADC using a Pot and im reading correct values from 0 to 4095 but when I touch ADC4 with the wire the device disconnects. This is my code:

unsigned int AdcData[8];

#define ADC_POWERON (1<<12)
#define PCLK_ADC 24
#define PCLK_ADC_MASK (3<<24)

#define SELECT_ADC0 (1<<14)
#define SELECT_ADC1 (1<<16)
#define SELECT_ADC2 (1<<18)
#define SELECT_ADC3 (1<<20)
#define SELECT_ADC4 (3<<28)
#define SELECT_ADC5 (3<<30)
#define SELECT_ADC6 (2<<6)
#define SELECT_ADC7 (2<<4)

// ADOCR constants
#define START_ADC (1<<24)
#define OPERATIONAL_ADC (1<<21)
#define SEL_AD0 (1<<0)
#define SEL_AD1 (1<<1)
#define SEL_AD2 (1<<2)
#define SEL_AD3 (1<<3)
#define SEL_AD4 (1<<4)
#define SEL_AD5 (1<<5)
#define SEL_AD6 (1<<6)
#define SEL_AD7 (1<<7)
#define ADC_DONE_BIT (1<<31)

//=======================================================================================
void ConfigADC(void)
{
LPC_SC->PCONP |=  ADC_POWERON;// Turn on power to ADC block

LPC_SC->PCLKSEL0 &= ~(PCLK_ADC_MASK);// Turn on ADC peripheral clock
LPC_SC->PCLKSEL0 |=  (3 << PCLK_ADC);

LPC_PINCON->PINSEL1|= SELECT_ADC0;// Set P0.23 to AD0.0 in PINSEL1
LPC_PINCON->PINSEL1|= SELECT_ADC1;// Set P0.24 to AD0.1 in PINSEL1
LPC_PINCON->PINSEL1|= SELECT_ADC2;// Set P0.25 to AD0.2 in PINSEL1
LPC_PINCON->PINSEL1|= SELECT_ADC3;// Set P0.26 to AD0.3 in PINSEL1
LPC_PINCON->PINSEL3|= SELECT_ADC4;// Set P1.30 to AD0.4 in PINSEL3
LPC_PINCON->PINSEL3|= SELECT_ADC5;// Set P1.31 to AD0.5 in PINSEL3
LPC_PINCON->PINSEL0|= SELECT_ADC6;// Set P0.3  to AD0.6 in PINSEL0
LPC_PINCON->PINSEL0|= SELECT_ADC7;// Set P0.2  to AD0.7 in PINSEL0
}
//=======================================================================================
void ADC(unsigned int SelectADC, unsigned int Channel)
{

    LPC_ADC->ADCR = START_ADC | OPERATIONAL_ADC | SelectADC;

    do
    {
    AdcData[Channel] = LPC_ADC->ADGDR;            // Read A/D Data Register
    }
    while ((AdcData[Channel] & ADC_DONE_BIT) == 0); // Wait for end of A/D Conversion

    LPC_ADC->ADCR &= ~(START_ADC | OPERATIONAL_ADC | SelectADC);  // Stop A/D Conversion

    AdcData[Channel] = (AdcData[Channel] >> 4) & 0x0FFF ;    // Extract value - 12 bit result in bits [15:4]
}
//=======================================================================================

In main loop:

ADC(SEL_AD0,0);
ADC(SEL_AD1,1);
ADC(SEL_AD2,2);
ADC(SEL_AD3,3);
ADC(SEL_AD4,4);
ADC(SEL_AD5,5);
ADC(SEL_AD6,6);
ADC(SEL_AD7,7);

I know my code isnt the best way to do things, im working on it...

Cant figure out the where the problem is.

Any help would be much appreciated. Thanks in advance.

ラベル(1)
0 件の賞賛
返信
1 返信

880件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketfuel on Wed Jul 23 18:11:42 MST 2014
Hi again. After several hours without figuring out what the problem was, I finally solved it by changing the order of two functions:

USBInit();
ConfigADC();

instead of:

ConfigADC();
USBInit();

Seems like USBInit configures that pin as input to check power supply and causes device reset when I plug in the pot. If somebody can confirm this would be much appreciated. I took USB HID from exaples folder to start this project, then I added ADC functionality.
0 件の賞賛
返信