Reply
Posts: 54
Registered: ‎09-06-2017
Accepted Solution

Correct ADC configuration for joystick?

I am trying to get the joystick working on the BRD8006A expansion board. I have configured the ADC as follows:

Screen Shot 2017-09-07 at 23.13.47.png

Screen Shot 2017-09-07 at 23.13.59.png

 

Reading ADC:

 

ADC_Start(ADC0, adcStartSingle);
while ((ADC0->IF & ADC_IF_SINGLE) == 0)
 ;

/* Get ADC single result */
uint32_t sample = ADC_DataSingleGet(ADC0);

The value of sample ranges from 55190 (center) to 65218 (no input)

 

The problem is that SW and SE are indistinguishable, both around 65114. Both vary while being held in that position. Am I doing something wrong?

Posts: 563
Registered: ‎09-18-2015

Re: Correct ADC configuration for joystick?

Hi @nickb,

 

Have you looked at the schematic for BRD8006A? It actually lists the voltages you should expect to read in each direction.

 

John

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Sure. I am new to the platform though. I don't know the best settings for the ADC to read those voltages. The ADC readings I am getting from the current configuration do not provide enough accuracy to differentiate between SE and SW.

Posts: 563
Registered: ‎09-18-2015

Re: Correct ADC configuration for joystick?

Couple of other things:

 

  1. What STK are you using?
  2. Why are you oversampling? You don't need oversampling to use the joystick, so just try single 8- or 12-bit conversions for now.

 

John

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Sure. I am new to the platform though. I don't know the best settings for the ADC to read those voltages. The ADC readings I am getting from the current configuration do not provide enough accuracy to differentiate between SE and SW.

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

BRD4001A rev A01. Not sure if that's the code you are looking for.

 

I'm using oversampling because I couldn't differentiate between readings for SE and SW.

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Oversampling doesn't really help, as the samples from SE and SW still vary and overlap. Without oversampling the readings for SE and SW are both around 4070.

Posts: 2,326
Registered: ‎10-14-2014

Re: Correct ADC configuration for joystick?


check the voltage output of joystick with multimeter to confirm if this is firmware issue.
WeiguoLu
Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

The voltage between joystick and ground when the center button is pressed is 2.78v. I am guessing this means the board is faulty?

Posts: 2,326
Registered: ‎10-14-2014

Re: Correct ADC configuration for joystick?

I don't know which joystick component the BRD8006 was using.

You could see the EFM8UB1 STK use circuit like attached cicuit.png for joystick.

And you could see the voltage level is like attached voltage.png

That's the reason I suggest you measure the voltage first when the joystick in different position.

WeiguoLu
Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

In the BGM111 board user guide the voltage table for the joystick is as attached. So I think my expansion board is faulty, should I contact tech support for a replacement?

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

I actually have a second BRD4001A and BRD8006A here, and it produces just the same results, so this is not a faulty hardware issue. The voltage measured at JOYSTICK does not match the documentation, and as the voltage range is far smaller this makes SE and SW indistinguishable, indeed my voltmeter reads the same. Please advise.

Highlighted
Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Resistance between JOYSTICK and GND when center is pressed is 100 Ohms which I think is correct, and the resistance between JOYSTICK and VMCU is 10 kOhms. This suggests something is holding the pin high. I see the pin is labelled UART TX on the STK, but I am not using UART.

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

I managed to fix the ADC – the pin needs disabling. When a pin is disabled in hardware configurator it does not set it to disabled in InitDevice.c. It seems like that is a bug in hardware configurator for all pins, but especially when ADC is configured for a pin it should add the code to disable the pin.

GPIO_PinModeSet(gpioPortA, 0, gpioModeDisabled, 0);
Posts: 563
Registered: ‎09-18-2015

Re: Correct ADC configuration for joystick?

Hi @nickb,

 

Not sure if you are aware of this, but pins are disabled by default out of reset and thus immediately available for analog functions.

 

You will find the Pin Configuration section of the GPIO chapter in the Blue Gecko Reference Manual very helpful with this.

 

Hardware Configurator is working correctly. It only configures a pin if you select any function for it other than disabled. There's no need to force the pin to be disabled for analog when you're just coming out of reset.

 

John

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

This wasn’t the case. The pin is disabled in configurator, but that didn’t generate a function call to disable the pin, and reading the pin mode returns PushPull. I’m not setting that, so unless it is being set by other code in the template/retargetio/retargetswo/glib then it seems like the default.
Posts: 563
Registered: ‎09-18-2015

Re: Correct ADC configuration for joystick?

@nickb,

 

All GPIOs are disabled by default.

 

I’m not setting that, so unless it is being set by other code in the template/retargetio/retargetswo/glib then it seems like the default.

 

You've mentioned elsewhere that you are using BGM111, and since you seem to have a WSTK, that would tell me that you've also most likely got a BRD4300A radio board.

 

