• Main Page
  • Modules
  • Files
  • File List
  • Globals

mTouchCVD_Config.h

Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2011 Microchip Technology Inc.                                       
00003  *  
00004  *  Project Name:    mTouch CVD Framework v1.1
00005  *  FileName:        mTouchCVD_Config.h
00006  *  Dependencies:    
00007  *  Processor:       See documentation for supported PIC® microcontrollers 
00008  *  Compiler:        HI-TECH Ver. 9.81 or later
00009  *  IDE:             MPLAB® IDE v8.50 (or later) or MPLAB® X                        
00010  *  Hardware:         
00011  *  Company:         
00012  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00013  *  Description:     mTouch CVD Framework Configuration File
00014  *                   - See documentation for better explanations of all
00015  *                     configuration options.
00016  *************************************************************************/
00017 /***********************************************************************
00018  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 
00019  * any derivatives created by any person or entity by or on your behalf, 
00020  * exclusively with Microchip's products in accordance with applicable
00021  * software license terms and conditions, a copy of which is provided for
00022  * your referencein accompanying documentation. Microchip and its licensors 
00023  * retain all ownership and intellectual property rights in the 
00024  * accompanying software and in all derivatives hereto. 
00025  * 
00026  * This software and any accompanying information is for suggestion only. 
00027  * It does not modify Microchip's standard warranty for its products. You 
00028  * agree that you are solely responsible for testing the software and 
00029  * determining its suitability. Microchip has no obligation to modify, 
00030  * test, certify, or support the software. 
00031  * 
00032  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
00033  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
00034  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
00035  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 
00036  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 
00037  * APPLICATION. 
00038  * 
00039  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 
00040  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 
00041  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 
00042  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 
00043  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 
00044  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 
00045  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 
00046  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 
00047  * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 
00048  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 
00049  * 
00050  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 
00051  * THESE TERMS. 
00052  *************************************************************************/
00053  /****************************************************************************
00054  * Revision History
00055  * Date         Rev      Author  Comments
00056  * 09.20.10 1.00         Public Release
00057  ****************************************************************************/
00062 //**********************************************
00063 //
00064 // System Configuration
00065 //
00066 //**********************************************
00067 
00068                                         //====================================================
00069 #define _XTAL_FREQ      32000000        // REQUIRED: The Fosc frequency of your system in Hz      
00070 #define TMR0_PRESCALER  2               // REQUIRED: The TMR0 prescaler value of your system   
00071 
00072 
00073 #define CVD_NUMBER_SENSORS          7       // Number of CVD Sensor Inputs
00074 
00075     #define CVD_SENSOR0             AN0
00076 
00077     #define CVD_SENSOR1             AN1    
00078     #define CVD_SENSOR2             AN2
00079     #define CVD_SENSOR3             AN3
00080     
00081     #define CVD_SENSOR4             AN4    
00082     #define CVD_SENSOR5             AN5     
00083     #define CVD_SENSOR6             AN6  
00084     #define CVD_SENSOR7             AN7       
00085     #define CVD_SENSOR8             AN8     
00086     #define CVD_SENSOR9             AN9     
00087     #define CVD_SENSOR10            AN10    
00088     #define CVD_SENSOR11            AN11    
00089     #define CVD_SENSOR12            AN12    
00090     #define CVD_SENSOR13            AN13     
00091     #define CVD_SENSOR14            AN14    
00092     #define CVD_SENSOR15            AN15   
00093     #define CVD_SENSOR16            AN16   
00094     #define CVD_SENSOR17            AN17   
00095     #define CVD_SENSOR18            AN18   
00096     #define CVD_SENSOR19            AN19   
00097     #define CVD_SENSOR20            AN20   
00098     #define CVD_SENSOR21            AN21   
00099     #define CVD_SENSOR22            AN22   
00100     #define CVD_SENSOR23            AN23   
00101     #define CVD_SENSOR24            AN24   
00102     #define CVD_SENSOR25            AN25   
00103     #define CVD_SENSOR26            AN26   
00104     #define CVD_SENSOR27            AN27   
00105     #define CVD_SENSOR28            AN28   
00106     #define CVD_SENSOR29            AN29  
00107 
00108     
00109 //**********************************************
00110 //
00111 // Typical-Use Configuration Options
00112 //
00113 //**********************************************
00114 
00115 // Do not edit these three timing definitions.
00116 #define CVD_100ms_Timing    (unsigned int)(((_XTAL_FREQ / 4) * 0.1)   / (224 * TMR0_PRESCALER * CVD_NUMBER_SENSORS))
00117 #define CVD_20ms_Timing     (unsigned int)(((_XTAL_FREQ / 4) * 0.02)  / (224 * TMR0_PRESCALER * CVD_NUMBER_SENSORS)) 
00118 #define CVD_17ms_Timing     (unsigned int)(((_XTAL_FREQ / 4) * 0.017) / (224 * TMR0_PRESCALER * CVD_NUMBER_SENSORS)) 
00119 
00120 
00121 
00122                                                     //====================================================
00123 #define CVD_SAMPLES_PER_SCAN        30
00124                                                     // This is the number of times each sensor will be 
00125                                                     //   scanned before asserting the mTouchCVD_dataReady() 
00126                                                     //   bit. If the application requires a specific
00127                                                     //   response time, there are several variables that 
00128                                                     //   will be important to the calculation of this
00129                                                     //   parameter.
00130                                                     //
00131                                                     // _XTAL_FREQ is the PICs oscillation frequency and
00132                                                     //   will determine how quickly the TMR0 counter will
00133                                                     //   increment.
00134                                                     //
00135                                                     // TMR0_PRESCALER also determines how quickly the 
00136                                                     //   TMR0 counter will increment. This value, located
00137                                                     //   in the OPTION register, is not set by the framework.
00138                                                     //
00139                                                     // CVD_NUMBER_SENSORS defines how many times the ISR
00140                                                     //   will interrupt between each decrement of the 
00141                                                     //   sample counter. The sample counter is initialized
00142                                                     //   with CVD_SAMPLES_PER_SCAN as its value.
00143                                                     //
00144                                                     // Allowable Range :: [ 1 to 65535 ]
00145                                                     //
00146                                                     // To help choose the appropriate number of samples,
00147                                                     //   we have provided some example timing calculations
00148                                                     //   to achieve 100, 20, and 17ms. You may either use
00149                                                     //   the defined label (ex: CVD_100ms_Timing) as the
00150                                                     //   value of CVD_SAMPLES_PER_SCAN or you can evaluate
00151                                                     //   the equation and place the integer result as the
00152                                                     //   value of this configuration option.
00153 
00154                                             
00155                                             
00156                                             //====================================================
00157 #define THRESHOLD_PRESS_SENSOR0         30  // These values determine how far away from             
00158 
00159 #define THRESHOLD_PRESS_SENSOR1         30  // the average the current reading must be in
00160 #define THRESHOLD_PRESS_SENSOR2         30  // order to trigger a press.
00161 #define THRESHOLD_PRESS_SENSOR3         30  //
00162 #define THRESHOLD_PRESS_SENSOR4         30  // Allowable Range :: [ 1 to 65535 ]
00163 #define THRESHOLD_PRESS_SENSOR5         30  //
00164 #define THRESHOLD_PRESS_SENSOR6         30  
00165 #define THRESHOLD_PRESS_SENSOR7         30  
00166 #define THRESHOLD_PRESS_SENSOR8         65  
00167 #define THRESHOLD_PRESS_SENSOR9         65  
00168 #define THRESHOLD_PRESS_SENSOR10        65
00169 #define THRESHOLD_PRESS_SENSOR11        65
00170 #define THRESHOLD_PRESS_SENSOR12        65
00171 #define THRESHOLD_PRESS_SENSOR13        65
00172 #define THRESHOLD_PRESS_SENSOR14        65
00173 #define THRESHOLD_PRESS_SENSOR15        65
00174 #define THRESHOLD_PRESS_SENSOR16        65
00175 #define THRESHOLD_PRESS_SENSOR17        65
00176 #define THRESHOLD_PRESS_SENSOR18        65
00177 #define THRESHOLD_PRESS_SENSOR19        65
00178 #define THRESHOLD_PRESS_SENSOR20        65
00179 #define THRESHOLD_PRESS_SENSOR21        65
00180 #define THRESHOLD_PRESS_SENSOR22        65
00181 #define THRESHOLD_PRESS_SENSOR23        65
00182 #define THRESHOLD_PRESS_SENSOR24        65
00183 
00184 
00185                                             //====================================================
00186 #define CVD_SCALING                 1       // This option will determine the amount of post-scaling
00187                                             //  that is implemented on the acquisition's accumulator
00188                                             //  register before being stored in the results register.
00189                                             // The scaling factor should be set so that it is not
00190                                             //  possible for the result register to overflow 
00191                                             //      (Max output value is 65535.)
00192                                             // When in doubt, 16 is usually the best option.
00193                                             //
00194                                             //
00195                                             // Options:
00196                                             //
00197                                             //   1 - No scaling is performed.
00198                                             //       1:1 relationship between accumulator and result
00199                                             //
00200                                             //  16 - Accumulator is divided by 16.
00201                                             //       16:1 relationship between accumulator and result
00202                                             //
00203                                             // 256 - Accumulator is divided by 256.
00204                                             //       256:1 relationship between accumulator and result
00205                                             //
00206 
00207 //**********************************************
00208 //
00209 // Communication Configuration
00210 //
00211 //**********************************************
00212 
00213                                             //====================================================
00214 //#define CVD_DEBUG 1                       // Enable CVD Data Logging through RS232, comment 
00215                                             //   this out to disable RS232 output.
00216                                             
00217     //#define CVD_DEBUG_OUTPUT_HEX          // Enabled: Output in Hex notation
00218                                             // Disabled: Output in Decimal notation
00219                                             
00220     #define CVD_DEBUG_SPEED     115200      // 115200 or 9600
00221     #define CVD_DEBUG_PIN       GP5         // When using a PIC that does not have a hardware UART
00222                                             //   module, this value determines which pin is used for
00223                                             //   the software implementation of a UART.
00224 
00225     #define CVD_DEBUG_OUTPUT_RAW            // You may output the raw sensor values, the sensor average
00226     //#define CVD_DEBUG_OUTPUT_AVG          // values, or both. Simply uncomment/comment one or more options.
00227                                                 
00228                                                 //====================================================
00229                                                 // System Version Control
00230                                                 //
00231                                                 //  These values are used only when communicating
00232                                                 //  with the mTouch PC software to relay
00233                                                 //  information about the current version of
00234                                                 //  firmware being used.
00235                                                 //
00236         #define CVD_Frame_Revision      01      //  Not yet implemented.
00237                                                 //
00238         #define CVD_Board_Revision      0001    //  Not yet implemented.
00239                                                 //
00240         #define CVD_Software_Revision   0002    //  Sets the current version of the GUI you are using
00241                                                 //  so the framework will know what communication
00242                                                 //  protocol is required.
00243                                                 //
00244                                                 //  Options:
00245                                                 //  
00246                                                 //      0001 - Sends raw data only
00247                                                 //      0002 - Sends raw data and button state
00248                                                 
00249                                             
00250 //**********************************************
00251 //
00252 // Advanced Configuration Options
00253 //
00254 //**********************************************
00255 
00256                                             //====================================================
00257 #define POWER_UP_SAMPLES            90      // This is the number of total scans that should be
00258                                             //   taken across ALL SENSORS before they will be 
00259                                             //   considered initialized.
00260                                             //
00261                                             // For example:
00262                                             //      Let's assume the dataReady flag is set once
00263                                             //      every 100ms due to the CVD_SAMPLES_PER_SCAN
00264                                             //      option and there are 8 sensors in our system.
00265                                             //      If we want a 3 second initialization time,
00266                                             //      we set POWER_UP_SAMPLES to 240.
00267                                             //
00268                                             //  (dataReady Toggle Rate / CVD_NUMBER_SENSORS) * POWER_UP_SAMPLES
00269                                             //  = Initialization Duration
00270                                             //
00271                                             //   Allowable Range :: [ 1 to 65535 ]
00272 
00273                                             //====================================================
00274 #define BUTTON_TIMEOUT              150     // This feature will reset the sensor's state if it
00275                                             //   remains in the 'pressed' state for too long.
00276                                             // This number is based off the amount of time between
00277                                             //   dataReady flag toggles.
00278                                             //
00279                                             // For example: 
00280                                             //      Let's assume the dataReady flag is set once
00281                                             //      every 100ms due to the CVD_SAMPLES_PER_SCAN
00282                                             //      option. If we want a timeout of 10sec, the
00283                                             //      BUTTON_TIMEOUT value should be set to 100.
00284                                             //      If we want a timeout of 7.4 seconds, then
00285                                             //      BUTTON_TIMEOUT should be set to 74.
00286                                             //
00287                                             // dataReady Toggle Rate * BUTTON_TIMEOUT = Timeout Duration
00288                                             //
00289                                             //
00290                                             //   Allowable Range :: [ 2 to 255 ]
00291                                             //
00292                                             // Setting to '0' or commenting the #define will
00293                                             //   disable the timeout feature.
00294                                             
00295                                             //====================================================
00296 #define AVG_ENABLE                          // Leaving this uncommented will enable 
00297                                             //   implementation of an average (or 'baseline')
00298                                             //   to track environmental changes in the system.
00299                                             // NOTE!: Turning this off is highly discouraged.
00300                                             
00301                                             
00302                                             //====================================================
00303     #define AVG_UPDATE              8       // When the average updates itself using a new 
00304                                             //   reading, this value determines what weight is 
00305                                             //   given to the reading variable in the 
00306                                             //   calculation of the new average.
00307                                             // The reading variable will have a weight of 
00308                                             //   1/AVG_UPDATE in the average calculation. 
00309                                             // Ex: If it is 4, the average calculation would be 
00310                                             //   average = (1/4)*reading + (3/4)*average
00311                                             // Allowed Values :: 1, 2, 4, 8, 16
00312 
00313                                             
00314                                             
00315                                             //====================================================
00316     #define AVG_RATE                4       // The update rate of the sensors' average values 
00317                                             //   when the current sensor value is farther away 
00318                                             //   from the average value than AVG_RATE_THRESHOLD. 
00319                                             // (Fastest = 1)
00320                                             // Allowable Range :: [ 1 to 255 ]
00321 
00322 //---------
00323 
00324                                             //====================================================
00325 #define RELEASE_THRESHOLD_FACTOR    0.5     // Defines the hysteresis between press and release
00326                                             //   In other words, '0.5' would result in a release
00327                                             //   threshold equal to half of the press threshold.
00328                                             //
00329                                             // Release Thresholds are calculated using the equation:
00330                                             //
00331                                             // Release Threshold = Press Threshold * Release Threshold Factor
00332                                             //
00333                                             // Example: Press Threshold             = 100
00334                                             //          Release Threshold Factor    = 0.5
00335                                             //          Release Threshold         --> 50
00336                                             //
00337                                             //   Allowable Range :: [ 0.30 to 1.00 ]
00338                                             
00339                                             //====================================================
00340 #define CVD_JITTER_ENABLE                   // This option should always be left on to maximize
00341                                             // noise immunity. 
00342                                             // 
00343                                             // The only time you may want to comment this out is if
00344                                             // you are looking at the sensor's waveform on a scope.
00345                                             // In that case, turning this off will allow you to 
00346                                             // see a clear waveform. 
00347 
00348                                             //====================================================
00349 #define CVD_JITTER_TYPE             1       // This option will choose between two 'random' seeds
00350                                             //   for a random number generator that is used to
00351                                             //   implement the jittering functionality in the
00352                                             //   acquisition process.
00353                                             //
00354                                             // Options:
00355                                             //
00356                                             //   0 - The least significant bits of the ADRESL
00357                                             //       register are used. This is the smallest
00358                                             //       and fastest jittering option but may not
00359                                             //       provide the same amount of randomness that
00360                                             //       the other option can provide.
00361                                             //
00362                                             //   1 - For a slightly higher processing and memory
00363                                             //       cost, this jittering routine implements
00364                                             //       a linear feedback shift register to maximize
00365                                             //       the randomness. Requires one byte of memory
00366                                             //       and 5 additional instruction cycles to execute.
00367 
00368                                             
00369                                             //====================================================
00370 #define DEBOUNCE_COUNT_RELEASE      1       // Number of consecutive scans a button must be seen
00371                                             //   as released before a 'released state' is declared
00372                                             //
00373                                             //   Allowable Range :: [ 1 to 255 ]
00374  
00375  
00376                                             //====================================================
00377 #define DEBOUNCE_COUNT_PRESS            1       // Number of consecutive scans a button must be seen 
00378                                             //   as pressed before a 'pressed state' is declared
00379                                             //
00380                                             //   Allowable Range :: [ 1 to 255 ]                                            
00381 
00382                                             
00383 #define NEGATIVE_CAPACITANCE        0       //====================================================
00384                                             // This option determines the method used to handle
00385                                             //   a negative capacitance shift. In other words, how
00386                                             //   the system will respond to a reading value shift
00387                                             //   in the opposite direction of a normal shift
00388                                             //   caused by a finger.
00389                                             // 
00390                                             // These shifts occur for a variety of reasons and you 
00391                                             //   may want to adjust this behavior based on your 
00392                                             //   system.
00393                                             //
00394                                             // Options:
00395                                             //
00396                                             //   0 - Normal Average Behavior
00397                                             //       (DEFAULT) No special behavior. The average 
00398                                             //       will update at the normal rate, as always.
00399                                             //       For Metal-over-Capacitive systems, a negative
00400                                             //       shift usually means a neighboring sensor is
00401                                             //       being pressed, so this is the best option to
00402                                             //       keep the current state of the sensor and
00403                                             //       allow it to be pressed quickly after a
00404                                             //       neighbor has been pressed.
00405                                             //
00406                                             //   1 - Increase Average Speed
00407                                             //       The average will ignore the AVG_RATE counter
00408                                             //       and update itself after each new reading
00409                                             //       value. This has the effect of speeding up
00410                                             //       the average until it catches up with the
00411                                             //       negative shift. 
00412                                             //
00413                                             //   2 - Average Directly Follows Reading
00414                                             //       The average will instantly follow a negative
00415                                             //       shift. This behavior is best for a system
00416                                             //       that needs a very fast response time. It
00417                                             //       will help prevent quick, repeated presses 
00418                                             //       from being missed due to the average not
00419                                             //       updating quickly enough.
00420 
00421 //**********************************************
00422 //
00423 // Advanced CVD Scan Routine Configuration Options
00424 //
00425 //**********************************************
00426                                             
00427 #define CVD_SETTLING_DELAY          5       //====================================================
00428                                             // The larger this value is, the more susceptible to
00429                                             //   noise the application will be. However, there is
00430                                             //   a minimum amount of time required to get full
00431                                             //   sensitivity. 
00432                                             //
00433                                             // The correct amount of delay is dependant on VDD,
00434                                             //   the PIC's oscillation frequency, and the hardware
00435                                             //   design. Because of this, the correct amount of
00436                                             //   delay cannot be determined by this framework.
00437                                             //
00438                                             // Correctly choosing the delay is easy once you can
00439                                             //   see the live sensor data on the PC's GUI. 
00440                                             //
00441                                             // DESIGN RULE:
00442                                             // Increase CVD_BALANCE_DELAY until changes in VDD 
00443                                             //   no longer cause changes in the sensor's reading.
00444                                             // 
00445                                             // For low-voltage applications, maximum sensitivity
00446                                             //   can be attained in a shorter amount of time.
00447                                             //   Just be sure to verify that the sensor's value
00448                                             //   does not change across the possible VDD range
00449                                             //   for your application.
00450 
00451 
00452 #define CVD_CHOLD_CHARGE_DELAY      5       //====================================================
00453                                             // The correct value for this delay is dependant on
00454                                             //   the reference source used to charge the internal 
00455                                             //   ADC capacitor.
00456                                             //
00457                                             // If the source is another sensor's I/O pin, this 
00458                                             //   delay will should be set so that CHOLD fully 
00459                                             //   reaches VDD despite changes in the reference
00460                                             //   sensor I/O's capacitance.
00461                                             //   
00462                                             //   For example: if SensorA uses SensorB as it's
00463                                             //   reference sensor, this delay should be set so
00464                                             //   so that there's enough time to fully charge
00465                                             //   to VDD even if the sensor being strongly pressed.
00466                                             //   (ie. when the sensor is at it's maximum amount of
00467                                             //   capacitance)
00468                                             //
00469                                             // If the source is the DAC, the delay time could be
00470                                             //   dependant on VDD.
00471                                             //   
00472                                             // DESIGN RULE:
00473                                             // Increase CVD_CHOLD_CHARGE_DELAY until pressing on
00474                                             //   one sensor no longer causes another sensor to
00475                                             //   decrease in value. ("negative crosstalk")
00476                                             //
00477                                             // Also, increase CVD_CHOLD_CHARGE_DELAY until the
00478                                             //   voltage change during the balancing step of the
00479                                             //   scan is maximized.

mTouch CVD Framework v1.1 documentation by  Click here to visit our website at www.microchip.com