Advertisement
Guest User

CTS_HAL.c

a guest
May 18th, 2014
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.22 KB | None | 0 0
  1. #ifdef RO_PINOSC_TA0
  2. /***************************************************************************//**
  3.  * @brief   RO method capactiance measurement using PinOsc IO, and TimerA0
  4.  *
  5.  *          Schematic Description:
  6.  *
  7.  *     \n      element-----+->Px.y
  8.  *
  9.  *     \n   The measurement window is accumulation_cycles/ACLK. The ACLK is
  10.  *          used to generate a capture event via the internal connection CCIOB.
  11.  *          The counts within the TA0R that have accumulated during the
  12.  *          measurement window represents the capacitance of the element.
  13.  *
  14.  * @param   group Pointer to the structure describing the Sensor to be measured
  15.  * @param   counts Pointer to where the measurements are to be written
  16.  * @return  none
  17.  ******************************************************************************/
  18. extern uint8_t CCR0_interrupted;
  19.  
  20. inline void my_delay(unsigned int d) {  // Delays d instruction cycles (d µs @ 1MHz)
  21.     for(; d > 0 ; d--) {
  22.         __no_operation();
  23.     }
  24. }
  25.  
  26. void TI_CTS_RO_PINOSC_TA0_HAL(const struct Sensor *group,uint16_t *counts)
  27. {
  28.     uint8_t i;
  29.     uint16_t j;
  30.     //** Context Save
  31. //  TIMERA0: TA0CTL, TA0CCTL0
  32. //  Ports: PxSEL, PxSEL2
  33.     uint16_t contextSaveTA0CTL,contextSaveTA0CCTL0,contextSaveTA0CCR0;
  34.     uint8_t contextSaveSel,contextSaveSel2;
  35.  
  36.     contextSaveTA0CTL = TA0CTL;
  37.     contextSaveTA0CCTL0 = TA0CCTL0;
  38.     contextSaveTA0CCR0 = TA0CCR0;
  39.  
  40.     //** Setup Measurement timer***************************************************
  41.     // Choices are TA0,TA1,TB0,TB1,TD0,TD1 these choices are pushed up into the
  42.     // capacitive touch layer.
  43.  
  44.     // Configure and Start Timer
  45.     TA0CTL = TASSEL_3+MC_2;                // INCLK, continuous up mode
  46.     for (i =0; i< (group->numElements); i++)
  47.     {
  48.         // Context Save
  49.         contextSaveSel = *((group->arrayPtr[i])->inputPxselRegister);
  50.         contextSaveSel2 = *((group->arrayPtr[i])->inputPxsel2Register);
  51.         // Configure Ports for relaxation oscillator
  52.         j = (group->accumulationCycles);
  53.         *((group->arrayPtr[i])->inputPxselRegister) &= ~((group->arrayPtr[i])->inputBits);
  54.         *((group->arrayPtr[i])->inputPxsel2Register) |= ((group->arrayPtr[i])->inputBits);
  55.         CCR0_interrupted = 0;
  56.         TA0CCTL0 = CM_3+CCIS_1+CAP+CCIE;        // Pos&Neg,ACLK (CCI0B),Cap & interrupt
  57.  
  58.         // Put the MSP430 into LPM0
  59.         while(!CCR0_interrupted) {
  60.             P1OUT &= ~BIT6;
  61.             _BIS_SR(LPM0_bits+GIE);
  62.         }
  63.  
  64.         TA0CTL |= TACLR;                        // Clear Timer_A TAR
  65.         while(j--)
  66.         {
  67.             CCR0_interrupted = 0;
  68.             TA0CCTL0 = CM_3+CCIS_1+CAP+CCIE;            // Pos&Neg, ACLK (CCI0B), Cap & interrupt
  69.             //P1OUT |= BIT0;
  70.  
  71.             //* Put the MSP430 into LPM0
  72.             while(!CCR0_interrupted) {
  73.                 P1OUT &= ~BIT6;
  74.                 _BIS_SR(LPM0_bits+GIE);
  75.             }
  76.             //*/
  77.             //P1OUT &= ~BIT0;
  78.  
  79.         }
  80.         counts[i] = TA0CCR0;                    // Save result
  81.         TA0CTL = TASSEL_3+MC_2;
  82.         // Context Restore
  83.         *((group->arrayPtr[i])->inputPxselRegister) = contextSaveSel;
  84.         *((group->arrayPtr[i])->inputPxsel2Register) = contextSaveSel2;
  85.     }
  86.     // End Sequence
  87.     // Context Restore
  88.     TA0CTL = contextSaveTA0CTL;
  89.     TA0CCTL0 = contextSaveTA0CCTL0;
  90.     TA0CCR0 = contextSaveTA0CCR0;
  91. }
  92. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement