• AVR Freaks

Helpful ReplySetting up ADC10BIT Touch Screen Support in Harmony

Page: 12 > Showing page 1 of 2
Author
Digital_Angel
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
2016/04/07 01:36:01 (permalink)
0

Setting up ADC10BIT Touch Screen Support in Harmony

I've put together a small Harmony project to test the resistive touch screen use, but cannot seem to get a sensible signal on the touch screen connections.
I'm wondering if I have set up the pins incorrectly, as there does not appear to be any placeholder for the definitions in the Harmony generated code.
I have added the following to drv_adc10bit.h
 

// ADC10BIT definitions for Resistive Touch Screen Input
 
#define DRV_TOUCH_ADC10BIT_XPLUS_PORT PORT_CHANNEL_B
#define DRV_TOUCH_ADC10BIT_YPLUS_PORT PORT_CHANNEL_B
#define DRV_TOUCH_ADC10BIT_XMINUS_PORT PORT_CHANNEL_G
#define DRV_TOUCH_ADC10BIT_YMINUS_PORT PORT_CHANNEL_D
 
#define DRV_TOUCH_ADC10BIT_XPLUS_PIN PORTS_BIT_POS_11
#define DRV_TOUCH_ADC10BIT_YPLUS_PIN PORTS_BIT_POS_10
#define DRV_TOUCH_ADC10BIT_YMINUS_PIN PORTS_BIT_POS_8
#define DRV_TOUCH_ADC10BIT_XMINUS_PIN PORTS_BIT_POS_15
 
#define PORTS_PIN_MODE_DIGITAL 1
#define PORTS_PIN_MODE_ANALOG 0
 
#define DRV_TOUCH_ADC10BIT_XPLUS_PIN_MASK PORTS_BIT_POS_11
#define DRV_TOUCH_ADC10BIT_YPLUS_PIN_MASK PORTS_BIT_POS_10
#define DRV_TOUCH_ADC10BIT_XMINUS_PIN_MASK PORTS_BIT_POS_8
#define DRV_TOUCH_ADC10BIT_YMINUS_PIN_MASK PORTS_BIT_POS_15
 
#define DRV_TOUCH_ADC10BIT_MUX_TYPE ADC_MUX_A

 
The code compiles and runs on my dev boards, Explorer 16 with PIC32MX795F512L, Graphics LCD Controller SSD1926, Graphics Display Powertip 4.3", and my screen is displayed on the LCD.
If anyone can spot any errors, please let me know!
 
Has anyone here used Harmony with a resistive touch screen successfully? It's either not a common choice, or a very easy one, as I can't seem to find any other threads about it! :)
post edited by Digital_Angel - 2016/04/07 01:50:36
#1
NKurzman
A Guy on the Net
  • Total Posts : 17939
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/07 05:48:48 (permalink)
0
Did you look to see if there is an existing sample app that uses your touch screen?
#2
Digital_Angel
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/07 06:25:00 (permalink)
0
NKurzman
Did you look to see if there is an existing sample app that uses your touch screen?



I have scoured the ENTIRE internet and can find nothing of use. Which can't be right, I'm obviously missing something somewhere!
Everything seems to be geared towards capacitive, but our application ideally requires resistive.
#3
Digital_Angel
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/07 06:32:25 (permalink)
0
I have realised that I was doing my pin masks incorrectly, so the pin directions (TRIS) were not being set correctly.
This has helped in that I no longer have erratic behaviour on the touch screen pins, but the voltages of all pins are remaining at Vdd rather than responding to touch at all.
I'll keep slogging at it, but sample/example code would still be brilliant!
#4
NKurzman
A Guy on the Net
  • Total Posts : 17939
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/07 06:41:40 (permalink)
0
I was referring to the harmony apps folder.
The graphic apps. None of them have a configuration for your display? Even if it is not your chip.
Or posibly the MLA for pic32 or pic24.
I think the board was original for pic24
#5
Digital_Angel
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/07 06:47:19 (permalink)
3 (1)
NKurzman
I was referring to the harmony apps folder.
The graphic apps. None of them have a configuration for your display? Even if it is not your chip.
Or posibly the MLA for pic32 or pic24.
I think the board was original for pic24



Ah I see!
There are Harmony options to configure the display, but no examples that utilise the touch features, they are more about demo-ing the graphics capabillities.
The MLA is the same, no examples that utilise the touch at all.
You're quite right, there's a PIC24 on-board, and example code for that would be fine too, just so I can play with the touch screen, but I cannot find anything for that or the PIC32 beyond actual graphics demos.
 
I'm more than happy to be told I'm wrong and that there IS something suitable that I have just missed!
#6
NKurzman
A Guy on the Net
  • Total Posts : 17939
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/07 08:48:21 (permalink)
3 (1)
No some of them have Touch.
 
 Look for projects with:
