| Author |
Message |
|
|
Posted: May 26, 2012 - 04:45 PM |
|


Joined: Dec 22, 2005
Posts: 1281
Location: shiraz , iran
|
|
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?
Code:
#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 );
}
|
_________________ I love Digital
and you who involved in it!
|
| |
|
|
|
|
|
Posted: May 26, 2012 - 11:14 PM |
|


Joined: Mar 28, 2001
Posts: 20630
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
|
|
|
|
|
Posted: May 27, 2012 - 01:36 AM |
|

Joined: May 24, 2004
Posts: 6028
Location: Tampere, Finland
|
|
|
|
|
|
|
Posted: May 27, 2012 - 07:13 AM |
|


Joined: Dec 22, 2005
Posts: 1281
Location: shiraz , iran
|
|
|
Quote:
Is AVCC connected
yes |
_________________ I love Digital
and you who involved in it!
|
| |
|
|
|
|
|
Posted: May 29, 2012 - 06:29 AM |
|


Joined: Dec 22, 2005
Posts: 1281
Location: shiraz , iran
|
|
| Has anyone ever used the atmel touch library? |
_________________ I love Digital
and you who involved in it!
|
| |
|
|
|
|
|
Posted: May 29, 2012 - 08:21 AM |
|


Joined: Mar 28, 2001
Posts: 20630
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
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
|
| |
|
|
|
|
|
Posted: May 30, 2012 - 02:14 AM |
|

Joined: Jan 26, 2009
Posts: 535
Location: Thessaloniki Greece
|
|
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. |
|
|
| |
|
|
|
|
|