?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik  
2 /*****************************************************************************
3 * FileName: mTouchCap_Timers.c
4 * Dependencies:
5 * Processor: PIC18, PIC24
6 * Compiler: C18, C30
7 * Linker: MPLINK,MPLAB LINK30
8 * Company: Microchip Technology Incorporated
9 *
10 * Software License Agreement
11 *
12 * Copyright © 2009 Microchip Technology Inc.
13 * Microchip licenses this software to you solely for use with Microchip products, according to the terms of the
14 * accompanying click-wrap software license. Microchip and its licensors retain all right, title and interest in
15 * and to the software. All rights reserved. This software and any accompanying information is for suggestion only.
16 * It shall not be deemed to modify Microchip’s standard warranty for its products. It is your responsibility to ensure
17 * that this software meets your requirements.
18  
19 * SOFTWARE IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
20 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT
21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP OR ITS LICENSORS BE LIABLE
22 * FOR ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO INCIDENTAL,
23 * SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA,
24 * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, OR ANY CLAIMS BY THIRD PARTIES
25 * (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
26 * The aggregate and cumulative liability of Microchip and its licensors for damages related to the use of the software
27 * will in no event exceed $1000 or the amount you paid Microchip for the software, whichever is greater.
28  
29 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE TERMS AND
30 * THE TERMS OF THE ACCOMPANYING CLICK-WRAP SOFTWARE LICENSE.
31 *
32 *
33 * Author Date Comment
34 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 * BDB 26-Jun-2008 First release
36 * Naveen. M 14 Apr 2009 Version 0.1 Initial Draft
37 * Nithin Kumar. M 14 May 2009 Version 0.2 Updates
38 * Sasha. M / Naveen. M 4 June 2009 Version 0.3 Updates
39 * Bruce Bohn 10 Nov 2009 Version 0.4 Updates
40 * Sasha. M / Naveen. M 11 Nov 2009 Version 1.0 Release
41 * Nithin Kumar 02 March 2010 Interfacing the mTouch Library to the mTouch GUI plug-in
42 * Sasha. M / Nithin. 10 April 2010 Version 1.20 Release
43 *****************************************************************************/
44  
45 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
46 /* ~~~~~~~~~~~~~~~~~~~~~ Includes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
47 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
48  
49 #include "mTouchCap_Timers.h"
50  
51  
52 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
53 /* ~~~~~~~~~~~~~~~~~~~~~ Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
54 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
55 SHORT T3counter;
56 SHORT tick;
57 SHORT tickCount =0;
58 WORD channelSelect = 0;
59 CHAR dataReadyCTMU = 0;
60  
61 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
62 /* ~~~~~~~~~~~~~~~~~~~~~ Function Prototypes ~~~~~~~~~~~~~~~~~~~~~~~~~~ */
63 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
64  
65  
66  
67  
68  
69 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
70 /* ~~~~~~~~~~~~~~~~~~~~~ Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
71 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
72  
73  
74  
75  
76  
77  
78 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
79 /* ~~~~~~~~~~~~~~~~~~~~~ Function Definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
80 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
81  
82  
83 /******************************************************************************
84 * Function: void Delayms(BYTE milliseconds)
85 *
86 * PreCondition: None
87 *
88 * Input: BYTE millisecons - Number of ms to delay
89 *
90 * Output: None
91 *
92 * Side Effects: None
93 *
94 * Overview: Delays the code- not necessairly accurate
95 *
96 * Note: None.
97 *****************************************************************************/
98  
99  
100 void Delayms(BYTE milliseconds)
101 {
102 BYTE ms;
103 DWORD count;
104  
105 ms = milliseconds;
106 while (ms--)
107 {
108 count = MILLISECDELAY;
109  
110 while (count--)
111 {
112 ;
113 }
114 }
115 Nop();
116 return;
117 }
118  
119  
120 #ifdef __PIC24F__
121  
122 #ifdef GUI_USB_INTERFACE
123  
124 void T1Init( void )
125 {
126 T1CON = TIMER1_T1CON_OFF;
127 }
128  
129 /********************************************************************
130 * Function : void mTouchCapPhy_Timer1Set( WORD time)
131 *
132 * PreCondition : None
133 *
134 * Input : The time period for loading the PR1 register of the timer1
135 *
136 * Output : None
137 *
138 * Side Effects : None
139 *
140 * Overview :
141 *
142 * Note :
143 *******************************************************************/
144 void mTouchCapPhy_Timer1Set( WORD time)
145 {
146 T1CON = TIMER1_T1CON_OFF; //turn off the timer 1
147 PR1 = time;
148 TMR1 = 0;
149 TIMER1_IF = 0;
150  
151 T1CON = TIMER1_T1CON_ON; //TIMER1_ON | TIMER1_CLK ;//TIMER1_T1CON_ON;
152 }
153  
154 #endif //#ifdef GUI_USB_INTERFACE
155  
156 /*****************************************************************************/
157 /* PIC24F related timer initializations */
158 /*****************************************************************************/
159 /****************************************************************************
160 Function:
161 void mTouchCapPhy_TickInit( void )
162  
163 Description:
164 This function sets up Timer 4 to generate an interrupt every 1 ms. This
165 is the basic timer tick for the system. The CTMU samples each channel
166 at a 1ms rate. This yields 16ms to sample all of the channels. This
167 timer is then disabled while the data gathered is updated by the main
168 program loop.
169  
170 Precondition:
171 None
172  
173 Parameters:
174 None
175  
176 Returns:
177 None
178  
179 Remarks:
180 The timer period and prescaler
181 values are dependent on the oscillator speed.
182 ***************************************************************************/
183  
184 void mTouchCapPhy_TickInit( void )
185 {
186 TMR4 = 0;
187 PR4 = TIMER_PERIOD;
188 T4CON = TIMER_ON | TIMER_SOURCE_INTERNAL | GATED_TIME_DISABLED | TIMER_16BIT_MODE | TIMER4_PRESCALER;
189  
190 Set_ScanTimer_IF_Bit_State(DISABLE); //Clear flag
191 Set_ScanTimer_IE_Bit_State(ENABLE); //Enable interrupt
192 Set_ScanTimer_ON_Bit_State(ENABLE) ; //Run timer
193 }
194  
195  
196  
197 /****************************************************************************
198 Function:
199 void __attribute__((interrupt, shadow, auto_psv)) _T4Interrupt(void)
200  
201 Description:
202 This function calls ReadCTMU() to monitor the
203 touchpads.
204  
205 Precondition:
206 Timer 4 and the Timer 4 interrupt must be enabled in order for
207 this function to execute. CTMUInit() must be called before
208 Timer 4 and the Timer 4 interrupt are enabled. The tickinit() function
209 is called to setup timer 4
210  
211 Parameters:
212 None
213  
214 Returns:
215 None
216  
217 Remarks:
218 None
219 ***************************************************************************/
220 void __attribute__((interrupt, shadow, auto_psv)) _T4Interrupt(void)
221 {
222 /* Check the interrupt Flag */
223 if (IFS1bits.T4IF == HIGH)
224 {
225 if(channelSelect >= ScanChannelIndex)
226 {
227 /* Count upto MAX ADC channel though the actual scan happen only for channels which are enabled.
228 This helps to maintain the same interval for any channel when enabled or disabled. */
229 if(channelSelect>= MAX_ADC_CHANNELS)
230 {
231 channelSelect = 0;
232 dataReadyCTMU = 1;
233 }
234 else
235 {
236 channelSelect++;
237 }
238 }
239 else
240 {
241 /* Scans the CTMU channel for ADC voltage. It updates the "curRawData" and "actualValue" buffers. */
242 mTouchCapPhy_ReadCTMU(ScanChannels[channelSelect]); //NK_DIRKEY
243  
244 /* Periodically average the channel data based on User configuration. */
245 mTouchCapPhy_AverageData(ScanChannels[channelSelect]); //NK_DIRKEY
246  
247 /* Set the channel number for scanning */
248 channelSelect++;
249 }
250  
251 /* Clear the interrupt Flag */
252 IFS1bits.T4IF = LOW;
253 }
254 }
255  
256 /*****************************************************************************/
257 /* PIC18F related timer initializations */
258 /*****************************************************************************/
259 #else //(__18CXX)
260  
261 //#define TIMER_PRESCALER TIMER_PRESCALER_4 //divide by 8
262 // #define TIMER_PERIOD 2000; //@ 8MHz clock with 4x PLL = 32MHz
263 // 8MHz instruction cycle 1/8000000 * 4x
264 // prescale * 2000 = 1mS
265  
266  
267 /****************************************************************************
268 Function:
269 void mTouchCapPhy_TickInit( void )
270  
271 Description:
272 This function sets up Timer 4 to generate an interrupt every 1 ms. This
273 is the basic timer tick for the system. The CTMU samples each channel
274 at a 1ms rate. This yields 16ms to sample all of the channels. This
275 timer is then disabled while the data gathered is updated by the main
276 program loop.
277  
278 Precondition:
279 None
280  
281 Parameters:
282 None
283  
284 Returns:
285 None
286  
287 Remarks:
288 The timer period and prescaler
289 values are dependent on the oscillator speed.
290 ***************************************************************************/
291  
292 void mTouchCapPhy_TickInit( void )
293 {
294 TMR2 = 0x00;
295 PR2 = TIMER_PERIOD;
296 T2CON = TIMER_ON | TIMER_PRESCALER_4 | TIMER_POSTSCALER; //about every 8 ms scan for Switch
297  
298 INTCONbits.GIE = 1; //Enable Global Interrupt
299 INTCONbits.PEIE = 1; //Enable Peripheral Interrupt
300 PIR1bits.TMR2IF = 0; //Clear flag
301 PIE1bits.TMR2IE = 1; //Enable Timer2 interrupt // TMR2ON =1;
302 }
303  
304 /*******************************************************************************
305 * Interrupt service routine for timer 2
306 *******************************************************************************/
307  
308  
309 #pragma code InterruptVectorHigh = 0x08
310 void
311 InterruptVectorHigh (void)
312 {
313 _asm
314 goto InterruptHandlerHigh //jump to interrupt routine
315 _endasm
316 } //isr
317  
318  
319  
320 /****************************************************************************
321 Function:
322 void InterruptHandlerHigh ()
323 Description:
324 This function calls ReadCTMU() to monitor the
325 touchpads.
326  
327 Precondition:
328 Timer 2 and the Timer 2 interrupt must be enabled in order for
329 this function to execute. CTMUInit() must be called before
330 Timer 2 and the Timer 2 interrupt are enabled. The tickinit() function
331 is called to setup timer 2
332  
333 Parameters:
334 None
335  
336 Returns:
337 None
338  
339 Remarks:
340 None
341 ***************************************************************************/
342 //----------------------------------------------------------------------------
343 #pragma code
344 #pragma interrupt InterruptHandlerHigh
345  
346 void InterruptHandlerHigh ()
347 {
348 /* Check the interrupt Flag */
349 if (PIR1bits.TMR2IF == HIGH)
350 {
351 if(channelSelect >= ScanChannelIndex)
352 {
353 /* Count upto MAX ADC channel though the actual scan happen only for channels which are enabled.
354 This helps to maintain the same interval for any channel when enabled or disabled. */
355 if(channelSelect>= MAX_ADC_CHANNELS)
356 {
357 channelSelect = 0;
358 dataReadyCTMU = 1;
359 }
360 else
361 {
362 channelSelect++;
363 }
364 }
365 else
366 {
367 /* Scans the CTMU channel for ADC voltage. It updates the "curRawData" and "actualValue" buffers. */
368 mTouchCapPhy_ReadCTMU(ScanChannels[channelSelect]);
369  
370 /* Periodically average the channel data based on User configuration. */
371 mTouchCapPhy_AverageData(ScanChannels[channelSelect]);
372  
373 /* Set the channel number for scanning */
374 channelSelect++;
375 }
376  
377 /* Clear the interrupt Flag */
378 PIR1bits.TMR2IF =LOW;
379 }
380  
381 }
382  
383 #ifdef GUI_USB_INTERFACE
384 void mTouchCapPhy_Timer1Set( WORD time)
385 {
386 T1CON = 0x00; //TIMER1_OFF ; //TIMER1_T1CON_OFF;
387 /* load the time to higher and lower byte of the timer register */
388 TMR1L = mTouchCap_GUI_comm_tx_interval.byte.LB;
389 TMR1H = mTouchCap_GUI_comm_tx_interval.byte.HB;
390 //TMR1 = 0;
391 TIMER1_IF = 0;
392 T1CON = 0x01; //TIMER1_ON | TIMER1_CLK ;//TIMER1_T1CON_ON;
393 }
394 #endif //end of #ifdef GUI_USB_INTERFACE
395  
396 #endif //end of #else //(__18CXX)
397  
398  
399  
400  
401  
402  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3