18
APPLICATION NOTE Atmel AVR3004: QTouch with Safety Features Atmel QTouch Features Importance of IEC60730 Class B standard Atmel ® QTouch ® application with Class B Test scenarios to validate safety features Introduction For reliable and safe operation of electronic devices used in variety of home appliances and white goods namely, dishwasher, washing machine, refrigerator, freezer, induction cooker, ovens, etc., International Electro-Technical Commission has introduced IEC60730 standard. The Class B software classification of IEC60730 requires software implementation which prevents unsafe operation. The purpose of this document is to describe how to add safety features to an Atmel QTouch Library based Atmel Capacitive Touch Solution. The document provides test scenarios to simulate the failure conditions and validate the safety features. The guidelines provided enable the users to develop a QTouch application for complying with IEC60730 Class B requirements. For full compliance the user can customize the tests as required. 42041AAVR11/2012

Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

APPLICATION NOTE

Atmel AVR3004: QTouch with Safety Features

Atmel QTouch

Features

• Importance of IEC60730 Class B standard

• Atmel® QTouch® application with Class B

• Test scenarios to validate safety features

Introduction

For reliable and safe operation of electronic devices used in variety of home appliances and white goods namely, dishwasher, washing machine, refrigerator, freezer, induction cooker, ovens, etc., International Electro-Technical Commission has introduced IEC60730 standard. The Class B software classification of IEC60730 requires software implementation which prevents unsafe operation.

The purpose of this document is to describe how to add safety features to an Atmel QTouch Library based Atmel Capacitive Touch Solution. The document provides test scenarios to simulate the failure conditions and validate the safety features. The guidelines provided enable the users to develop a QTouch application for complying with IEC60730 Class B requirements. For full compliance the user can customize the tests as required.

42041A−AVR−11/2012

Page 2: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

2

Table of Contents

1.  Overview of Safety Tests ..................................................................... 3 1.1  Class B .............................................................................................................. 3 

1.1.1  CPU and Stack Registers ................................................................... 3 1.1.2  Watchdog Function ............................................................................. 3 1.1.3  CPU Status Register ........................................................................... 3 1.1.4  SRAM ............................................................................................. 3 1.1.5  Timer Function .................................................................................... 4 1.1.6  Interrupt Function ................................................................................ 4 

1.2  FMEA ............................................................................................................... 4 1.2.1  Short to VCC ........................................................................................ 4 1.2.2  Short to GND ...................................................................................... 4 1.2.3  Short to Other Touch Pins .................................................................. 4 1.2.4  Sampling Capacitor (Cs) short ............................................................ 4 1.2.5  Unusual Signal Value.......................................................................... 4 

1.3  Application Flow Chart ...................................................................................... 5 1.4  Overview of API’s Performing Functional Tests ................................................ 6 1.5  Reporting FMEA Error Status ........................................................................... 6 

2.  Test Scenarios ..................................................................................... 8 2.1.1  Pre-Requisites .................................................................................... 8 2.1.2  Test Cases .......................................................................................... 8 

3.  Deliverables ....................................................................................... 12 3.1  Folders and Files ............................................................................................. 12 

4.  Porting Safety Features to a QTouch Project .................................... 13 4.1  Creating a QTouch Project .............................................................................. 13 4.2  Integrating Class B and FMEA ........................................................................ 13 

5.  References ......................................................................................... 16 

6.  Revision History ................................................................................. 17 

Page 3: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

3

1. Overview of Safety Tests According to IEC60730, single channel applications (applications which use only one microcontroller) must have firmware designs which can perform:

• Start-up functional test • Periodic functional test

Single channel functional test is the most popular mechanism used today and the easiest to implement. A set of functionality is tested in the startup and some functionality is tested periodically. Based on the test results, appropriate actions are taken.

The test functions are segregated into two sections namely, Class B and FMEA. The functional tests which test the internal modules of a MCU are covered in Class B tests and functional tests for QTouch which test the connectivity at IO levels are covered in FMEA (Failure Mode Effect Analysis) tests. In general, a reset is issued or CPU is kept idle during error conditions which are internal to the MCU.

1.1 Class B The Class B test covers functional test of various modules/peripherals of a MCU. The tests covered in Class B are common for any application. The following tests are performed to check the MCU functionality.