pic32mx_usb_sk2+lcc_pictail+wqvga
pic32mx_usb_sk2+s1d_pictail+wqvga
pic32mz_ec_sk+s1d_pictail+vga
pic32mz_ec_sk+s1d_pictail+wqvga
pic32mz_ef_sk+s1d_pictail+vga
pic32mz_ef_sk+s1d_pictail+wqvga
 
Is one of these you hardware?


 
According to the Help 
LCC and Object demo support them.
And they do have touch
post edited by NKurzman - 2016/04/07 08:55:19
#7
Netraver
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2015/06/02 07:20:29
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/13 17:16:55 (permalink) ☄ Helpfulby svcguy 2016/05/27 08:22:08
5 (1)
There was a previous post:-
[SOLVED] pic32mz 4-wire resistive touchscreen ADC  ByUsRaceSolutions Thursday, March 03, 2016
I have also got my resistive touchscreen working for a PIC32MZ2048EFG144 :-
  1. 1.       Set up the Harmony Configurator:-
  • ·         Set up ADC correctly
  • ·         Drivers*Touch*ADC10BIT (it works with 12bit)
  • ·         Graphics Library*Harmony Graphics Library*Use Graphics Library*Use Input Device*enable Touchscreen Support
  • ·         Touch*Use Touch System Service
 
  1. 2.       ADC values
There are 3 interface states:-
DRV_ADC_touch_detect() : x+  digital input (pulled up) ,y+ open(input) ,x-  open , y-  low 
DRV_ADC_Set_X_measure() : x+ high, y+ analog input , x- low, y- open
DRV_ADC_Set_Y_measure() : x+ analog input ,y+ high ,x- open ,y- low 
 
These have to be merged in with other ADC readings, there are multiple ADCs some dedicated and some shared, I had a mixture, so I used:-
 
PLIB_ADCHS_ScanCompleteInterruptEnable(DRV_ADC_ID_1);
 
So that an interrupt is generated after all the ADC inputs have been read. I needed to put:-
appData.flush = ADCCON2; to reset the scan complete flag.
 
Run a ADC scan, If a touch has been detected (x+ low) go through:-
  • ·         change the interface with DRV_ADC_Set_X_measure(), run a ADC scan
  • ·         change the interface with DRV_ADC_Set_Y_measure(), run a ADC scan
  • ·         change the interface to DRV_ADC_touch_detect() and back.
 
  1. 3.       Make a adc state machine
void adc_tasks(void)
{
    switch ( appData.adc_state )
    {
        case ADC_INIT:
        {
            DRV_ADC0_Open();
            DRV_ADC1_Open();
            DRV_ADC2_Open(); 
            appData.adc_state = ADC_SET;
            break;
        }
        case ADC_IDLE:       {       break;       }
        case ADC_SET:        
        {
            DRV_ADC_Start();
            appData.adc_state = ADC_WAIT;
            break;
        }
        case ADC_WAIT:
        {
            if(appData.dataReady)
            {
                appData.dataReady = 0;
                appData.adc_state = ADC_READ;
            }       
            break;
        }
        case ADC_READ:    {    break;    }
        case ADC_DONE:   {    appData.adc_state = ADC_SET;  break;    }
    }
}
 
  1. 4.       Modify drv_adc10bit.c
 
I changed drv_adc10bit.c (which is in the Harmony stack)
 
DRV_TOUCH_ADC10BIT_PositionDetect(void)
/*there are multiple states in the original function but I changed only the one, a state machine is inside it following the 3 step process above*/
case DRV_ADC10BIT_STATE_SET_VALUES:
        {
            if ( appData.adc_state != ADC_READ ) break;//nothing to read come back later
            appData.adc_state = ADC_DONE; //set up the next ADC scan
            switch(appData.touch_state)
            {
case TOUCH_DETECT:               if(SYS_PORTS_PinRead(PORTS_ID_0,DRV_TOUCH_ADC10BIT_XPLUS_PORT, DRV_TOUCH_ADC10BIT_XPLUS_PIN))
               {
                        adcX = -1;                    //no detection
                        adcY = -1;
                        pDrvInstance->touchStatus = DRV_TOUCH_POSITION_SINGLE;
                        return 1; // touch screen acquisition is done
               }
                                else{DRV_ADC_Set_X_measure(); appData.touch_state = TOUCH_MEAS_X}   break;
               case TOUCH_MEAS_X:
                    {
                        tempY = appData.yAxis;
                        DRV_ADC_Set_Y_measure();
                        appData.touch_state = TOUCH_MEAS_Y;
                    }
                    break;
                case TOUCH_MEAS_Y:
                    {
                        tempX = appData.xAxis;
                        adcX = tempX;
                        adcY = tempY;
                        pDrvInstance->touchStatus = DRV_TOUCH_POSITION_SINGLE;
                        DRV_ADC_touch_detect();
                        appData.touch_state = TOUCH_DETECT;
                        return 1; // touch screen acquisition is done
                    }
                    break;
            }      
            break;
        }
 
  1. 5.       calibration data,
 
