atmel Qtouch8 Snsor is not detected

Status
Not open for further replies.

sammey_geek

Junior Member level 1
Joined
May 22, 2013
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Visit site
Activity points
1,395
hi...
i am working on a project called touch switch...i am using QT600-ATTINY88-QT8 evaluation board...i am enabling two keys...and using those keys.... iwant to toggle portd3 and portd4 for GET_SENSOR_STATE(6), AND PORTB6 and PORTB7 for GET_SENSOR_STATUS(7)......can anyone please help me..why it is not detecting....here is my code...
Code:
*----------------------------------------------------------------------------
include files 
----------------------------------------------------------------------------*/

#include <avr/io.h> 
#include <avr/interrupt.h> 
#define __delay_cycles(n)     __builtin_avr_delay_cycles(n) 
#define __enable_interrupt()  sei() 

/*  now include touch api.h with the localization defined above */ 
#include "touch_api.h" 

//#include "QDebug.h" 
//#include "QDebugTransport.h" 

/*----------------------------------------------------------------------------
manifest constants 
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
type definitions 
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
prototypes 
----------------------------------------------------------------------------*/
/*  initialise host app, pins, watchdog, etc    */ 
static void init_system( void ); 
/*  configure timer ISR to fire regularly   */ 
static void init_timer_isr( void ); 
/*  Assign the parameters values to global configuration parameter structure    */ 
static void qt_set_parameters( void ); 

static void  gangswitch(void); 

/*----------------------------------------------------------------------------
Structure Declarations 
----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------
macros 
----------------------------------------------------------------------------*/

#define GET_SENSOR_STATE(SENSOR_NUMBER) qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8)) 
#define GET_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER) qt_measure_data.qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER] 

#define TIMER_COUNTER_L TCNT1L 
#define TIMER_COUNTER_H TCNT1H 

/*----------------------------------------------------------------------------
global variables 
----------------------------------------------------------------------------*/
unsigned int gMsTimeout;// The ms timeout variable, 
// only access with NOT_TIMEDOUT and SET_TIMEOUT 
/* Timer period in msec. */ 
uint16_t qt_measurement_period_msec = 25u; 

/*#ifdef _DEBUG_INTERFACE_ 

extern uint16_t timestamp1_hword; 
extern uint16_t timestamp1_lword;    
extern uint16_t timestamp2_hword; 
extern uint16_t timestamp2_lword; 
extern uint16_t timestamp3_hword; 
extern uint16_t timestamp3_lword; 
#endif */ 
/*----------------------------------------------------------------------------
extern variables 
----------------------------------------------------------------------------*/
/* This configuration data structure parameters if needs to be changed will be
changed in the qt_set_parameters function */ 
extern qt_touch_lib_config_data_t qt_config_data; 
/* touch output - measurement data */ 
extern qt_touch_lib_measure_data_t qt_measure_data; 
/* Get sensor delta values */ 
extern int16_t qt_get_sensor_delta( uint8_t sensor); 

/*----------------------------------------------------------------------------
static variables 
----------------------------------------------------------------------------*/
/* flag set by timer ISR when it's time to measure touch */ 
static volatile uint8_t time_to_measure_touch = 0u; 
/* current time, set by timer ISR */ 
volatile uint16_t current_time_ms_touch = 0u; 

/*============================================================================
Name    :   main 
------------------------------------------------------------------------------
Purpose :   main code entry point 
Input   :   n/a 
Output  :   n/a 
Notes   : 
============================================================================*/
int main( void ) 
{ 
    /*status flags to indicate the re-burst for library*/ 
    uint16_t status_flag = 0u; 
    uint16_t burst_flag = 0u; 

    init_timer_isr(); 
/*#ifdef _DEBUG_INTERFACE_ 
    timestamp1_hword = current_time_ms_touch; 
    timestamp1_lword = (uint16_t)TIMER_COUNTER_L; 
    timestamp1_lword |= (uint16_t)(TIMER_COUNTER_H << 8); 
#endif */ 
    /* initialise host app, pins, watchdog, etc */ 
    init_system(); 

    /* Config sensors */ 
    qt_enable_slider( CHANNEL_0, CHANNEL_2, NO_AKS_GROUP, 10u, HYST_6_25, RES_8_BIT, 0u  ); 
    qt_enable_rotor( CHANNEL_3, CHANNEL_5, NO_AKS_GROUP, 10u, HYST_6_25, RES_8_BIT, 0u ); 
    qt_enable_key( CHANNEL_6, NO_AKS_GROUP, 10u, HYST_6_25 ); 
    qt_enable_key( CHANNEL_7, NO_AKS_GROUP, 10u, HYST_6_25 ); 

    /* initialise touch sensing */ 
    qt_init_sensing(); 
    qt_set_parameters(); 

    /*  Address to pass address of user functions   */ 
    /*  This function is called after the library has made capacitive measurements, 
    *   but before it has processed them. The user can use this hook to apply filter 
    *   functions to the measured signal values.(Possibly to fix sensor layout faults)    */ 
    qt_filter_callback = 0; 
//#ifdef _DEBUG_INTERFACE_    
   /* Initialize debug protocol */ 
    
   //QDebug_Init();    
//#endif 
    __enable_interrupt(); 
//#ifdef _DEBUG_INTERFACE_ 
    /* Process commands from PC */ 
  //  QDebug_ProcessCommands(); 
//#endif 
    /* loop forever */ 
    for( ; ; ) 
    {    if( time_to_measure_touch ) 
        { 
            time_to_measure_touch = 0u; 
            do 
            { 
           /* #ifdef _DEBUG_INTERFACE_ 
             timestamp2_hword = current_time_ms_touch; 
                timestamp2_lword = (uint16_t)TIMER_COUNTER_L; 
                timestamp2_lword |= (uint16_t)(TIMER_COUNTER_H << 8); 
         #endif */ 
                /* Measure touch once */ 
                status_flag = qt_measure_sensors( current_time_ms_touch ); 
      /*   #ifdef _DEBUG_INTERFACE_ 
                timestamp3_hword = current_time_ms_touch; 
                timestamp3_lword = (uint16_t)TIMER_COUNTER_L; 
                timestamp3_lword |= (uint16_t)(TIMER_COUNTER_H << 8); 
         #endif*/ 
                burst_flag = status_flag & QTLIB_BURST_AGAIN; 
         //#ifdef _DEBUG_INTERFACE_ 
                /* send debug data */ 
             //   QDebug_SendData(status_flag); 
      //   #endif 
                /* Time-critical host application code goes here */ 

            }while (burst_flag) ; 
            //#ifdef _DEBUG_INTERFACE_ 
            /* Process commands from PC */ 
            //QDebug_ProcessCommands(); 
         //#endif 
        
      } 
        gangswitch(); 
        /* Non time-critical application code goes here */ 
    } 
} 

