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

mTouchCVD_Acquistion.c

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_Acquisition.c
00006  *  Dependencies:    mTouchCVD.h
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 Acquisition Module
00014  *                   - Implements the CVD acquisition process through use
00015  *                     of the TMR0 ISR. Additional ISR functions should be
00016  *                     carefully designed to not interfere with the mTouch
00017  *                     interrupt service.
00018  *                   - See the documentation for more information about
00019  *                     implementing the framework with your application.
00020  *************************************************************************/
00021 /**************************************************************************
00022  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 
00023  * any derivatives created by any person or entity by or on your behalf, 
00024  * exclusively with Microchip's products in accordance with applicable
00025  * software license terms and conditions, a copy of which is provided for
00026  * your referencein accompanying documentation. Microchip and its licensors 
00027  * retain all ownership and intellectual property rights in the 
00028  * accompanying software and in all derivatives hereto. 
00029  * 
00030  * This software and any accompanying information is for suggestion only. 
00031  * It does not modify Microchip's standard warranty for its products. You 
00032  * agree that you are solely responsible for testing the software and 
00033  * determining its suitability. Microchip has no obligation to modify, 
00034  * test, certify, or support the software. 
00035  * 
00036  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
00037  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
00038  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
00039  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 
00040  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 
00041  * APPLICATION. 
00042  * 
00043  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 
00044  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 
00045  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 
00046  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 
00047  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 
00048  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 
00049  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 
00050  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 
00051  * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 
00052  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 
00053  * 
00054  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 
00055  * THESE TERMS. 
00056  *************************************************************************/
00057  /****************************************************************************
00058  * NOTE:  This is written in assembly to guarantee proper timing control for noise robustness.
00059  * PORTING THIS CODE TO 'C' COULD MAKE IT LESS ROBUST TO NOISE ENVIRONMENTS
00060  * Revision History
00061  * Date         Rev      Author  Comments
00062  * 09.20.10    1.00         Public Release
00063  ****************************************************************************/
00068 #include "includes/mTouchCVD.h"
00069 
00075 
00076       unsigned short long   CVD_Acq_Filtered_Data [CVD_NUMBER_SENSORS]; 
00077 bank0 unsigned int          last_result;                                
00078 bank0 unsigned int          sample_counter = CVD_SAMPLES_PER_SCAN;      
00079 
00080       unsigned char mTouchCVD_dataReady;                                
00081       unsigned int  sensor_data                 [CVD_NUMBER_SENSORS];   
00082       unsigned int  CVDSensorData               [CVD_NUMBER_SENSORS];   
00083 
00084 #if defined(CVD_JITTER_ENABLE) && (CVD_JITTER_TYPE == 1)
00085       unsigned char mTouchCVD_jitter = 0x55;                            
00086 #endif
00087 #if CVD_NUMBER_SENSORS > 1
00088 bank0 unsigned char current_sensor;                                     
00089 #endif
00090 #if defined(CVD_DELAY_VARIABLE_REQUIRED)
00091       unsigned char mTouchCVD_delayCount;                               
00092 #endif
00093 
00094 #if defined(_PIC14)
00095 // These state-saving variables are only required in non-enhanced core PIC microcontrollers. They are automatically omitted if not needed.
00096 near  unsigned char int_w;                                              
00097 near  unsigned char int_status;                                         
00098 near  unsigned char int_fsr;                                            
00099 near  unsigned char int_pclath;                                         
00100 // TIP: The 'near' qualifier tells the compiler to place these variables in common memory so they may be accessed from any bank.
00101 #endif
00102 
00103 
00104 
00117 void interrupt ISR(void)
00118 {
00119 #asm
00120 
00121 #if defined(_12F617) && (_HTC_VER_MAJOR_ == 9 && _HTC_VER_MINOR_ == 80)
00122     #include <cas12F617.h>      // HiTech's 9.80 compiler's caspic.h includes the 617 header file twice, causing compiling 
00123                                 // errors. This will by-pass the mistake by directly including the correct file only once.
00124                                 // This issue has been fixed as of the 9.81 release.
00125 #else
00126     #include <caspic.h>
00127 #endif
00128 
00129 mTouchCVD_ISR:
00130 #endasm 
00131 
00137     SAVE_STATE();
00138 
00143     CHECK_AND_CLEAR_TMR0IF();
00144     
00149     JITTER_START_TIME(); 
00150 
00152     WAIT_FOR_GODONE_BIT();
00153     // TODO: Update this check to perform an action if the Go/Done flag has
00154     //       not cleared. When called off an interrupt, the Go/Done flag
00155     //       should always have enough time to be cleared. If it isn't, it
00156     //       means something has broken and action needs to be taken.
00157     //       PIC16F193x (Mask A1) devices' ADC temp issue, for example.
00158 
00164     STORE_LAST_RESULT();
00165     
00170     #pragma switch rangetable
00171     // TIP: The 'switch rangetable' option tells the compiler to implement
00172     //      the following switch statement as a jump table. It is still not as
00173     //      efficient as hand-coded assembly, however.
00174     GENERATE_JUMP_TABLE();    
00175    
00184 #asm
00185 sensor_0:                                               // This label is used by the jump table, above.
00186 #endasm
00187     #if CVD_NUMBER_SENSORS > 0
00188         READ_SENSOR(0, CVD_SENSOR0_REFERENCE);          // WARNING: Only in the single-sensor configuration 
00189                                                         //          may a sensor use itself as the reference. 
00190                                                         //          Sending the same number as both arguments
00191                                                         //          of the READ_SENSOR macro in any other
00192                                                         //          configuration will cause the CVD scan to
00193                                                         //          no longer function correctly.
00194                                                         //
00195                                                         //          By default, sensors use the previously
00196                                                         //          scanned sensor as their reference.
00197                                                         
00198         #if CVD_NUMBER_SENSORS > 1                      // If there is more than one sensor,
00199         EXIT_SENSOR(current_sensor);                    // Use the normal ISR exiting method
00200         #else                                           // If there is only one sensor,
00201         EXIT_LAST_SENSOR(0);                            // Use the 'last sensor' exiting method
00202         #endif
00203     #endif
00204 #asm
00205 sensor_1:
00206 #endasm
00207     #if CVD_NUMBER_SENSORS > 1
00208         READ_SENSOR(1, 0);                              // Scan sensor1 using sensor0 as the reference
00209         #if CVD_NUMBER_SENSORS > 2                      // If this is not the last sensor,
00210         EXIT_SENSOR(current_sensor);                    // Use the normal ISR exiting method
00211         #else                                           // If this is the last sensor,
00212         EXIT_LAST_SENSOR(current_sensor);               // Use the 'last sensor' exiting method
00213         #endif
00214     #endif
00215 #asm
00216 sensor_2:
00217 #endasm
00218     #if CVD_NUMBER_SENSORS > 2
00219         READ_SENSOR(2, 1);                              // etc
00220         #if CVD_NUMBER_SENSORS > 3
00221         EXIT_SENSOR(current_sensor);
00222         #else
00223         EXIT_LAST_SENSOR(current_sensor);
00224         #endif
00225     #endif
00226 #asm
00227 sensor_3:
00228 #endasm
00229     #if CVD_NUMBER_SENSORS > 3
00230         READ_SENSOR(3, 2);                              
00231         #if CVD_NUMBER_SENSORS > 4
00232         EXIT_SENSOR(current_sensor);
00233         #else
00234         EXIT_LAST_SENSOR(current_sensor);
00235         #endif
00236     #endif
00237 #asm
00238 sensor_4:
00239 #endasm
00240     #if CVD_NUMBER_SENSORS > 4
00241         READ_SENSOR(4, 3);
00242         #if CVD_NUMBER_SENSORS > 5
00243         EXIT_SENSOR(current_sensor);
00244         #else
00245         EXIT_LAST_SENSOR(current_sensor);
00246         #endif
00247     #endif
00248 #asm
00249 sensor_5:
00250 #endasm
00251     #if CVD_NUMBER_SENSORS > 5
00252         READ_SENSOR(5, 4);
00253         #if CVD_NUMBER_SENSORS > 6
00254         EXIT_SENSOR(current_sensor);
00255         #else
00256         EXIT_LAST_SENSOR(current_sensor);
00257         #endif
00258     #endif
00259 #asm
00260 sensor_6:
00261 #endasm
00262     #if CVD_NUMBER_SENSORS > 6
00263         READ_SENSOR(6, 5);
00264         #if CVD_NUMBER_SENSORS > 7
00265         EXIT_SENSOR(current_sensor);
00266         #else
00267         EXIT_LAST_SENSOR(current_sensor);
00268         #endif
00269     #endif
00270 #asm
00271 sensor_7:
00272 #endasm
00273     #if CVD_NUMBER_SENSORS > 7
00274         READ_SENSOR(7, 6);
00275         #if CVD_NUMBER_SENSORS > 8
00276         EXIT_SENSOR(current_sensor);
00277         #else
00278         EXIT_LAST_SENSOR(current_sensor);
00279         #endif
00280     #endif
00281 #asm
00282 sensor_8:
00283 #endasm
00284     #if CVD_NUMBER_SENSORS > 8
00285         READ_SENSOR(8, 7);
00286         #if CVD_NUMBER_SENSORS > 9
00287         EXIT_SENSOR(current_sensor);
00288         #else
00289         EXIT_LAST_SENSOR(current_sensor);
00290         #endif
00291     #endif
00292 #asm
00293 sensor_9:
00294 #endasm
00295     #if CVD_NUMBER_SENSORS > 9
00296         READ_SENSOR(9, 8);
00297         #if CVD_NUMBER_SENSORS > 10
00298         EXIT_SENSOR(current_sensor);
00299         #else
00300         EXIT_LAST_SENSOR(current_sensor);
00301         #endif
00302     #endif
00303 #asm
00304 sensor_10:
00305 #endasm
00306     #if CVD_NUMBER_SENSORS > 10
00307         READ_SENSOR(10, 9);
00308         #if CVD_NUMBER_SENSORS > 11
00309         EXIT_SENSOR(current_sensor);
00310         #else
00311         EXIT_LAST_SENSOR(current_sensor);
00312         #endif
00313     #endif
00314 #asm
00315 sensor_11:
00316 #endasm
00317     #if CVD_NUMBER_SENSORS > 11
00318         READ_SENSOR(11, 10);
00319         #if CVD_NUMBER_SENSORS > 12
00320         EXIT_SENSOR(current_sensor);
00321         #else
00322         EXIT_LAST_SENSOR(current_sensor);
00323         #endif
00324     #endif
00325 #asm
00326 sensor_12:
00327 #endasm
00328     #if CVD_NUMBER_SENSORS > 12
00329         READ_SENSOR(12, 11);
00330         #if CVD_NUMBER_SENSORS > 13
00331         EXIT_SENSOR(current_sensor);
00332         #else
00333         EXIT_LAST_SENSOR(current_sensor);
00334         #endif
00335     #endif
00336 #asm
00337 sensor_13:
00338 #endasm
00339     #if CVD_NUMBER_SENSORS > 13
00340         READ_SENSOR(13, 12);
00341         #if CVD_NUMBER_SENSORS > 14
00342         EXIT_SENSOR(current_sensor);
00343         #else
00344         EXIT_LAST_SENSOR(current_sensor);
00345         #endif
00346     #endif
00347 #asm
00348 sensor_14:
00349 #endasm
00350     #if CVD_NUMBER_SENSORS > 14
00351         READ_SENSOR(14, 13);
00352         #if CVD_NUMBER_SENSORS > 15
00353         EXIT_SENSOR(current_sensor);
00354         #else
00355         EXIT_LAST_SENSOR(current_sensor);
00356         #endif
00357     #endif
00358 #asm
00359 sensor_15:
00360 #endasm
00361     #if CVD_NUMBER_SENSORS > 15
00362         READ_SENSOR(15, 14);
00363         #if CVD_NUMBER_SENSORS > 16
00364         EXIT_SENSOR(current_sensor);
00365         #else
00366         EXIT_LAST_SENSOR(current_sensor);
00367         #endif
00368     #endif
00369 #asm
00370 sensor_16:
00371 #endasm
00372     #if CVD_NUMBER_SENSORS > 16
00373         READ_SENSOR(16, 15);
00374         #if CVD_NUMBER_SENSORS > 17
00375         EXIT_SENSOR(current_sensor);
00376         #else
00377         EXIT_LAST_SENSOR(current_sensor);
00378         #endif
00379     #endif
00380 #asm
00381 sensor_17:
00382 #endasm
00383     #if CVD_NUMBER_SENSORS > 17
00384         READ_SENSOR(17, 16);
00385         #if CVD_NUMBER_SENSORS > 18
00386         EXIT_SENSOR(current_sensor);
00387         #else
00388         EXIT_LAST_SENSOR(current_sensor);
00389         #endif
00390     #endif
00391 #asm
00392 sensor_18:
00393 #endasm
00394     #if CVD_NUMBER_SENSORS > 18
00395         READ_SENSOR(18, 17);
00396         #if CVD_NUMBER_SENSORS > 19
00397         EXIT_SENSOR(current_sensor);
00398         #else
00399         EXIT_LAST_SENSOR(current_sensor);
00400         #endif
00401     #endif
00402 #asm
00403 sensor_19:
00404 #endasm
00405     #if CVD_NUMBER_SENSORS > 19
00406         READ_SENSOR(19, 18);
00407         #if CVD_NUMBER_SENSORS > 20
00408         EXIT_SENSOR(current_sensor);
00409         #else
00410         EXIT_LAST_SENSOR(current_sensor);
00411         #endif
00412     #endif
00413 #asm
00414 sensor_20:
00415 #endasm
00416     #if CVD_NUMBER_SENSORS > 20
00417         READ_SENSOR(20, 19);
00418         #if CVD_NUMBER_SENSORS > 21
00419         EXIT_SENSOR(current_sensor);
00420         #else
00421         EXIT_LAST_SENSOR(current_sensor);
00422         #endif
00423     #endif
00424 #asm
00425 sensor_21:
00426 #endasm
00427     #if CVD_NUMBER_SENSORS > 21
00428         READ_SENSOR(21, 20);
00429         #if CVD_NUMBER_SENSORS > 22
00430         EXIT_SENSOR(current_sensor);
00431         #else
00432         EXIT_LAST_SENSOR(current_sensor);
00433         #endif
00434     #endif
00435 #asm
00436 sensor_22:
00437 #endasm
00438     #if CVD_NUMBER_SENSORS > 22
00439         READ_SENSOR(22, 21);
00440         #if CVD_NUMBER_SENSORS > 23
00441         EXIT_SENSOR(current_sensor);
00442         #else
00443         EXIT_LAST_SENSOR(current_sensor);
00444         #endif
00445     #endif
00446 #asm
00447 sensor_23:
00448 #endasm
00449     #if CVD_NUMBER_SENSORS > 23
00450         READ_SENSOR(23, 22);
00451         #if CVD_NUMBER_SENSORS > 24
00452         EXIT_SENSOR(current_sensor);
00453         #else
00454         EXIT_LAST_SENSOR(current_sensor);
00455         #endif
00456     #endif
00457 #asm
00458 sensor_24:
00459 #endasm
00460     #if CVD_NUMBER_SENSORS > 24
00461         READ_SENSOR(24, 23);
00462         #if CVD_NUMBER_SENSORS > 25
00463         EXIT_SENSOR(current_sensor);
00464         #else
00465         EXIT_LAST_SENSOR(current_sensor);
00466         #endif
00467     #endif
00468 #asm
00469 sensor_25:
00470 #endasm
00471     #if CVD_NUMBER_SENSORS > 25
00472         READ_SENSOR(25, 24);
00473         #if CVD_NUMBER_SENSORS > 26
00474         EXIT_SENSOR(current_sensor);
00475         #else
00476         EXIT_LAST_SENSOR(current_sensor);
00477         #endif
00478     #endif
00479 #asm
00480 sensor_26:
00481 #endasm
00482     #if CVD_NUMBER_SENSORS > 26
00483         READ_SENSOR(26, 25);
00484         #if CVD_NUMBER_SENSORS > 27
00485         EXIT_SENSOR(current_sensor);
00486         #else
00487         EXIT_LAST_SENSOR(current_sensor);
00488         #endif
00489     #endif
00490 #asm
00491 sensor_27:
00492 #endasm
00493     #if CVD_NUMBER_SENSORS > 27
00494         READ_SENSOR(27, 26);
00495         #if CVD_NUMBER_SENSORS > 28
00496         EXIT_SENSOR(current_sensor);
00497         #else
00498         EXIT_LAST_SENSOR(current_sensor);
00499         #endif
00500     #endif
00501 #asm
00502 sensor_28:
00503 #endasm
00504     #if CVD_NUMBER_SENSORS > 28
00505         READ_SENSOR(28, 27);
00506         #if CVD_NUMBER_SENSORS > 29
00507         EXIT_SENSOR(current_sensor);
00508         #else
00509         EXIT_LAST_SENSOR(current_sensor);
00510         #endif
00511     #endif
00512 #asm
00513 sensor_29:
00514 #endasm
00515     #if CVD_NUMBER_SENSORS > 29
00516         READ_SENSOR(29, 28);
00517         EXIT_LAST_SENSOR(current_sensor);
00518     #endif
00519 
00525     GENERATE_STORAGE_FUNCTION();    
00526     
00531     SET_DATA_READY_FLAG();
00532 
00534     
00535 #asm
00536 END_ISR:
00537 #endasm
00538 
00543     RESTORE_STATE();
00544 
00555     #asm    
00556     retfie
00557     #endasm
00558     
00560 
00568 
00569 #asm
00570 decimate:
00571 #endasm
00572     CVD_DECIMATE();         // Compare the previous sensor's scan result with
00573                             // its decimated latch register. If the current 
00574                             // result is larger, increment the latch register.
00575 #asm
00576 sensor_smaller:
00577 #endasm
00578     CVD_SENSOR_SMALLER();   // If the current result is smaller, decrement the
00579                             // latch register.
00580 #asm
00581 decimate_end:
00582 #endasm
00583     CVD_DECIMATE_END();     // Now add the new value of the latch register into
00584                             // the accumulater register. Finally, grab the
00585                             // result from the ADC scan that was performed in
00586                             // the first half of the READ_SENSOR() macro 
00587                             // currently under execution.
00588     
00589 
00590 }

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