• CPU and Stack Registers • Watchdog Function • CPU Status Register • SRAM • Timer Function • Interrupt Function

The following sub-sections describe each functional test. The order in which the test is performed is important and the tests must be conducted in the same order as mentioned above. For example, general purpose registers should be checked before checking SRAM. Also, any failure in Class B should result in either halt in the application or a reset.

1.1.1 CPU and Stack Registers General purpose CPU registers R0-R25, X, Y and Z are tested for stuck-on. This test is carried out by successively writing and reading 0x55 and 0xAA value on each registers. Similarly, Stack pointer register is also tested for stuck-on. This code is written in assembly and must be executed before executing main function.

1.1.2 Watchdog Function Watchdog is configured to issue a reset and the same is monitored on reset. With successful watchdog reset, watchdog test is declared as pass.

1.1.3 CPU Status Register CPU stats register, SREG, is checked for stuck-on by writing and reading 0x55 and 0xAA.

1.1.4 SRAM Initially, SRAM is checked for stuck-on by writing and reading 0x55 and 0xAA. Also, the complement of the address corresponding to a SRAM location is written on the location and read back. This ensures the proper functionality of the address encoder. After this, March B test is conducted. During March B test SRAM is divided in to two portions and each portion is tested independently.

Note: March B test is described in the Atmel application note AVR998: Guide to IEC60730 Class B compliance with AVR® microcontroller.

Page 4: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

4

1.1.5 Timer Function Initially timer registers are checked for stuck-on by writing and reading 0x55 and 0xAA.

Later the timers are configured to set interrupt flag when the timer count register value matches the compare registers value. The interrupt flags are checked after specified times. If the interrupt flags are not set, then the test is declared as failed.

1.1.6 Interrupt Function In order to check the interrupt function, one timer is configured to issue over-flow interrupt and the same is monitored. If interrupt didn’t occur, then the test is declared as failed.

1.2 FMEA Though the internal functionality of MCU is working properly, a physical fault in pins may lead to erratic behavior in touch operations. These errors should be indentified and corrective action should be taken. The FMEA tests mentioned in this document are specific to QTouch application and cannot be used in other applications.

The FMEA test covers IO pin level functional test on touch pins (both SNS and SNSK). The following tests are performed on SNS and SNSK pins.

• Short to VCC

• Short to GND

• Short to other touch pins

• Sampling Capacitor (Cs) short

• Unusual Signal Value

The following sub-sections describe each FMEA functional test. There is no specific order in which these tests need to be performed.

1.2.1 Short to VCC The SNS and SNSK pins of all channels are checked whether they are shorted to VCC. If SNS or SNSK of a particular channel is shorted to VCC, then the corresponding channel is reported as faulty.

1.2.2 Short to GND The SNS and SNSK pins of all channels are checked whether they are shorted to GND. If SNS or SNSK of a particular channel is shorted to GND, then the corresponding channel is reported as faulty.

1.2.3 Short to Other Touch Pins In this test, touch pins are checked whether they are shorted to other touch pins from the same port. If two touch pins are shorted then channels corresponding to both the touch pins are reported as faulty.

1.2.4 Sampling Capacitor (Cs) short Sampling Capacitor of all the channels is checked for short. If a sampling Capacitor is shorted then the corresponding channel is reported as faulty. In intra-port configuration, a Cs short will be reported as “Sampling Capacitor short” and “Short to other touch pin” errors.

1.2.5 Unusual Signal Value Each channel’s signal values are checked with a predefined range. If a channel’s signal value is not within the range then channel is reported as faulty.

Page 5: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

5

1.3 Application Flow Chart The following flow chart describes a QTouch application with Class B and FMEA code integrated into it.

Page 6: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

6

1.4 Overview of API’s Performing Functional Tests The functional tests are modularized such that each module performs a unique test. The following table gives the list of important APIs.

API Description

void __low_level_init(void) Performs stuck on test on CPU and Stack registers.

uint8_t watchdog_test(void) Configures watchdog module and perform watchdog functionality test.

uint8_t cpu_status_test(void) Perform stuck on test on Status register.

uint8_t sram_test(void) Perform stuck on and March B test.

