Small VGA monitor
| Author | Message | ||||
TassyJim![]() Guru Joined: 07/08/2011 Location: AustraliaPosts: 6546 |
My new toy arrived today.
The UBW32 is on the left. I really must get one of Mick's boards for the final installation! The display works well with the Maximite and I have a rough working touch program. Only two extra resistors were needed for a low parts count. I have to do a bit more fine tuning with the timing delays but I am pleased with a first attempt. See the XPT2046 or ADS7843 data sheets for a good description of how the resistive touch screen works.
How the interrupt works: TouchIntEnable is set high Y2 is set low When the touch contact is made the low resistances of the X and Y resistors pulls TouchInt low. This triggers the interrupt. TouchIntEnable is then turned off to prevent it from interfering with the readings. X1 is driven High and X2 low and the mid point voltage read through Y1. The Y resistance has no effect on the reading due to the high input impedence. Y1 is then driven high and Y2 low and the Y positoin is read through X1. The delays are needed because of the high capacitance of the touchscreen and we need settling time. ***EDIT: In my real circuit, I have the Interrupt connected to the Y resistor and grounded X2. The theory is the same and it doesn't matter which way it's done. ' touch display demo
' by TassyJim ' 16 Nov 2012 ' see the XPT2046 or ADS7843 data sheets for a description ' of how the resistive touch screen works cls TouchY1=37 ' 4 analogue input pins for the resistors TouchY2=35 TouchX1=38 TouchX2=36 TouchIntEnable=34 ' any digital output pin TouchInt=28 ' digital interupt pin gosub _touchEnable _mainLoop: 'do stuff while waiting for a touch if t=1 then font 1, 4 print @(100, 40)"X ";Xhit;" ";@(100, 90)"Y ";Yhit;" " pause 100 gosub _touchEnable endif goto _mainLoop _touchEnable: setpin TouchY1, 1 setpin TouchY2, 1 setpin TouchX1, 1 setpin TouchX2, 8 Pin(TouchX2)=0 setpin TouchIntEnable, 8 pin(TouchIntEnable)=1 pause 100 setpin TouchInt, 7, _Touched t=0 return _Touched: pause 5 ' debounce time if pin(TouchInt)=0 then ' touch still there setpin TouchInt, 0 ' disable the interupt setpin TouchIntEnable,0 ' disable the interupt resistor setpin TouchX1, 8 ' Pin(TouchX1)=1 ' X1 is now high and X2 low pause 5 Xvolt=pin(TouchY1) ' read the X position using Y1 setpin TouchX1, 1 setpin TouchX2, 1 ' set the X as input setpin TouchY1, 8 ' and the Y as potential divider setpin TouchY2, 8 Pin(TouchY1)=1 Pin(TouchY2)=0 pause 5 Yvolt=pin(TouchX1) ' read the Y position using X1 Xhit=int(mm.hres*Xvolt/3.3) ' you can scale to any value here Yhit=int(mm.vres*Yvolt/3.3) if Xhit >470 or Yhit < 5 then 'reading is suspect Xhit=0 ' so set the results to zero Yhit=0 endif t=1 ' flag to indicate a touch decoded endif ireturn The next job is to get some working menus (and work out where in the caravan it is going to live) Jim VK7JH MMedit |
||||