I measured these manually:-
#define TOUCHCAL_ULX 455
#define TOUCHCAL_ULY 655
#define TOUCHCAL_URX 3769
#define TOUCHCAL_URY 624
#define TOUCHCAL_LLX 624
#define TOUCHCAL_LLY 3408
#define TOUCHCAL_LRX 3869
#define TOUCHCAL_LRY 3626
 
Top left is 0, 0 .
Left to Right X goes from low to High
Top to Bottom Y goes from low to High.
Your calibration will have to follow these rules, even if it means flipping or swapping coordinates.
 
You may also have to set the following to match your screen:-
#define TOUCHSCREEN_RESISTIVE_FLIP_Y
#define TOUCHSCREEN_RESISTIVE_FLIP_X
#define TOUCHSCREEN_RESISTIVE_SWAP_XY
 
adcX and adcY will be used and scaled by the other functions in drv_adc10bit.c
Functions like DRV_TOUCH_ADC10BIT_TouchGetX convert your ADC readings to be 1:1 with the pixel location of the touch.
 
Hope that helps.
#8
Digital_Angel
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/19 06:40:07 (permalink)
0
Thank you so much for that!
I've not had a chance to look through both codes yet as something else cropped up, but will take a look as soon as I can.
Looks like you've supplied fairly comprehensive info, so hopefully this should get me up and running. 
Thanks again! I'll report back ;)
#9
Netraver
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2015/06/02 07:20:29
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/19 06:49:06 (permalink)
3 (1)
I found the X, Y measurement was a bit noisy, so there needs to be some filtering
something like:-
 
#define CLOSE_ENOUGH 10
if (abs(tempX- last_tempX)<CLOSE_ENOUGH) //is valid data
if (abs(tempY- last_tempY)<CLOSE_ENOUGH) //is valid data
 
Otherwise it is working well.
 
#10
Digital_Angel
Starting Member
  • Total Posts : 57
  • Reward points : 0
  • Joined: 2014/08/27 06:56:45
  • Location: Northampton, UK
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/26 05:54:54 (permalink)
5 (1)
Huge thanks Netraver, with your clear explanations I now have a vague clue about how it works, and have at least managed to get my touch screen to output meaningful analog voltages. Doing something with those voltages may take me a little longer, but at least I have now proven the circuit we are using.
Many thanks. Smile: Smile
#11
automate
Junior Member
  • Total Posts : 86
  • Reward points : 0
  • Joined: 2014/11/10 09:58:57
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/04/27 08:46:46 (permalink)
0
Hi Digital,
 
ADC is a popular choice for touch.
Help me understand your available hardware for Harmony.
 
Calibration and screen orientation would have to be understood.
The SSD1926 memory may not be able to successfully drive a WQVGA display.
Are you looking for a working demo for any hardware configuration or just the one you have mentioned?
#12
Paul PortSol
Super Member
  • Total Posts : 512
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/05/26 10:10:08 (permalink)
0
Which pins get assigned to Resistive 4wire Touchscreen, or how do you assign the pins?
If using the MHC Pin settings tab, then how should the pins be set? Or set them in BSP with what settings?
 
Have:
- PIC32MZ EC Starter Kit
- MEBII
- AC32006, and IO Expansion board
- On order 7" LCD with Resistive 4wire touch screen (Unless someone can recommend a Harmony compatible 7" or 10" capacitive touchscreen)
 
**** Rereading above and digging, should I copy and customize this bsp in HarmonyV10701?
  \microchip\harmony\v1_07_01\bsp\pic32mz_ec_sk+s1d_pictail+vga 
or is there a better way?
 
Paul
post edited by Paul PortSol - 2016/05/26 10:28:58
#13
Netraver
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2015/06/02 07:20:29
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/05/27 03:50:54 (permalink) ☄ Helpfulby Paul PortSol 2016/05/27 04:18:17
0
As of version 1.07 the resistive touch screen driver is not complete, it is a bit of a hack to get going, so don’t expect it to work just with some configuration.
 
I used a custom BSP to set the I/O, a whole other topic.
 