uint8_t timer0_test(void)

Perform timer functionality test. uint8_t timer1_test(void)

uint8_t timer2_test(void)

uint8_t interrupt_test(void) Check the interrupt functionality.

uint8_t startup_test(void) Calls various Class B test functions and provide a consolidated error status.

void qt_fmea_init(void) Initialize variables and PORTs used by FMEA test.

fmea_ret_t fmea_util_check_short_to_vcc(void) Check whether SNS/SNSK pins are shorted to VCC.

fmea_ret_t fmea_util_check_short_to_vss(void) Check whether SNS/SNSK pins are shorted to GND.

fmea_ret_t fmea_util_check_short_to_pins(void) Check whether touch pins are shorted to other touch pin in the same port.

fmea_ret_t fmea_util_check_short_cap(void) Check whether any channel’s Sampling Capacitor is shorted.

fmea_ret_t fmea_util_check_unusual_signal(void) Check whether any channels signal value is beyond the specified range.

uint8_t qt_fmea_run_diagnostics(uint8_t select_checks) Perform various FMEA tests based on the input passed to it.

uint8_t qt_fmea_read_error_status(uint8_t channel_num) Returns the error status of a particular channel

void qt_fmea_save_error_status_to_eeprom(void) Stores the FMEA error status in EEPROM.

Uint8_t qt_fmea_read_error_status_from_eeprom(uint8_t channel_num)

Reads the FMEA error status of a particular channel from EEPROM.

void perform_initial_fmea_check(void) Perform initial FMEA checks and take user defined action on error.

void perform_periodic_fmea_check(void) Perform periodic FMEA checks and take user defined action on error.

1.5 Reporting FMEA Error Status The FMEA errors are updated in an array (fmea_channel_status) whose width is one byte and depth is maximum number of QTouch channels plus 1. Each byte corresponds to one channel. The last byte in the array is a “Global FMEA test status” byte. An error in a channel is captured in the corresponding one byte and in the last byte of the array. The user can use “Global FMEA test status” byte to check error conditions and does not need to always scan through the entire array. The errors in the channels are updated as shown in Figure 1-1.

Page 7: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

7

Figure 1-1. Test Results.

Example Errors

• If channel 0 SNS/SNSK pin is shorted to GND, then bit location ‘1’ of 0th byte and last byte will be set to 1

• If channel 3 SNS/SNSK pin is shorted to VCC, then bit location ‘0’ of 3rd byte and last byte will be set to 1

• If channel 2 and channel 3 SNS pins are in same port and are shorted, then bit location ‘2’ of 2nd byte, 3rd byte and last byte will be set to 1

• If SNS and SNSK pins of channel 4 is shorted to each other and they are in same port, then bit locations ‘2’ and ‘3’ of 4th byte will be set to 1

• If channel 5 Sampling Capacitor is shorted then bit location ‘4’ of 5th byte and last byte will be set to 1

• If channel 6 has signal value beyond the specified range, then bit location ‘5’ of 6th byte and last byte will be set to 1

Page 8: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

8

2. Test Scenarios This section describes the possible ways to test the Class B and FMEA test codes. These test scenarios are targeted for Atmel ATtiny88 and Atmel ATmega324A devices.

The Class B test performs functionality checks on various peripherals of a MCU. These tests can be tested by introducing the errors manually and need to be performed by executing the example projects in debug mode.

Unlike Class B, FMEA tests are performed on the IOs of a MCU. So, user can easily simulate the errors and check the functionality of FMEA tests. These test cases are common for all the devices. User can view the result (fmea_channel_status array) through watch window or the array can be transmitted through UART to view them in PC.

2.1.1 Pre-Requisites • Hardware platform to perform test

• Debugging tool (Atmel AVR JTAGICE mkII, JTAGICE 3 or AVR ONE!)

• Knowledge of watch window and debugging in Atmel Studio 6

• Build and flash the example project into the device

2.1.2 Test Cases The following table describes the various test cases and expected result. User need to run the example project in debugging mode to perform tests 1-5. The remaining tests can be performed either in debugging mode or after programming the device. Any extra code included for the current test should be removed before running the next test case.

Sl. no.

Test scenarios Procedure to perform the test Expected result

