/** \brief Configures touch library and measurement setup * * @pre Interrupts must be enabled in order to trigger regular measurements * The touch configuration requires a fixed CPU speed to work properly in this * case we need 2 MHz. */ void touch_init(void) { #ifdef QTOUCH_STUDIO_MASKS SNS_array[0][0] = 0x40; SNS_array[0][1] = 0x0; SNS_array[1][0] = 0x0; SNS_array[1][1] = 0x0; SNSK_array[0][0] = 0x80; SNSK_array[0][1] = 0x0; SNSK_array[1][0] = 0x0; SNSK_array[1][1] = 0x0; #endif config_sensor(); qt_init_sensing(); qt_set_parameters(); init_timer_isr(); /* Set up callback function. 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_ QDebug_Init(); #endif }
/*============================================================================ Name : main ------------------------------------------------------------------------------ Purpose : main code entry point Input : Output : Notes : ============================================================================*/ int main( void ) { /*status flags to indicate the re-burst for library*/ uint16_t status_flag = 0u; uint16_t burst_flag = 0u; #ifdef QTOUCH_STUDIO_MASKS SNS_array[0]=0x01; SNS_array[1]=0x00; SNSK_array[0]=0x02; SNSK_array[1]=0x00; #endif /* initialise host app, pins, watchdog, etc */ init_system(); /* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */ config_sensors(); /* initialise 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 */ init_timer_isr(); /* 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; /* enable interrupts */ __enable_interrupt(); /* loop forever */ for( ; ; ) { 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; /*Time critical host application code goes here*/ }while ( burst_flag) ; } /* Time Non-critical host application code goes here */ } }
void app_touch_init(void) { #ifdef QTOUCH_STUDIO_MASKS SNS_array[0][0] = 0x50; SNS_array[0][1] = 0x00; SNS_array[1][0] = 0x00; SNS_array[1][1] = 0x00; SNSK_array[0][0] = 0xA0; SNSK_array[0][1] = 0x00; SNSK_array[1][0] = 0x00; SNSK_array[1][1] = 0x00; #endif /* Configures the sensors as keys and assigns the channel numbers. * The sensor is wired up with SNS=PF6 and SNSK=PF7 * When using "pin reconfigurability" this will result in channel 0 * because it is the first and only channel that is used. * For the standard qtouch library setup we would need to use * channel 3 since we are using the last two pins on the port. */ qt_enable_key(CHANNEL_0, NO_AKS_GROUP, 10u, HYST_6_25); qt_enable_key(CHANNEL_1, NO_AKS_GROUP, 10u, HYST_6_25); qt_init_sensing(); /* This will fill the default threshold values in the configuration * data structure. But User 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; /* Initialize the timer counter */ tc_enable(&TCC0); tc_write_period(&TCC0, TIMER_PERIOD); tc_write_clock_source(&TCC0, TC_CLKSEL_DIV8_gc); tc_set_cca_interrupt_level(&TCC0, PMIC_LVL_LOW); tc_set_cca_interrupt_callback(&TCC0, app_touch_tc_interrupt_callback); /* * Set up callback function. 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 = NULL; #ifdef _DEBUG_INTERFACE_ QDebug_Init(); #endif sleepmgr_lock_mode(SLEEPMGR_IDLE); }
//! \brief Initialize QTouch Configuration and sensors static void qtouch_init(void){ /** Configures sensors for rotor, slider or for button * based on the options given in the SYMBOLS */ config_sensors(); // initialize touch sensing qt_init_sensing(); // Set the parameters like recalibration threshold, Max_On_Duration etc qt_set_parameters( ); }
void touch_init( void ) { /* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */ config_sensors(); /* initialise touch sensing */ qt_init_sensing(); /* Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */ 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) */ #ifdef _DEBUG_INTERFACE_ #ifdef _QDEBUG_TIME_STAMPS_ qt_filter_callback = &set_timestamp1; #else qt_filter_callback = 0; #endif #else qt_filter_callback = 0; #endif #ifdef _DEBUG_INTERFACE_ /* Initialize debug protocol */ QDebug_Init(); #endif /* enable interrupts */ __enable_interrupt(); #ifdef _DEBUG_INTERFACE_ /* Process commands from PC */ QDebug_ProcessCommands(); #endif }
/**************************************************************************//** * \brief Initialize QTouch. ******************************************************************************/ void BSP_InitQTouch(BSP_TouchEventHandler_t handler) { /* initialise host app, pins, watchdog, etc */ init_system(); /* Reset touch sensing */ qt_reset_sensing(); /*Configure Burst Length*/ burst_len_config(); config_sensors(); /* Initialise and set touch params */ qt_init_sensing(); qt_set_parameters(); init_timer_isr(); buzzer_init(); /* 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) */ /* This function is also used to send signal values to simulate Accelero * meter, * Just for demo purpose */ qt_filter_callback = qt_avr477_filter_cb; cpu_irq_enable(); handler = handler; }
/** \brief Function to setup touch button. * * This function will configure touch sensing for the QTB0 touch button. * LED1 is used as touch indication. Touch detected: LED1 on, touch not * detected: LED1 off. */ void touch_init(void) { // Configure touch button (QTB0) pin mapping SNS_array[0][0] = 0x40; SNS_array[0][1] = 0x00; SNS_array[1][0] = 0x00; SNS_array[1][1] = 0x00; SNSK_array[0][0] = 0x80; SNSK_array[0][1] = 0x00; SNSK_array[1][0] = 0x00; SNSK_array[1][1] = 0x00; timer1_init(); // PORTB3 (LED1) output default high (LED1 off) DDRB |= (1 << DDB3); PORTB |= (1 << PORTB3); // Configure the Sensor qt_enable_key(CHANNEL_0, NO_AKS_GROUP, 30, HYST_6_25); // 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( ); /* 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; }
int main( void ) { /*status flags to indicate the re-burst for library*/ uint16_t status_flag = 0u; uint16_t burst_flag = 0u; /* initialise host app, pins, watchdog, etc */ init_system(); /* Configure the Sensors as keys or Keys With Rotor/Sliders in this function */ config_sensors(); /* initialise 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 */ 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 /* 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_ QDebug_Init(); #endif /* enable interrupts */ __enable_interrupt(); #ifdef _DEBUG_INTERFACE_ /* Process commands from PC */ QDebug_ProcessCommands(); #endif /* loop forever */ for( ; ; ) { if( time_to_measure_touch ) { /* clear flag: it's 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 /* one time measure touch sensors */ 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 /* Time Non-critical host application code goes here */ } }
/** * \brief getting-started Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { /*Status flags to indicate the re-burst for library */ uint16_t status_flag = 0u; uint16_t burst_flag = 0u; /* Initialize the SAM system */ init_system(); /* Reset touch sensing */ qt_reset_sensing(); /* 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 */ init_timer_isr(); /* 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; /* Loop forever */ for (;;) { 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; /*Time critical host application code goes here */ } while (burst_flag); } /* Get slider value and update the blink frequency */ if (GET_ROTOR_SLIDER_POSITION(0) != qt_shift_data) { qt_shift_data = GET_ROTOR_SLIDER_POSITION(0); #ifdef QT_DATA_REVERT configure_tc((QT_MAX_DATA - qt_shift_data)/LED_FREQ_DIV); #else configure_tc(qt_shift_data/LED_FREQ_DIV); #endif } } }
int main(void) { /*Status flags to indicate the re-burst for library */ uint16_t status_flag = 0u; uint16_t burst_flag = 0u; uint8_t lft_pressed = 0; uint8_t rgt_pressed = 0; static uint8_t old_position = 0; uint8_t uc_char; uint8_t uc_flag; sysclk_init(); board_init(); configure_buttons(); configure_hall(); wdt_disable(WDT); pmc_enable_periph_clk(ID_PIOC); qt_reset_sensing(); config_sensors(); qt_init_sensing(); /* Set the parameters like recalibration threshold, Max_On_Duration etc in this function by the user */ qt_set_parameters(); init_timer_isr(); qt_filter_callback = 0; configure_console(); printf(STRING_HEADER); configure_lcd(); g_pwm_channel = configure_pwm(); /* Cabeçalho do lcd */ pos_lcd_x = 20; pos_lcd_y = 40; start_lcd(pos_lcd_x, pos_lcd_y, ul_duty, hall_1, hall_2, hall_3, phase); /* Infinite loop */ while (1) { static uint8_t phase_aux; static uint32_t hall_1_aux, hall_2_aux, hall_3_aux, ul_duty_aux; /* Atualiza o display somente quando houver alteração nas variáveis que serão apresentadas */ if(ul_duty_aux != ul_duty) { escreve_int_lcd("dc = ", ul_duty*100/PERIOD_VALUE, pos_lcd_x, 40); ul_duty_aux = ul_duty; } if(phase_aux != phase || hall_1_aux != hall_1 || hall_2_aux != hall_2 || hall_3_aux != hall_3) { escreve_int_lcd("hall1 = ", hall_1, pos_lcd_x, 60); escreve_int_lcd("hall2 = ", hall_2, pos_lcd_x, 80); escreve_int_lcd("hall3 = ", hall_3, pos_lcd_x, 100); escreve_int_lcd("phase = ", phase, pos_lcd_x, 120); phase_aux = phase; hall_1_aux = hall_1; hall_2_aux = hall_2; hall_3_aux = hall_3; } if(motor_run == 0 && ul_duty != 0) Hall_Phase(); uc_char = 0; uc_flag = uart_read(CONSOLE_UART, &uc_char); if (!uc_flag) { if (uc_char == 't') { printf(" duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE); printf(" hall1 = %lu \r\n", hall_1); printf(" hall2 = %lu \r\n", hall_2); printf(" hall3 = %lu \r\n", hall_3); printf(" phase = %u \r\n\n", phase); } if (uc_char == 'a'){ if(ul_duty < PERIOD_VALUE) ul_duty++; printf(" duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE); } if (uc_char == 's'){ if(ul_duty > INIT_DUTY_VALUE) ul_duty--; printf(" duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE); } if (uc_char == 'd') { ensaio = 1; printf(" Ensaio de rampa\r\n"); printf(" para parar pressione a letra 'P'\r\n"); } if (uc_char == 'f') { ensaio = 2; printf(" Ensaio de degrau\r\n"); printf(" para parar pressione a letra 'P'\r\n"); } if (uc_char == 'p') { ensaio = 0; ul_duty = 0; } if (uc_char == 'i') { sel_rot = !sel_rot; printf(" Rotacao invertida\r\n"); printf(" para parar pressione a letra 'P'\r\n"); } } 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; /*Time critical host application code goes here */ } while (burst_flag); } /* Time Non-critical host application code goes here */ if ((GET_SENSOR_STATE(BOARD_LEFT_KEY_ID) != 0) && (lft_pressed == 0)) { lft_pressed = 1; if(ul_duty > INIT_DUTY_VALUE) ul_duty--; printf(" duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE); } else { if ((GET_SENSOR_STATE(BOARD_LEFT_KEY_ID) == 0) && (lft_pressed == 1)) { lft_pressed = 0; } } if ((GET_SENSOR_STATE(BOARD_RIGHT_KEY_ID) != 0) && (rgt_pressed == 0)) { rgt_pressed = 1; if(ul_duty < PERIOD_VALUE) ul_duty++; printf(" duty cicle = %lu \r\n",ul_duty*100/PERIOD_VALUE); } else { if ((GET_SENSOR_STATE(BOARD_RIGHT_KEY_ID) == 0) && (rgt_pressed == 1)) { rgt_pressed = 0; } } if (GET_ROTOR_SLIDER_POSITION(0) != old_position) { old_position = GET_ROTOR_SLIDER_POSITION(0); if (motor_run==0) flag_hab_m = 1; ul_duty = old_position*PERIOD_VALUE/255; } } }
/** * \brief Initializes the touch measurement timer. * * We need a timer that triggers approx. every millisecond. * The touch library seems to need this as time-base. */ static void init_timer(void) { volatile avr32_tc_t *tc = TOUCH_MEASUREMENT_TC; const tc_waveform_opt_t waveform_options = { .channel = TOUCH_MEASUREMENT_TC_CHANNEL, //! Software trigger effect on TIOB. .bswtrg = TC_EVT_EFFECT_NOOP, //! External event effect on TIOB. .beevt = TC_EVT_EFFECT_NOOP, //! RC compare effect on TIOB. .bcpc = TC_EVT_EFFECT_NOOP, //! RB compare effect on TIOB. .bcpb = TC_EVT_EFFECT_NOOP, //! Software trigger effect on TIOA. .aswtrg = TC_EVT_EFFECT_NOOP, //! External event effect on TIOA. .aeevt = TC_EVT_EFFECT_NOOP, //! RC compare effect on TIOA: toggle. .acpc = TC_EVT_EFFECT_NOOP, //! RA compare effect on TIOA: toggle. .acpa = TC_EVT_EFFECT_NOOP, //! Waveform selection .wavsel = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, //! External event trigger enable. .enetrg = 0, //! External event selection. .eevt = 0, //! External event edge selection. .eevtedg = TC_SEL_NO_EDGE, //! Counter disable when RC compare. .cpcdis = 0, //! Counter clock stopped with RC compare. .cpcstop = 0, //! Burst signal selection. .burst = 0, //! Clock inversion selection. .clki = 0, //! Internal source clock 3 (fPBA / 8). .tcclks = TC_CLOCK_SOURCE_TC3 }; const tc_interrupt_t tc_interrupt = { .etrgs = 0, .ldrbs = 0, .ldras = 0, .cpcs = 1, .cpbs = 0, .cpas = 0, .lovrs = 0, .covfs = 0, }; #if (defined __GNUC__) Disable_global_interrupt(); INTC_register_interrupt(&tc_irq, TOUCH_MEASUREMENT_TC_IRQ, AVR32_INTC_INT0); Enable_global_interrupt(); #endif /* initialize the timer/counter. */ sysclk_enable_peripheral_clock(&AVR32_TC1); tc_init_waveform(tc, &waveform_options); /* set the compare triggers. */ tc_write_rc(tc, TOUCH_MEASUREMENT_TC_CHANNEL, (sysclk_get_pba_hz() / 8) / 1000); tc_configure_interrupts(tc, TOUCH_MEASUREMENT_TC_CHANNEL, &tc_interrupt); tc_start(tc, TOUCH_MEASUREMENT_TC_CHANNEL); } /** * \brief Initializes the touch library configuration. * * Sets the correct configuration for the QTouch library. */ 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; /* * 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 = NULL; } /** * \brief Initialize touch sensors * * The touch channels are connected on the GPIO controller 4 which is a part of * port X * * Touch Button: * GPIO * 98 SNSK1 CHANNEL1_SNS * 99 SNS1 CHANNEL1_SNSK * * Touch Slider: * 100 SNS0 CHANNEL2_SNS * 101 SNSK0 CHANNEL2_SNSK * 102 SNS1 CHANNEL3_SNS * 103 SNSK1 CHANNEL3_SNSK * 104 SNS2 CHANNEL4_SNS * 105 SNSK2 CHANNEL4_SNSK */ void touch_init(void) { /* * Reset sensing is only needed when doing re-initialization during * run-time */ // qt_reset_sensing(); qt_enable_key(CHANNEL_1, NO_AKS_GROUP, 30u, HYST_12_5); /* * Position hysteresis is not used in QTouch slider so this value will * be ignored */ qt_enable_slider(CHANNEL_2, CHANNEL_4, NO_AKS_GROUP, 20u, HYST_12_5, RES_8_BIT, 0); qt_init_sensing(); qt_set_parameters(); #ifdef _DEBUG_INTERFACE_ sysclk_enable_peripheral_clock(&AVR32_SPI0); /* Initialize debug protocol */ QDebug_Init(); /* Process commands from PC */ QDebug_ProcessCommands(); #endif init_timer(); }