See my post above to see how I got it working, it is the best I could do.
#14
svcguy
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2006/04/20 21:41:52
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/05/27 08:01:00 (permalink)
3 (1)
I have a ticket into support about ADC10BIT, I'll post any information they give me.  Hopefully, it's more than "yeah, that should be fixed in 1.08, which is out sometime soon..."
#15
svcguy
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2006/04/20 21:41:52
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/05/27 08:21:23 (permalink)
0
Netraver, thanks for finding the post and providing such help.  Would you be able to answer a few questions?
 
Netraver
  • ·         Set up ADC correctly

 
Must the ADC be setup seprately, or can the ADC setup done by the ADC10BIT driver be used alone.  It is not being used otherwise in my project, I'm just trying to get touch working at the moment...
 
Netraver
 
PLIB_ADCHS_ScanCompleteInterruptEnable(DRV_ADC_ID_1);
 
So that an interrupt is generated after all the ADC inputs have been read. I needed to put:-
appData.flush = ADCCON2; to reset the scan complete flag.
 

 
At what place in the code are you doing these?
 
Netraver
  1. 3.       Make a adc state machine

 
At what place is your ADC state machine implemented (app_tasks()?)
 
Thanks,
Andy
 
#16
Netraver
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2015/06/02 07:20:29
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2016/05/27 08:57:15 (permalink)
0
ADC
Both the touch adc10bit driver and adc driver are set up in the configurator.
The touch screen interface is IO intensive, it has to be synced with your ADC readings so you have to run the adc / IO for the 3 states:-
DRV_ADC_touch_detect() : x+  digital input (pulled up) ,y+ open(input) ,x-  open , y-  low 
DRV_ADC_Set_X_measure() : x+ high, y+ analog input , x- low, y- open
DRV_ADC_Set_Y_measure() : x+ analog input ,y+ high ,x- open ,y- low 
 
Locations
PLIB_ADCHS_ScanCompleteInterruptEnable(DRV_ADC_ID_1);  is in DRV_ADC_Initialize()
(volatile) appData.flush = ADCCON2; is in the adc interrupt
The Adc state machine is in app_tasks.
#17
dhlii
New Member
  • Total Posts : 7
  • Reward points : 0
  • Joined: 2017/01/17 21:26:41
  • Location: 0
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2017/02/01 12:54:19 (permalink)
0
I am trying to resistive touchpad working with Harmony 2.01b and a PCI32MZ using the above. 
 
I thank netraver for his contribution, 
 
But working with Harmony has been warfare. 
I finnally have completed all the above changes - but when I use harmony to "generate" those other drivers etc dictated by the settings is removes the drivers for the Timer and I2C even though those are enabled and required. 
And I end up with something that will not build without error. 
 
What to I need to do to persuade Harmony to include bother the ADC driver and the TMR and I2C drivers. 
 
How can I figure out why harmony wants to remove the TMR and I2C ?
 
 
 
 
 
#18
Paul PortSol
Super Member
  • Total Posts : 512
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2017/02/01 14:27:17 (permalink)
0
Not sure if it affects you but HarmonyV202b with MHC2024 are available.
 
Also, if you have trouble with ADC in HarmonyV202b see post m971862:
http://www.microchip.com/...m971862.aspx?tree=true
 
Paul
#19
Paul PortSol
Super Member
  • Total Posts : 512
  • Reward points : 0
  • Joined: 2015/07/03 11:52:03
  • Location: Newfoundland, Canada
  • Status: offline
Re: Setting up ADC10BIT Touch Screen Support in Harmony 2017/02/01 14:42:54 (permalink)
0
Also: I have noticed that MHC generated files can get corrupted/confused.
 
To fix this I sometimes (This also reduces size for project archives):
 
Clear for Full Regenerate
- Backup the whole project (zip it) so that any of my modifications to generated files aren't lost.
-- It is very useful to keep in the project a text document listing changes you made to generated files, and what MHC version generated them!
- Delete: (fill in appropriate at * and ***)
--  under *:\microchip\harmony\v2_02_00b\_port\***\firmware\***.X\
--- delete (build, debug, dist)    
--  under *:\microchip\harmony\v2_02_00b\_port\***\firmware\src\system_config\default\
--- delete all except (configuration.xml, default.mhc, or appropriate Project Configuration Name)
- Restore customization: Do a diff between new generated files and your backed up files to find any modifications you may need (I use "Beyond Compare" to compare the folder tree - http://www.scootersoftware.com/)
- Recompile
 
Pin Misbehaving (Not input/output as expected):
I also noticed on one occasion that some pin settings didn't get properly set, and by changing pin (to output, then input, then desired setting) it seemed to reset all the pin's attributes (check pins in the default.xml) and then work properly.
#20
Page: 12 > Showing page 1 of 2
Jump to:
© 2019 APG vNext Commercial Version 4.5