If you check the schematic, you'll see that PA0 is used for the VCOM TX pin. So, if you are using the VCOM functionality (connecting the designated USART to the WSTK board controller such that it appears under Windows as a virtual COM port), the pin would have to be configured as an output.

 

Any chance you are calling RETARGET_SerialInit()?

 

If so, this would be why PA0 is getting configured as an output, which also means you can't use the VCOM functionality and the joystick board at the same time.

 

John

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

After placing GPIO_PinModeGet in a few places I found

  • Initially at the start of main() the mode is 1 (Input)
  • After calling enter_DefaultMode_from_RESET the mode is 0 (Disabled)
  • After calling graphInit("") the mode is 4 (PushPull)

So it is glib setting it to PushPull.

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Specifically,

PAL_GpioPinModeSet(LCD_PORT_DISP_SEL, LCD_PIN_DISP_SEL, palGpioModePushPull, 0);

On line 165 of displayls013b7dh03.c

 

The display continues to work after this pin is disabled so I'm not sure if this is required.

Posts: 563
Registered: ‎09-18-2015

Re: Correct ADC configuration for joystick?

You need to look at the WSTK motherboard schematic (BRD4001A).

 

This is the output goes to a mux that switches the displays inputs between the board controller and the EFR32.

 

There is a pull-down on the pin, so if you reconfigure this pin as an input, the display will be switched to the board controller, and you will no longer be able to write to the display. It will retain whatever was previously written to it, so you could, conceivably, switch back and forth on the WSTK.

 

You haven't bothered to tell us what board you are using. All of the different BGM radio boards I looked at use PA0 for VCOM_TX. DISPLAY_ENABLE is PD15 across those boards that support the display, so I'm not sure why the display driver would be touching PA0.

 

John

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Yes I am using BRD4300A with BGM111.

 

I have included the same files as the soc-smartPhone example which uses the display. That includes displayls013b7dh03.c. displayls013b7dh03.h has the definition

#define LCD_PORT_DISP_SEL         (0)  /* = gpioPortF */
#define LCD_PIN_DISP_SEL          (0)

 

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Yes PA0 is labelled UART TX. I have no idea why the driver is using it for the display

Posts: 3,100
Registered: ‎02-07-2002

Re: Correct ADC configuration for joystick?


nickb wrote:

 

#define LCD_PORT_DISP_SEL         (0)  /* = gpioPortF */

This should worry you. The value 0 and the comment gpioPortF do not match!

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

I know. I’m not sure it is supposed to be defined at all. It’s in the SDK.
Posts: 563
Registered: ‎09-18-2015

Re: Correct ADC configuration for joystick?

We seem to have a bug in our SDK here.

 

@nickb caught the relevant code in the LS013B7DH03 driver (line 156):

 

 

#if defined(LCD_PORT_DISP_SEL)
  PAL_GpioPinModeSet(LCD_PORT_DISP_SEL, LCD_PIN_DISP_SEL, palGpioModePushPull, 0);
#endif

 

As you can see, this is conditional if LCD_PORT_DISP_SEL is #defined, which it is in C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v1.1\hardware\kit\EFR32BG1_BRD4300A\config\displayls013b7dh03config.h:

 

 

/* LCD and SPI GPIO pin connections on the SLWSTK6020A_EFR32BG. */
#define LCD_PORT_SCLK             (2)  /* = gpioPortC */
#define LCD_PIN_SCLK              (8)
#define LCD_PORT_SI               (2)  /* = gpioPortC */
#define LCD_PIN_SI                (6)
#define LCD_PORT_SCS              (3)  /* = gpioPortD */
#define LCD_PIN_SCS              (14)
#define LCD_PORT_EXTCOMIN         (3)  /* = gpioPortD */
#define LCD_PIN_EXTCOMIN         (13)
#define LCD_PORT_DISP_SEL         (0)  /* = gpioPortF */
#define LCD_PIN_DISP_SEL          (0)
#define LCD_PORT_DISP_PWR         (3)  /* = gpioPortD */
#define LCD_PIN_DISP_PWR         (15)

 

The thing is, it shouldn't be #defined. If you look in the display driver config for a related device, say the EFR32MG1 on BRD4151A, you'll find it's not there.

 

Furthermore, if you look at the schematic for BRD4300A, there is no DISP_SEL signal:

 

brd4300a.png

 

So, this is why @nickb's joystick doesn't work as expected. He's using the display, and we are inadvertently configuring PA0 when it should only be configured on BRD4300A if you are using the VCOM functionality.

 

I'll see about putting in a fix for this since it's pretty simple and something I can't mess up Smiley Happy Watch for it in a future SDK release.

 

John

Posts: 54
Registered: ‎09-06-2017

Re: Correct ADC configuration for joystick?

Thanks John