1 Watchdog Test No Error Condition -Configure a GPIO, say PORTD0, as output. -Make the pin LOW before calling startup_test() in main.c. -Make the pin HIGH after calling startup_test(). -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Start debugging by pressing (Alt+F5). -Place a break point at while(1) statement in watchdog_test(). -Run the application (F5). -Modify the value of WDTCSR to zero through watch window. This ensures that watchdog module is not configured to issue reset.

No Error Condition

Pin D0 should be HIGH. Error Condition Pin D0 should be LOW.

Page 9: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

9

Sl. no.

Test scenarios Procedure to perform the test Expected result

2 CPU Status register Test

No Error Condition -Configure two GPIO, say D0 and D1, as output. -Make both the pins as LOW before calling startup_test(). -Make D0 HIGH after calling startup_test() -Make D1 HIGH before qt_fmea_init() function. -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Start debugging by pressing (Alt+F5). -Place a break point at “a=SREG;” in cpu_status_test() -Modify the value of SREG to zero through watch window. This will result in reading wrong value and this leads to test failure. -Run the application (F5).

No Error Condition Pins D0 and D1 should be HIGH.

Error Condition Pins D0 should be HIGH and D1 should be LOW.

3 SRAM Test No Error Condition Perform “No Error” test similar to “CPU Status Register Test”.

Simulating Error Condition -Start debugging by pressing (Alt+F5). -Place a break point at any of the “for” loop in sram_test() -Run the application (F5) -Modify the value of the RAM location which is currently test to a random value. This will make the SRAM test failure. -Run the application (F5)

No Error Condition Pins D0 and D1 should be HIGH.

Error Condition Pins D0 should be HIGH and D1 should be LOW.

4 Timer 0 Test Timer 1 Test Timer 2 Test “Timer 2 Test” is available only for ATmega324A device.

No Error Condition Perform “No Error” test similar to “CPU Status Register Test”.

Simulating Error Condition -Start debugging by pressing (Alt+F5). -Place a break point at “i=0” statement in timer0_test(). -Run the application (F5) -Modify the value of “TCCRnA/B” to zero through watch window. “TCCR0A” for ATtiny88. “TCCR0B” for ATmega324A. -Run the application (F5) Perform similar test on Timer1 and Timer2.

No Error Condition Pins D0 and D1 should be HIGH.

Error Condition Pins D0 should be HIGH and D1 should be LOW. Error conditions are same for Timer1 and Timer2.

5 Interrupt Test No Error Condition Perform “No Error” test similar to “CPU Status Register Test”.

Simulating Error Condition -Start debugging by pressing (Alt+F5). -Place a break point at “TCNT0 = 254” statement in interrupt_test().-Run the application (F5). -Modify the value of TIMSK0 to zero through watch window. -Run the application (F5).

No Error Condition Pins D0 and D1 should be HIGH.

Error Condition Pins D0 should be HIGH and D1 should be LOW.

Page 10: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

10

Sl. no.

Test scenarios Procedure to perform the test Expected result

6 Short to VCC No Error Condition -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Add the following code after qt_fmea_init(). While(1) fmea_util_check_short_to_vcc(); -Start debugging by pressing (Alt+F5). -Place a break point at fmea_util_check_short_to_vcc(). -Connect either SNS or SNSK of channel ‘N’ to VCC and Run the application (F5). -Similarly, connect other channels SNS or SNSK pin to VCC and Run the application.

No Error Condition All fields of fmea_channel_status array should be 0x00.

Error Condition Bit 0 of fmea_channel_status[N] and last byte of fmea_channel_status array should be set to 1. While checking other channels, respective byte of the array should be checked.

7 Short to GND No Error Condition -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Add the following code after qt_fmea_init(). While(1) fmea_util_check_short_to_vss(); -Start debugging by pressing (Alt+F5). -Place a break point at fmea_util_check_short_to_vss(). -Connect either SNS or SNSK of channel ‘N’ to GND and Run the application (F5). -Similarly, connect other channel’s SNS or SNSK pin to VCC and Run the application.

No Error Condition All fields of fmea_channel_status array should be 0x00.

Error Condition Bit 1 of fmea_channel_status[N] and last byte of fmea_channel_status array should be set to 1. While checking other channels, respective byte of the array should be checked.

