M16 and QTouch problem

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have used a 15mm x 15mm square area on my pcb to connect just a single button to ATmega16,and I have used the following code, but I do not get any touch sensing data. Do you have any idea?

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


static volatile uint16_t current_time_ms_touch = 0u;
/* Timer period in msec. */
uint16_t qt_measurement_period_msec = 25u;
/* flag set by timer ISR when it's time to measure touch */
static volatile uint8_t time_to_measure_touch = 0u;


ISR(TIMER1_OVF_vect)
{
	// Reinitialize Timer1 value
	TCNT1H=0x6D84 >> 8;
	TCNT1L=0x6D84 & 0xff;
	/*  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;
}



int main(void)
{
	/*status flags to indicate the re-burst for library*/
	static uint16_t status_flag = 0u;
	static uint16_t burst_flag = 0u;

	//enable led
	DDRC |= _BV(7);
	
	
	/* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */
	config_sensors();

	/* initialize touch sensing */
	qt_init_sensing();

	/*  Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */
	qt_set_parameters( );
	/* configure timer ISR to fire regularly */
	/*  set timer compare value (how often timer ISR will fire) */
	// Timer/Counter 1 initialization
	// Clock source: System Clock
	// Clock value: 1500.000 kHz
	// Mode: Normal top=0xFFFF
	// OC1A output: Discon.
	// OC1B output: Discon.
	// Noise Canceler: Off
	// Input Capture on Falling Edge
	// Timer1 Overflow Interrupt: On
	// Input Capture Interrupt: Off
	// Compare A Match Interrupt: Off
	// Compare B Match Interrupt: Off
	TCCR1A=0x00;
	TCCR1B=0x02;
	TCNT1H=0x6D;
	TCNT1L=0x84;
	ICR1H=0x00;
	ICR1L=0x00;
	OCR1AH=0x00;
	OCR1AL=0x00;
	OCR1BH=0x00;
	OCR1BL=0x00;
	// Timer(s)/Counter(s) Interrupt(s) initialization
	TIMSK=0x04;
 /*  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;
	qt_config_data.qt_di = 2;
	sei();
	while(1)
    {
        if( time_to_measure_touch )
        {

	        /*  clear flag: it's time to measure touch  */
	        time_to_measure_touch = 0u;

	        do {
		        /*  one time measure touch sensors    */
		        status_flag = qt_measure_sensors( current_time_ms_touch );
		        
		        burst_flag = status_flag & QTLIB_BURST_AGAIN;
		        if (burst_flag!= 0u)
		        {
			        
			        /*Time critical host application code goes here*/
			        
		        }
		        
		        else
		        {
			        if(GET_SENSOR_STATE(0))
			        {
				        PORTC &= ~_BV(7);

			        }
			        else
			        {
				        PORTC |= _BV(7);
			        }
		        }
	        }while (  burst_flag) ;

		
		
		}			
    }
}


static void qt_set_parameters( void )
{
    /*  This will be modified by the user to different values   */
    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;
}


static void config_sensors(void)
{
  qt_enable_key( CHANNEL_0, AKS_GROUP_1, 4u, HYST_6_25 );
}

Attachment(s): 

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ali have you tried the Qtouch forum? http://forum.atmel.com/forumdisp... I know it was horribly slow last time I visited but there MAY be more people able to help there.

Yep tried again still slow :(

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is AVCC connected?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is AVCC connected

yes

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has anyone ever used the atmel touch library?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried but failed, not smart enough :( so I used a pre-programmed chips instead QT113 (now EOL).

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Recently i tried to add a touch button facility to a already project of mine to replace a push button but with no success.I tried with polling a pin with having a register increased inside a sbis PINB,x loop and then compared with a value but with no luck.
After a lot of effort i gave up,the project uses the external interrupt and the timer and the interrupts are causing different charging time values since the polling loop as is increased is interrupted while capacitor is still in charge process and cannot compared with any known constant value.