Helpful ReplyHot!Harmony touch expectations

Author
bblessing
Super Member
  • Total Posts : 679
  • Reward points : 0
  • Joined: 2008/12/04 06:44:21
  • Location: Cincinnati, OH
  • Status: offline
2017/07/18 08:56:46 (permalink)
0

Harmony touch expectations

Background: MPLAB X IDE 3.65, XC32 v1.43, Harmony v2.03b, custom board using PIC32MZ2064DAH176, Newhaven NHD-4.3-480272EF-ASXN#-T display (4.3", 480x272 pixel, 4 wire resitive touchscreen)
 
I have a simple question regarding the touchscreen calibration and basic orientation. With 0° orientation, i.e. none, can I assume that the top left corner of the screen is (0, 0)? The orientation is identical to that of the screen pictured here: (look for Newhaven's product page for NHD-4.3-480272EF-ASXN#-T). I wired up the device as follows (Newhaven side | PIC side):
 
XR = X+ (100k pullup here)
YD = Y+ (100k pullup here)
XL = X-
YU = Y-
 
I don't totally understand Newhaven's convention and how it translates to Microchip, however let's set that aside for the moment. My question: should the scaled A/D readings follow the pixel values?
 
The calibration points are at the following (in pixels, going from upper left->upper right->lower right->lower left):
 
Upper left: (48,27)
Upper right: (431,27)
Lower right: (431,244)
Lower left: (48,244)
 
This assumes an inset factor of 20.
 
The raw readings are essentially just 10 bit count values, so they'll read from 0-1023. Practically speaking, when I press on the corners of the screen (not THE corners, but near the cal points) I'll get readings ranging from 160 to about 870 for x and y depending on where I'm pressing. So, in my case, should example raw values look like this:
 
Upper left: (160, 160)
Upper right: (870,160)
Lower right: (870,870)
Lower left: (160,870)
 
Do you see what I'm getting at now? Is it absolutely the case that raw x values increase from left to right and raw y values increase from top to bottom in accordance with pixel values? I believe this to be the case, as I've found that I should transpose my X and Y settings. That is, for a Newhaven display like mine, the following should be the wiring:
 
XR = Y+ (100k pullup here)
YD = X+ (100k pullup here)
XL = Y-
YU = X-
#1
bblessing
Super Member
  • Total Posts : 679
  • Reward points : 0
  • Joined: 2008/12/04 06:44:21
  • Location: Cincinnati, OH
  • Status: offline
Re: Harmony touch expectations 2017/07/19 12:14:05 (permalink)
0
I'm such a moron. What I stated above is correct with regards to the wiring diagram, including the assumptions. What happened was that I used my BSP from my older project as some settings were still valid. Unfortunately, one of those settings that hung around was in my bsp.h.ftl file:
 
TOUCHSCREEN_RESISTIVE_SWAP_XY
 
That was useful for the 10 bit adc driver, but not the touch_adc driver. However, it nicely screwed up what went into the upper layers. Everything works perfectly now.

That having been said, are there plans to actually add a ready made touch calibration routine? I vaguely recall seeing something about that.
#2
Bradnz
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2011/11/23 15:22:15
  • Location: 0
  • Status: offline
Re: Harmony touch expectations 2017/12/17 16:17:41 (permalink)
0
Great to hear you are actually getting some ADC touch readings using Harmony V2, that is further than I have managed to get.
 
How do you tell harmony which ADC pins the 4 resistive touch wires are connected to?
 
When I select the touch ADC driver and generate some code using harmony I get a heap of build errors. A lot of them are just the X and Y plus and minus pins, ports and pin masks haven't been defined. I can fix this by manually defining them as shown in the http://www.microchip.com/forums/m923202.aspx forum thread.
 
However there are several instances where there are missing expression to do with the ADC
i.e. if ( !PLIB_ADCHS_AnalogInputDataIsReady(DRV_ADC_ID_1, ) )
#3
bblessing
Super Member
  • Total Posts : 679
  • Reward points : 0
  • Joined: 2008/12/04 06:44:21
  • Location: Cincinnati, OH
  • Status: offline
Re: Harmony touch expectations 2017/12/18 07:03:13 (permalink) ☄ Helpfulby jcandle 2018/01/10 20:18:29
0
I did have to edit drv_touch_adc.c.ft here: C:\microchip\harmony\v2_04\framework\driver\touch\touch_adc\templates. The reason for that was because I used class 1 inputs (AN0 and AN1). Below are my settings in my .mhc file. Perhaps you can glean something from it. Mind you, those are just the relevant snippets.
 
 
CONFIG_USE_DRV_ADC=y
#
# from $HARMONY_VERSION_PATH\framework\driver\adc\config\drv_adchs.hconfig
#
CONFIG_DRV_ADCHS_DRIVER_MODE="STATIC"
CONFIG_DRV_ADCHS_INTERRUPT_MODE=n
CONFIG_DRV_ADCHS_POLLED_MODE=y
CONFIG_DRV_ADCHS_CHARGEPUMP_MODE="ADCHS_CHARGEPUMP_DISABLE"
CONFIG_DRV_ADCHS_FAST_SYNC_SYSTEM_CLOCK="ADCHS_FAST_SYNC_SYSTEM_CLOCK_DISABLE"
CONFIG_DRV_ADCHS_FAST_SYNC_PERIPHERAL_CLOCK="ADCHS_FAST_SYNC_PERIPHERAL_CLOCK_DISABLE"
CONFIG_DRV_ADCHS_OUTPUT_DATA_FORMAT="ADCHS_OUTPUT_DATA_FORMAT_INTEGER"
CONFIG_DRV_ADC_VOLTAGE_REFERENCE_ADCHS="ADCHS_VREF_AVDD_AVSS"
CONFIG_DRV_ADCHS_CLOCK_SOURCE="ADCHS_CLOCK_SOURCE_PBCLK"
CONFIG_DRV_ADCHS_CLOCK_DIVIDER=1
CONFIG_DRV_ADCHS_WARMUP_CLOCK="ADCHS_WARMUP_CLOCK_32768"
CONFIG_DRV_ADCHS_CHANNEL_NUMBER=6
#
# from $HARMONY_VERSION_PATH\framework\driver\adc\config\drv_adchs_channel_idx.ftl
#
CONFIG_DRV_ADCHS_CHANNEL_INST_IDX0=y
CONFIG_DRV_ADCHS_CHANNEL_ID_IDX0="ADCHS_CHANNEL_0"
CONFIG_DRV_ADCHS_CHNL_0_ALT_INP_SEL_IDX0="ADCHS_DEFAULT_CLASS1_AN0"
CONFIG_DRV_ADCHS_ANALOG_INPUT_LEVEL_TRIGGER_IDX0=n
CONFIG_DRV_ADCHS_TRIGGER_SOURCE_IDX0="ADCHS_TRIGGER_SOURCE_GLOBAL_SOFTWARE_EDGE"
CONFIG_DRV_ADCHS_INPUT_MODE_IDX0="ADCHS_INPUT_MODE_SINGLE_ENDED_UNIPOLAR"
CONFIG_DRV_ADCHS_DATA_RESOLUTION_SELECT_IDX0="ADCHS_DATA_RESOLUTION_12BIT"
CONFIG_DRV_ADCHS_CHANNEL_CLOCK_DIVIDER_IDX0=32
CONFIG_DRV_ADCHS_SAMPLE_TIME_COUNT_IDX0=1023
CONFIG_DRV_ADCHS_TRIGGER_SAMPLE_SELECT_IDX0="ADCHS_CHANNEL_UNSYNC_TRIGGER_UNSYNC_SAMPLING"
CONFIG_DRV_ADCHS_CHANNEL_INST_IDX1=y
CONFIG_DRV_ADCHS_CHANNEL_ID_IDX1="ADCHS_CHANNEL_1"
CONFIG_DRV_ADCHS_CHNL_1_ALT_INP_SEL_IDX1="ADCHS_DEFAULT_CLASS1_AN1"
CONFIG_DRV_ADCHS_ANALOG_INPUT_LEVEL_TRIGGER_IDX1=n
CONFIG_DRV_ADCHS_TRIGGER_SOURCE_IDX1="ADCHS_TRIGGER_SOURCE_GLOBAL_SOFTWARE_EDGE"
CONFIG_DRV_ADCHS_INPUT_MODE_IDX1="ADCHS_INPUT_MODE_SINGLE_ENDED_UNIPOLAR"
CONFIG_DRV_ADCHS_DATA_RESOLUTION_SELECT_IDX1="ADCHS_DATA_RESOLUTION_12BIT"
CONFIG_DRV_ADCHS_CHANNEL_CLOCK_DIVIDER_IDX1=32
CONFIG_DRV_ADCHS_SAMPLE_TIME_COUNT_IDX1=1023
CONFIG_DRV_ADCHS_TRIGGER_SAMPLE_SELECT_IDX1="ADCHS_CHANNEL_UNSYNC_TRIGGER_UNSYNC_SAMPLING"
CONFIG_DRV_ADCHS_CHANNEL_INST_IDX2=n
CONFIG_DRV_ADCHS_CHANNEL_INST_IDX3=n
CONFIG_DRV_ADCHS_CHANNEL_INST_IDX4=n
CONFIG_DRV_ADCHS_CHANNEL_INST_IDX5=n
#
# from $HARMONY_VERSION_PATH\framework\driver\adc\config\drv_adchs.hconfig
#
CONFIG_DRV_ADCHS_POWER_STATE="SYS_MODULE_POWER_RUN_FULL"
#
# from $HARMONY_VERSION_PATH\framework\driver\adc\config\drv_adc.hconfig
#
CONFIG_USE_DRV_ADCHS_CLASS_2_ANALOG_INPUT_CONVERT=n
CONFIG_USE_DRV_ADCHS_SCAN_MODE=y
CONFIG_DRV_ADCHS_ANALOG_INPUT_SCAN_INSTANCES_NUMBER=2
CONFIG_DRV_ADCHS_ANALOG_INPUT_SCAN_LEVEL_TRIGGER_SENSITIVE=n
CONFIG_DRV_ADCHS_ANALOG_INPUT_SCAN_TRIGGER_SOURCE="ADCHS_SCAN_TRIGGER_SOURCE_GLOBAL_SOFTWARE_EDGE"
#
# from $HARMONY_VERSION_PATH\framework\driver\adc\config\drv_adchs_analog_input_scan_idx.ftl
#
CONFIG_DRV_ADCHS_ANALOG_INPUT_SCAN_INST_IDX0=y
CONFIG_DRV_ADCHS_ANALOG_INPUT_ID_IDX0="ADCHS_AN1"
CONFIG_DRV_ADCHS_SCAN_ANALOG_INPUT_MODE_IDX0="ADCHS_INPUT_MODE_SINGLE_ENDED_UNIPOLAR"
CONFIG_DRV_ADCHS_ANALOG_INPUT_SCAN_INST_IDX1=y
CONFIG_DRV_ADCHS_ANALOG_INPUT_ID_IDX1="ADCHS_AN0"
CONFIG_DRV_ADCHS_SCAN_ANALOG_INPUT_MODE_IDX1="ADCHS_INPUT_MODE_SINGLE_ENDED_UNIPOLAR"
#
# from $HARMONY_VERSION_PATH\framework\driver\adc\config\drv_adc.hconfig
#
CONFIG_USE_DRV_ADCHS_DIGITAL_COMPARATOR=n
CONFIG_DRV_ADCHS_DIGITAL_COMPARATOR_INTERRUPT_EN=n
CONFIG_USE_DRV_ADCHS_DIGITAL_FILTER=n
CONFIG_DRV_ADCHS_DIGITAL_FILTER_INTERRUPT=n
CONFIG_USE_DRV_ADCHS_CVD=n
 
#
# from $HARMONY_VERSION_PATH\framework\driver\touch\touch_adc\config\drv_touch_adc.hconfig
#
CONFIG_USE_DRV_TOUCH_ADC=y
CONFIG_DRV_TOUCH_ADC_CAL_ULX_SAMPLE="160"
CONFIG_DRV_TOUCH_ADC_CAL_ULY_SAMPLE="243"
CONFIG_DRV_TOUCH_ADC_CAL_URX_SAMPLE="860"
CONFIG_DRV_TOUCH_ADC_CAL_URY_SAMPLE="240"
CONFIG_DRV_TOUCH_ADC_CAL_LRX_SAMPLE="864"
CONFIG_DRV_TOUCH_ADC_CAL_LRY_SAMPLE="828"
CONFIG_DRV_TOUCH_ADC_CAL_LLX_SAMPLE="154"
CONFIG_DRV_TOUCH_ADC_CAL_LLY_SAMPLE="830"
CONFIG_DRV_TOUCH_ADC_INPUT_SCAN_X_INSTANCE=0
CONFIG_DRV_TOUCH_ADC_INPUT_SCAN_Y_INSTANCE=1
CONFIG_DRV_TOUCH_ADC_TOUCH_DIAMETER=10
CONFIG_DRV_TOUCH_ADC_SAMPLE_POINTS=4
CONFIG_DRV_TOUCH_ADC_CALIBRATION_DELAY=300
CONFIG_DRV_TOUCH_ADC_CALIBRATION_SCALE_FACTOR=8
CONFIG_DRV_TOUCH_ADC_CALIBRATION_INSET_FACTOR=20
CONFIG_DRV_TOUCH_ADC_PRESS_THRESHOLD=256

#4
Ger jackson
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2017/07/20 00:07:04
  • Location: 0
  • Status: offline
Re: Harmony touch expectations 2018/01/10 01:18:40 (permalink) ☄ Helpfulby jcandle 2018/01/10 20:18:33
5 (1)
@Brandz
 
You need to define in system_config.h where are  "X+ Y+ X- Y-" connected by hardware see the device datasheet. X+ and Y+ are called as both analog and digital by "drv_touch adc.c" , so you should activate the corresponding ADC pins where X+ and Y+ are connected. 
 
(i.e ) I am using a pic32MZ2064DAH176, harmony version 2.05. My X+ are connected to RE9 digital pin which it will work as AN26 at the same time, hence inside sistem.config.h:
/*** Functions for BSP_ADC_TOUCH_XPLUS pin ***/
#define BSP_ADC_TOUCH_XPLUS_PORT PORT_CHANNEL_E
#define BSP_ADC_TOUCH_XPLUS_PIN PORTS_BIT_POS_9
#define BSP_ADC_TOUCH_XPLUS_PIN_MASK (0x1 << 9)
 
and then, within drv_touch.adc.c:
 
if(!PLIB_ADCHS_AnalogInputDataIsReady(DRV_ADC_ID_1, ADCHS_AN26))
 
The same for the rest of the pins. Hope this help.   
#5
Bradnz
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2011/11/23 15:22:15
  • Location: 0
  • Status: offline
Re: Harmony touch expectations 2018/02/13 16:41:18 (permalink)
0
Thanks Ger, I will give that a try.
 
Does anyone know if the touch pins all need to be on dedicated ADC channels (ADC0, 1, 2, 3 or 4) or is it best to have them all connected to the the shared ADC channel (ADC7)?
#6
bblessing
Super Member
  • Total Posts : 679
  • Reward points : 0
  • Joined: 2008/12/04 06:44:21
  • Location: Cincinnati, OH
  • Status: offline
Re: Harmony touch expectations 2018/02/13 16:55:30 (permalink)
0
For the Harmony driver they are class 3 inputs. AN32 and above. I think I have that correct.
#7
Bradnz
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2011/11/23 15:22:15
  • Location: 0
  • Status: offline
Re: Harmony touch expectations 2018/02/13 18:32:25 (permalink)
0
Do I need to have pullups on the Y+ and X+ pins? Isn't the micro setting these high when required in DRV_TOUCH_ADC_STATE_CHECK_ X & Y states within drv_touch_adc.c?
 
I assigned my pins as Ger jackson has for all of my ADC touch pins in system_config.h. I'm using AN5=X+, AN6=X-, AN7=Y+ and AN24=Y- (all on the shared ADC channel 7 now), but I'm not 100% sure what the pin mask does. Is it as simple as defining the pin mask to "0x1 << 5" for X+(AN5) in my case?
 
Also, there are several cases within drv_touch_adc.c where "PLIB_ADCHS_AnalogInputResultGet(DRV_ADC_ID_1, ADCHS_AN24 )" is used:
 
DRV_TOUCH_ADC_STATE_SET_VALUES prior to DRV_TOUCH_ADC_STATE_SET_X
 
DRV_TOUCH_ADC_STATE_CHECK_X and DRV_TOUCH_ADC_STATE_CHECK_Y
 
DRV_TOUCH_ADC_STATE_GET_X and DRV_TOUCH_ADC_STATE_GET_X
 
DRV_TOUCH_ADC_STATE_SET_Y
 
Which ADC inputs do I need to select in each case?
#8
Bradnz
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2011/11/23 15:22:15
  • Location: 0
  • Status: offline
Re: Harmony touch expectations 2018/02/14 14:21:53 (permalink)
0
I found that if I have analog input scanning enabled in the harmony options, then the ADC ports in drv_touch_adc.c (mentioned above) do get assigned automatically by MHC.
 
This got me thinking I may have other options set wrong. Can anyone see anything wrong in the attached images showing my options?
 
 
 

Attached Image(s)

#9
Digital_Angel
Starting Member
  • Total Posts : 50
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
Re: Harmony touch expectations 2018/05/23 05:40:11 (permalink)
0
bblessing
 

That having been said, are there plans to actually add a ready made touch calibration routine? I vaguely recall seeing something about that.


 
Have you heard anything more about this? I'm about to delve into user touch screen calibration territory, and it would be nice to not have to bother with what must be a really common requirement.
#10
Jump to:
© 2018 APG vNext Commercial Version 4.5