8 Short to other touch pins Note: The touch pins shorted across ports are not checked in this test.

No Error Condition -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Add the following code after qt_fmea_init(). While(1) fmea_util_check_short_to_pins(); -Start debugging by pressing (Alt+F5). -Place a break point at fmea_util_check_short_to_pins(). -Connect touch pin of channel ‘N’ and touch pin of channel ‘M’ and Run the application (F5). -Similarly, check other channels.

No Error Condition All fields of fmea_channel_status array should be 0x00.

Error Condition Bit 2 of fmea_channel_status[N], fmea_channel_status[M] and last byte of fmea_channel_status array should be set to 1. While checking other channels, respective byte of the array should be checked.

Page 11: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

11

Sl. no.

Test scenarios Procedure to perform the test Expected result

9 Sampling Capacitor (Cs) short

No Error Condition -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Add the following code after qt_fmea_init(). While(1) fmea_util_check_short_cap(); -Start debugging by pressing (Alt+F5). -Place a break point at fmea_util_check_short_cap(). -Short Sampling Capacitor of channel N and Run the application (F5). -Similarly, check other channels.

No Error Condition All fields of fmea_channel_status array should be 0x00.

Error Condition Bit 3 of fmea_channel_status[N] and last byte of fmea_channel_status array should be set to 1. Note: Bit location 2 will also be set if sensors are configured as intra-port.

10 Unusual signal value

No Error Condition -Set proper value for FMEA_UNUSUAL_SIG_VAL_HIGH and FMEA_UNUSUAL_SIG_VAL_LOW. -Start debugging by pressing (Alt+F5). -Run the application (F5).

Simulating Error Condition -Change Sampling Capacitor of channel ‘N’ so that the signal value can go beyond the specified range. -Start debugging by pressing (Alt+F5). -Place a break point at qt_fmea_perform_periodic_check(). -Run the application (F5).

Note: This test needs to be conducted after calling (at least once) qt_measure_sensors().

No Error Condition All fields of fmea_channel_status array should be 0x00.

Error Condition Bit 4 of fmea_channel_status[N] and last byte of fmea_channel_status array should be set to 1. While checking other channels, respective byte of the array should be checked.

Page 12: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

12

3. Deliverables The example QTouch projects are provided with safety features added into them. The example projects are provided for Atmel ATmega324A and Atmel ATtiny88 devices. User can easily modify the test functions in “Class B.c” file to enable safety feature for other Atmel tinyAVR® or megaAVR® devices. The files, “qfmea.c” and “qfmea.h” are common for any Atmel tinyAVR or megaAVR devices and are provided separately for GCC and IAR™ compiler, though these are functionally identical.

Note: The test code or reference project does not have any corrective codes on test failures. User need to add the corrective codes in the respective places as mentioned in Chapter 4.

Note: The FEMA code stores the FMEA error status array in EEPROM for future access. QDebug protocol also uses EEPROM. So, care should be taken such that only one feature is enabled at a time or they use separate EEPROM memory spaces.

3.1 Folders and Files Figure 3-1 provides the details of the folders.

Figure 3-1. Folders.

The following files are available in “safety code” folder.

File name Description

low_level_init.c Contains implementation for CPU and Stack register tests

ClassB.c Includes tests for internal module/peripherals of MCU (Watchdog, Interrupt, SRAM, CPU Status register, and timer)

ClassB.h Contains the function prototype and macro definitions

qfmea.c Contains implementation of FMEA tests

qfmea.h Contains the function prototype, global declaration and macro definitions of FMEA tests

Page 13: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

13

4. Porting Safety Features to a QTouch Project Though the example projects are provided for Atmel ATmega324A and Atmel ATtiny88 devices, safety codes can be ported to various Atmel tinyAVR or megaAVR devices with little effort. The following sub-sections provide the procedure to port Class B and FMEA code to a QTouch application.

4.1 Creating a QTouch Project • Download and install QTouch Library 5.0 or latest

• Refer Library_Selection_Guide.xls for selecting the appropriate library and example project for the selected device

• Refer the following installed location “..\Atmel\Atmel_QTouch_Libraries_5.0\Generic_QTouch_Libraries\AVR_Tiny_Mega_XMega\QTouch\example_projects“ to access the example projects

