Getting started with Atmel SAM4S-EK2

Q-touch

We have to use Watch Dog timer. It is first disabled and later initialised.

wdt_disable(WDT);

The pheripheral clock for q-touch keys and slider has to be enabled.

pmc_enable_periph_clk(ID_PIOA);
pmc_enable_periph_clk(ID_PIOC);
qt_reset_sensing();

This function disables all enabled sensors, and returns all library variables (e.g., qt_di) to their default values. This may be useful if it is desired to dynamically reconfigure sensing. After calling this function, any required sensors must be re-enabled, and qt_init_sensing() must be called before qt_measure_channels() is called again.

config_sensors()

This enables all the sensor by

qt_enable_slider(BOARD_SLIDER_START_CHANNEL, BOARD_SLIDER_END_CHANNEL,
            AKS_GROUP_1, 16u, HYST_6_25, RES_8_BIT, 0u);
qt_enable_key(BOARD_VALID_KEY_CHANNEL, AKS_GROUP_1, 18u, HYST_6_25);
qt_enable_key(BOARD_UP_KEY_CHANNEL, AKS_GROUP_1, 18u, HYST_6_25);
qt_enable_key(BOARD_DOWN_KEY_CHANNEL, AKS_GROUP_1, 18u, HYST_6_25);
qt_enable_key(BOARD_LEFT_KEY_CHANNEL, AKS_GROUP_1, 18u, HYST_6_25);
qt_enable_key(BOARD_RIGHT_KEY_CHANNEL, AKS_GROUP_1, 18u, HYST_6_25);

Now we have to fill the default threshold values in the configuration data structure. You can change the values of these parameters.

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;

Now to configure timer ISR to fire it regularly

SysTick_Config((sysclk_get_cpu_hz() / 1000) *
                    qt_measurement_period_msec)
trace_library_info();