Detailed Description
Description of the example
This is the example application used to demonstrate the MEGA-1284P Xplained kit. Basically it has two main modes of operation: demo mode or terminal mode.
Example application flowchart
Demo mode
This mode lets the user select in which mode the ATmega1284P should operate: Active, power-save (with the 32kHz crystal connected to the TOSC pins enabled) or power-down. The user can easily measure the power consumption in the different modes by connecting an ampere meter to the two-pins power header. Please refer to the hardware user guide for more details.
The user can also try out capacitive touch sensing by pushing the QTB0 touch button on the board. LED1 will turn on when QTB0 is touched and switch off whenever QTB0 is not touched.
By shorting MISO (pin 7) and GND (pin 9) of the J1 header the ATmega1284P enters light sensor demo mode. The light sensor is then used to adjust the light intensity of the four leds (LED0:3). Normal demo mode will be resumed as soon as this short is removed.
Demo mode flowchart
Terminal mode
This mode uses USART1 of the ATmega1284P to control the application. Start hyperterminal (or the terminal program of choice) and connect to the COM port where the XPLAINED Virtual Com Port is connected. Select baud rate: 57k6, data bits: 8, parity: none, stop bits: 1 and flow control: none.
To start this mode push and hold SW1 while pressing the reset button on the MEGA-1284P Xplained board. Supported commands and a description will then be printed.
Terminal mode flowchart
Define Documentation
| #define ADC_NUM_OVERSAMPLING 16 |
| #define ASCII_BACKSPACE 8 |
| #define CMD_PROMPT "\r\nMEGA-1284P Xplained>" |
| #define EXTENDED_STANDBY 0x0F |
Extended standby SMCR setting.
| #define MAX_CMD_BUFFER_LEN 32 |
| #define NUMBER_OF_PORTS 1 |
Number of ports using touch.
| #define QT_KEY_DETECT |
( |
| ) |
(qt_measure_data.qt_touch_status.sensor_states[0] & 0x01) |
Macro used for touch key detection.
Enumeration Type Documentation
ADC sources enum.
- Enumerator:
| FILTER_OUTPUT |
RC filter on ADC Channel 5, PA5.
|
| LIGHT_SENSOR |
Light Sensor on ADC Channel 6, PA6.
|
| NTC |
NTC sensor on ADC Channel 7, PA7.
|
Function Documentation
TIMER2 overflow ISR used to indicate 32kHz crystal running.
All LEDs (LED0:3) are toggled to indicate that the 32kHz crystal is running.
| ISR |
( |
TIMER1_COMPA_vect |
| ) |
|
TIMER1 compare A ISR used to time touch measurement.
The TIMER1 compare A interrupt is used to time the touch acquisition. The period of the timer is set by qt_measurement_period_msec.
PCINT8,9,10 ISR used for wake-up from sleep only.
TIMER1 overflow ISR used to dim LEDs in light sensor demo mode.
LEDs are turned off at overflow ISR and turned on in compare match B ISR. The compare value is adjusted according to the light sensor readings. Brighter light will result in lower light sensor reading (ADC code) which results in shorter time to compare match B interrupt. This means that LEDs will be on longer than off at bright light and vice versa at dark light.
- Note:
- Wait one cycle to be sure PINB0 value has stabilized.
| ISR |
( |
TIMER1_COMPB_vect |
| ) |
|
TIMER1 compare B ISR used to dim LEDS in light sensor demo mode.
LEDs are turned off at overflow ISR and turned on in compare match B ISR. The compare value is adjusted according to the light sensor readings. Brighter light will result in lower light sensor reading (ADC code) which results in shorter time to compare match B interrupt. This means that LEDs will be on longer than off at bright light and vice versa at dark light.
brief Example code that demonstrates the some of the basic features of the MEGA-1284P Xplained kit.
This example code shows some of the basic features of the MEGA-1284P Xplained kit. This includes sleep modes, reading the light sensor and the ntc sensor.
Please refer to the detailed description for more informaiton.
Variable Documentation
void(* func)(void) [inherited] |
char help[70] [inherited] |
Touch acquisition timer period in msec.