• Open the example project in “Atmel Studio 6” or “IAR Embedded Workbench®”

• Configure the parameters in “touch_config.h” as per the requirement. Refer Library User Guide for more details on the parameters

• Build and flash the code

• Ensure that touch operation is proper functional with the help of Atmel QT600 and QTouch Analyzer

4.2 Integrating Class B and FMEA • Copy all the files from "../Safety_Code/" to the project folder

• Add "qfmea.c", "Class B.c", and "low_level_init.c" files to the project

• Do the modifications in “Class B.c” based on the selected device

• In main.c, include the following code after #include "touch_api.h"

• In main.c, include the following code after static void config_sensor(void);

• In main.c, include the following variable declaration code after uint16_t burst_flag = 0u;

Page 14: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

14

• In main.c, include the following code to call and check Class B startup test after uint8_t time_to_check_signal_value = 0;

• Add the following code before calling init_timer_isr()

• Add the following FMEA initialization code after assigning EEPROM address as shown below

• In main.c, run the initial FMEA test by including the following code after qt_fmea_init() function

Page 15: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

15

• In main.c, add the following watchdog reset code after startup_test(), qt_fmea_init(), qt_fmea_run_initial_test(), init_system(), config_sensors(), qt_init_sensing(), qt_set_parameters(), init_timer_isr(), QDebug_Init(), QDebug_ProcessCommands() function calls. Also add after /* Time-critical host application code goes here */

• Add the following code after time_to_measure_touch = 0u;

• Add the following code after /* Time Non-critical host application code goes here */

• Copy the definition of perform_initial_fmea_check() and perform_periodic_fmea_check() functions from the example project and add the same at the end of the main.c file

• Ensure that in main.c file the following proper values are set to the following variables. qt_fmea_config.hi_signal_threshold: signal value less than this, will be declared as fail in function "qt_fmea_run_diagnostics" qt_fmea_config.lo_signal_threshold: signal value greater than this, will be declared as fail in function "qt_fmea_run_diagnostics" qt_fmea_config. eeprom_start_address: Starting address of FMEA error status stored in EEPROM

• Include the corrective code in main.c file in the following places • /* touch pin shorted to Vcc error */

• /* touch pin shorted to Vss error */

• /* touch pin shorted to other touch pins error */

• /* Cs short error */

• /* unusual signal error */

Page 16: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

16

5. References • Atmel AVR998: Guide to IEC60730 Class B compliance with AVR Microcontrollers

• Atmel AVR1610: Guide to IEC60730 Class B compliance with XMEGA®

• QTAN0079: Buttons, Sliders and Wheels Sensor Design Guide

• Atmel QTouch Library User Guide

Page 17: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012

17

6. Revision History Doc. Rev. Date Comments

42041A 11/2012 Initial document release

Page 18: Atmel AVR3004: QTouch with Safety Featuresww1.microchip.com/downloads/en/AppNotes/doc42041.pdfAtmel AVR3004: QTouch with Safety Features [APPLICATION NOTE] 42041A−AVR−11/2012 7

Atmel Corporation 1600 Technology Drive San Jose, CA 95110 USA Tel: (+1)(408) 441-0311 Fax: (+1)(408) 487-2600 www.atmel.com

Atmel Asia Limited Unit 01-5 & 16, 19F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon HONG KONG Tel: (+852) 2245-6100 Fax: (+852) 2722-1369

Atmel Munich GmbHBusiness Campus Parkring 4 D-85748 Garching b. Munich GERMANY Tel: (+49) 89-31970-0 Fax: (+49) 89-3194621

Atmel Japan G.K.16F Shin-Osaki Kangyo Bldg. 1-6-4 Osaki, Shinagawa-ku Tokyo 141-0032 JAPAN Tel: (+81)(3) 6417-0300 Fax: (+81)(3) 6417-0370

© 2012 Atmel Corporation. All rights reserved. / Rev.: 42041A−AVR−11/2012

Atmel®, Atmel logo and combinations thereof, AVR®, Enabling Unlimited Possibilities®, megaAVR®, QTouch®, tinyAVR®, XMEGA®, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.

Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.