/*============================================================================
Name    :   init_timer_isr 
------------------------------------------------------------------------------
Purpose :   configure timer ISR to fire regularly 
Input   :   n/a 
Output  :   n/a 
Notes   : 
============================================================================*/
static void init_timer_isr( void ) 
{ 
   /*  set timer compare value (how often timer ISR will fire) */ 
   OCR1A = ( TICKS_PER_MS * qt_measurement_period_msec); 
   /*  enable timer ISR */ 
   TIMSK1 |= (1u << OCIE1A); 
   /*  timer prescaler = system clock / 8  */ 
   TCCR1B |= (1u << CS11); 
   /*  timer mode = CTC (count up to compare value, then reset)    */ 
   TCCR1B |= (1u << WGM12); 
} 

/*============================================================================
Name    :   init_system 
------------------------------------------------------------------------------
Purpose :   initialise host app, pins, watchdog, etc 
Input   :   n/a 
Output  :   n/a 
Notes   : 
============================================================================*/
static void init_system( void ) 
{ 
   /*  run at 4MHz */ 
   asm("ldi r16,0x80"); 
   asm("sts 0x61,r16"); 
   asm("ldi r16,0x01"); 
   asm("sts 0x61,r16"); 
   /*  disable pull-ups    */ 
   MCUCR |= (1u << PUD); 
} 

/*============================================================================
Name    :   timer_isr 
------------------------------------------------------------------------------
Purpose :   timer 1 compare ISR 
Input   :   n/a 
Output  :   n/a 
Notes   : 
============================================================================*/
ISR(TIMER1_COMPA_vect) 
{ 
   if (gMsTimeout) 
      gMsTimeout--; 
   { 
   } 
   /*  set flag: it's time to measure touch    */ 
    
   time_to_measure_touch = 1u; 
   /*  update the current time */ 
   current_time_ms_touch += qt_measurement_period_msec; 
} 

/*============================================================================
Name    :   qt_set_parameters 
------------------------------------------------------------------------------
Purpose :   This will fill the default threshold values in the configuration 
data structure.But User can change the values of these parameters . 
Input   :   n/a 
Output  :   n/a 
Notes   :   initialize configuration data for processing 
============================================================================*/
static void qt_set_parameters( void ) 
{ 
   qt_config_data.qt_di              = DEF_QT_DI; 
   qt_config_data.qt_neg_drift_rate  = DEF_QT_NEG_DRIFT_RATE; 
   qt_config_data.qt_pos_drift_rate  = DEF_QT_POS_DRIFT_RATE; 
   qt_config_data.qt_max_on_duration = DEF_QT_MAX_ON_DURATION; 
   qt_config_data.qt_drift_hold_time = DEF_QT_DRIFT_HOLD_TIME; 
   qt_config_data.qt_recal_threshold = DEF_QT_RECAL_THRESHOLD; 
   qt_config_data.qt_pos_recal_delay = DEF_QT_POS_RECAL_DELAY;    
} 

/* 
HOST APPLICATION CODE */ 



void gangswitch(void) 
{ 
    
      DDRD = (1u << PORTD3)|(1u << PORTD4); 
      DDRB = (1u << PORTB6) | (1U << PORTB7); 
      //DDRC |= (1u << DDC7); 
      //DDRA = (1u << DDA0); 
  
        if((GET_SENSOR_STATE(6)) != 0) 
         { 
         PORTD |= (1u << PORTD3) | (1u << PORTD4); 
         } 
      else 
          { 
             PORTD &= ~((1u << PORTD3) | (1u << PORTD4)); 
          } 
      if((GET_SENSOR_STATE(7)) != 0) 
          { 
            PORTB |= (1u << PORTB6) | (1u << PORTB7); 
         } 
       else 
          { 
             PORTB &= ~((1u << PORTB6) | (1u << PORTB7)); 
         } 
    
          
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…