| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | |
| 2 | /***************************************************************************** |
||
| 3 | * FileName: mTouchCap_Timers.h |
||
| 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 Microchips 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 | * Sasha. M / Naveen. M 11 Nov 2009 Version 1.0 Release |
||
| 40 | * Sasha. M / Nithin. 10 April 2010 Version 1.20 Release |
||
| 41 | * |
||
| 42 | *****************************************************************************/ |
||
| 43 | #ifndef _MTOUCH_TIMERS_H |
||
| 44 | #define _MTOUCH_TIMERS_H |
||
| 45 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 46 | /* ~~~~~~~~~~~~~~~~~~~~~ Includes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 47 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 48 | //#include "mTouchCap_Config.h" |
||
| 49 | #include "GenericTypeDefs.h" |
||
| 50 | #include "Compiler.h" |
||
| 51 | #include "HardwareProfile.h" |
||
| 52 | #include "mTouchCap_CtmuAPI.h" |
||
| 53 | |||
| 54 | #ifdef __PIC24F__ |
||
| 55 | #include "mTouchCap_PIC24_CTMU_Physical.h" |
||
| 56 | #else |
||
| 57 | #include "mTouchCap_PIC18_CTMU_Physical.h" |
||
| 58 | #endif |
||
| 59 | #ifdef GUI_USB_INTERFACE |
||
| 60 | #ifdef __PIC24F__ //USB GUI |
||
| 61 | #include "mTouchCap_PIC24F_GUI_commn.h" |
||
| 62 | #else |
||
| 63 | #include "mTouchCap_PIC18F_GUI_commn.h" |
||
| 64 | |||
| 65 | #endif |
||
| 66 | #endif //end of #ifdef GUI_USB_INTERFACE |
||
| 67 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 68 | /* ~~~~~~~~~~~~~~~~~~~~~ Externs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 69 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 70 | |||
| 71 | /** External Variables **/ |
||
| 72 | extern CHAR dataReadyCTMU; //nsc |
||
| 73 | |||
| 74 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 75 | /* ~~~~~~~~~~~~~~~~~~~~~ Function Prototypes ~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 76 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 77 | #ifdef GUI_USB_INTERFACE |
||
| 78 | void T1Init(void); |
||
| 79 | void mTouchCapPhy_Timer1Set(WORD time); |
||
| 80 | #endif |
||
| 81 | void timer1_wait(WORD time); |
||
| 82 | void mTouchCapPhy_TickInit( void); |
||
| 83 | void InterruptHandlerHigh (void); |
||
| 84 | |||
| 85 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 86 | /* ~~~~~~~~~~~~~~~~~~~~~ Enums ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 87 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 88 | |||
| 89 | |||
| 90 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 91 | /* ~~~~~~~~~~~~~~~~~~~~~ Constants / Macros ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 92 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 93 | |||
| 94 | // Sample clock speed for PIC18 |
||
| 95 | #if defined (__18CXX) |
||
| 96 | #define GetPeripheralClock() GetSystemClock() // Peripheral clock freq. |
||
| 97 | #define GetInstructionClock() (GetSystemClock() / 4) // Instruction clock freq. Four osc cycle are required for a instruction execution in PIC18 |
||
| 98 | // Sample clock speed for a 16-bit processor |
||
| 99 | #elif defined (__C30__) |
||
| 100 | #define GetPeripheralClock() GetSystemClock() // Peripheral clock freq. |
||
| 101 | #define GetInstructionClock() (GetSystemClock() / 2) // Instruction clock freq. Two osc cycle are required for a instruction execution in PIC24 |
||
| 102 | #endif |
||
| 103 | |||
| 104 | /* Derive the TIMER PR register value based on Instruction clock, Prescale value, and Timer interrupt time expected */ |
||
| 105 | #if defined (__18CXX) |
||
| 106 | #define TIMER_PERIOD ((GetInstructionClock()) / ((DWORD)(TIMER_POSTSCALER_VALUE)*(TIMER_PRESCALER_VALUE)*(TIMER_INTERRUPT_TIME))) |
||
| 107 | #elif defined (__C30__) |
||
| 108 | #define TIMER_PERIOD ((GetInstructionClock()) / ((DWORD)(TIMER_PRESCALER_VALUE)*(TIMER_INTERRUPT_TIME))) |
||
| 109 | #endif |
||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 115 | /* Delay Generation: Macros */ |
||
| 116 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 117 | // Description: A delay prescaler |
||
| 118 | #define DELAY_PRESCALER (BYTE) 8 |
||
| 119 | |||
| 120 | // Description: An approximation of the number of cycles per delay loop of overhead |
||
| 121 | #define DELAY_OVERHEAD (BYTE) 5 |
||
| 122 | |||
| 123 | // Description: An approximate calculation of how many times to loop to delay 1 ms in the Delayms function |
||
| 124 | #define MILLISECDELAY (WORD) ((GetInstructionClock()/DELAY_PRESCALER/(WORD)1000) - DELAY_OVERHEAD) |
||
| 125 | |||
| 126 | |||
| 127 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 128 | /* Timer4 is used for tick generation in PIC24. */ |
||
| 129 | /* Timer2 is used for tick generation in PIC18. */ |
||
| 130 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 131 | #ifdef __PIC24F__ |
||
| 132 | |||
| 133 | #define STOP_TIMER_IN_IDLE_MODE 0x2000 |
||
| 134 | #define TIMER_SOURCE_INTERNAL 0x0000 |
||
| 135 | #define TIMER_ON 0x8000 |
||
| 136 | #define GATED_TIME_DISABLED 0x0000 |
||
| 137 | #define TIMER_16BIT_MODE 0x0000 |
||
| 138 | #define TIMER_PRESCALER_1 0x0000 |
||
| 139 | #define TIMER_PRESCALER_8 0x0010 |
||
| 140 | #define TIMER_PRESCALER_64 0x0020 |
||
| 141 | #define TIMER_PRESCALER_256 0x0030 |
||
| 142 | #define TIMER_INTERRUPT_PRIORITY 0x1000 |
||
| 143 | |||
| 144 | #define TIMER4_PRESCALER TIMER_PRESCALER_64 // User needs notto modify these two variables for different prescalar |
||
| 145 | #define TIMER_PRESCALER_VALUE 64 // This value is used to calculate TIMER_PERIOD |
||
| 146 | #define TIMER3_PERIOD 500 |
||
| 147 | |||
| 148 | #else //(__18CXX) |
||
| 149 | |||
| 150 | #define TIMER_ON 0x04 //Timer2 is on |
||
| 151 | #define TIMER_PRESCALER_4 0x01 //Prescaler is 4 |
||
| 152 | #define TIMER_POSTSCALER 0x78 //1:16 Postscale |
||
| 153 | |||
| 154 | #define TIMER_PRESCALER_VALUE 4 |
||
| 155 | #define TIMER_POSTSCALER_VALUE 16 |
||
| 156 | |||
| 157 | #endif |
||
| 158 | |||
| 159 | |||
| 160 | |||
| 161 | |||
| 162 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 163 | /* Timer1 can be used for mTouch GUI */ |
||
| 164 | /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
||
| 165 | #ifdef __PIC24F__ //PIC24F related definitions |
||
| 166 | //--- CONFIGURATION: CLK:FOSC/2/256 |
||
| 167 | #define TIMER1_T1CON_ON 0x8030 |
||
| 168 | #define TIMER1_T1CON_OFF 0x0030 |
||
| 169 | |||
| 170 | #define TIMER1_USEC (128.0) |
||
| 171 | #define TIMER1_MSEC (TIMER1_USEC * 1000) |
||
| 172 | |||
| 173 | #define TIMER1_IF IFS0bits.T1IF |
||
| 174 | #else //(__18CXX) //PIC18F related definitions |
||
| 175 | //--- CONFIGURATION: |
||
| 176 | #define TIMER1_T1CON_ON 0x31 //TMR1ON =1;TMR1CS = FOsc/4; |
||
| 177 | #define TIMER1_T1CON_OFF 0x30 //TMRON =0; --> off |
||
| 178 | #define TIMER1_ON 0x01 //TMR0N =1 |
||
| 179 | #define TIMER1_CLK 0x00 //FOsc/4 |
||
| 180 | #define TIMER1_OFF 0x00 //TIMER1 is disabled |
||
| 181 | |||
| 182 | #define TIMER1_USEC (128.0) |
||
| 183 | #define TIMER1_MSEC (TIMER1_USEC * 1000) |
||
| 184 | |||
| 185 | #define TIMER1_IF PIR1bits.TMR1IF |
||
| 186 | #endif // __TIMER1_H |
||
| 187 | |||
| 188 | |||
| 189 | /************************************************************************ |
||
| 190 | ************************************************************************ |
||
| 191 | MACROs |
||
| 192 | ************************************************************************ |
||
| 193 | **************************************************************************/ |
||
| 194 | #ifdef __PIC24F__ |
||
| 195 | |||
| 196 | |||
| 197 | /************************************************************************ |
||
| 198 | Macro : Set_Timer4_IF_Bit_State(State) |
||
| 199 | Overview : setting or clearing T4 Interrupt Flag Bit |
||
| 200 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 201 | Remarks : None. |
||
| 202 | **************************************************************************/ |
||
| 203 | |||
| 204 | #define Set_ScanTimer_IF_Bit_State(State) (IFS1bits.T4IF = State) |
||
| 205 | |||
| 206 | |||
| 207 | /************************************************************************ |
||
| 208 | Macro : Set_T4_IE_Bit_State(State) |
||
| 209 | Overview : setting or clearing T4 Interrupt Enable Bit |
||
| 210 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 211 | Remarks : None. |
||
| 212 | **************************************************************************/ |
||
| 213 | |||
| 214 | #define Set_ScanTimer_IE_Bit_State(State) (IEC1bits.T4IE = State) |
||
| 215 | |||
| 216 | |||
| 217 | /************************************************************************ |
||
| 218 | Macro : Set_T4_ON_Bit_State(State) |
||
| 219 | Overview : setting or clearing T4 ON bit |
||
| 220 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 221 | Remarks : None. |
||
| 222 | **************************************************************************/ |
||
| 223 | |||
| 224 | #define Set_ScanTimer_ON_Bit_State(State) (T4CONbits.TON = State) |
||
| 225 | |||
| 226 | /************************************************************************ |
||
| 227 | Macro : Wait_Till_Timer_Flag_SET |
||
| 228 | Overview : wait till T1 Status bit is set |
||
| 229 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 230 | Remarks : None. |
||
| 231 | **************************************************************************/ |
||
| 232 | #define Wait_Till_Timer_Flag_SET (IFS0bits.T1IF == 0) |
||
| 233 | |||
| 234 | /************************************************************************ |
||
| 235 | Macro : Wait_Till_OC_Flag_SET |
||
| 236 | Overview : Wait till OC1 Status bit is set |
||
| 237 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 238 | Remarks : None. |
||
| 239 | **************************************************************************/ |
||
| 240 | #define Wait_Till_OC_Flag_SET (IFS0bits.OC1IF == 0) |
||
| 241 | |||
| 242 | |||
| 243 | #else |
||
| 244 | /************************************************************************ |
||
| 245 | Macro : Set_Timer2_IF_Bit_State(State) |
||
| 246 | Overview : setting or clearing T4 Interrupt Flag Bit |
||
| 247 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 248 | Remarks : None. |
||
| 249 | **************************************************************************/ |
||
| 250 | |||
| 251 | #define Set_ScanTimer_IF_Bit_State(State) (PIR1bits.TMR2IF = State) |
||
| 252 | |||
| 253 | /************************************************************************ |
||
| 254 | Macro : Set_T2_IE_Bit_State(State) |
||
| 255 | Overview : setting or clearing T4 Interrupt Enable Bit |
||
| 256 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 257 | Remarks : None. |
||
| 258 | **************************************************************************/ |
||
| 259 | |||
| 260 | #define Set_ScanTimer_IE_Bit_State(State) (PIE1bits.TMR2IE = State) |
||
| 261 | |||
| 262 | /************************************************************************ |
||
| 263 | Macro : Set_T2_ON_Bit_State(State) |
||
| 264 | Overview : setting or clearing T4 ON bit |
||
| 265 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 266 | Remarks : None. |
||
| 267 | **************************************************************************/ |
||
| 268 | |||
| 269 | #define Set_ScanTimer_ON_Bit_State(State) (T2CONbits.TMR2ON = State) |
||
| 270 | |||
| 271 | /************************************************************************ |
||
| 272 | Macro : Wait_Till_Timer_Flag_SET |
||
| 273 | Overview : wait till T1 Status bit is set |
||
| 274 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 275 | Remarks : None. |
||
| 276 | **************************************************************************/ |
||
| 277 | #define Wait_Till_Timer_Flag_SET (INTCON3bits.INT1IF == 0) |
||
| 278 | |||
| 279 | /************************************************************************ |
||
| 280 | Macro : Wait_Till_OC_Flag_SET |
||
| 281 | Overview : Wait till OC1 Status bit is set |
||
| 282 | Parameters : ENABLE '1' or DISABLE '0' |
||
| 283 | Remarks : None. |
||
| 284 | **************************************************************************/ |
||
| 285 | #define Wait_Till_OC_Flag_SET (IFS0bits.OC1IF == 0) |
||
| 286 | |||
| 287 | |||
| 288 | ///************************************************************************ |
||
| 289 | //Macro : Set_Timer4_IF_Bit_State(State) |
||
| 290 | //Overview : setting or clearing T4 Interrupt Flag Bit |
||
| 291 | //Parameters : ENABLE '1' or DISABLE '0' |
||
| 292 | //Remarks : None. |
||
| 293 | //**************************************************************************/ |
||
| 294 | //#define Set_ScanTimer_IF_Bit_State(State) (PIR3bits.TMR4IF = State) |
||
| 295 | // |
||
| 296 | ///************************************************************************ |
||
| 297 | //Macro : Set_T4_IE_Bit_State(State) |
||
| 298 | //Overview : setting or clearing T4 Interrupt Enable Bit |
||
| 299 | //Parameters : ENABLE '1' or DISABLE '0' |
||
| 300 | //Remarks : None. |
||
| 301 | //**************************************************************************/ |
||
| 302 | //#define Set_ScanTimer_IE_Bit_State(State) (PIE3bits.TMR4IE = State) |
||
| 303 | // |
||
| 304 | ///************************************************************************ |
||
| 305 | //Macro : Set_T4_ON_Bit_State(State) |
||
| 306 | //Overview : setting or clearing T4 ON bit |
||
| 307 | //Parameters : ENABLE '1' or DISABLE '0' |
||
| 308 | //Remarks : None. |
||
| 309 | //**************************************************************************/ |
||
| 310 | //#define Set_ScanTimer_ON_Bit_State(State) (T4CONbits.TMR4ON = State) |
||
| 311 | // |
||
| 312 | #endif //PIC18 |
||
| 313 | |||
| 314 | |||
| 315 | |||
| 316 | |||
| 317 | #endif // _MTOUCH_TIMERS_H |
||
| 318 | |||
| 319 |
Powered by WebSVN v2.8.3