MEGA-1284P Xplained Example Application
Defines | Enumerations | Functions | Variables

MEGA-1284P Xplained example application

Defines

#define ADC_NUM_OVERSAMPLING   16
#define ASCII_BACKSPACE   8
#define ASCII_CR   13
#define ASCII_SPACE   32
#define MAX_CMD_BUFFER_LEN   32
#define CMD_PROMPT   "\r\nMEGA-1284P Xplained>"
#define FLASHCOUNT   100
#define IDLE   0x01
 Idle SMCR setting.
#define POWER_DOWN   0x05
 Power-Down SMCR setting.
#define POWER_SAVE   0x07
 Power-Save SMCR setting.
#define STANDBY   0x0D
 Standby SMCR setting.
#define EXTENDED_STANDBY   0x0F
 Extended standby SMCR setting.
#define NUM_COMMANDS   12
#define QT_KEY_DETECT()   (qt_measure_data.qt_touch_status.sensor_states[0] & 0x01)
 Macro used for touch key detection.
#define NUMBER_OF_PORTS   1
 Number of ports using touch.

Enumerations

enum  adc_sources { FILTER_OUTPUT = 0x05, LIGHT_SENSOR = 0x06, NTC = 0x07 }
 

ADC sources enum.

More...

Functions

 ISR (PCINT1_vect)
 PCINT8,9,10 ISR used for wake-up from sleep only.
 ISR (TIMER1_OVF_vect)
 TIMER1 overflow ISR used to dim LEDs in light sensor demo mode.
 ISR (TIMER1_COMPB_vect)
 TIMER1 compare B ISR used to dim LEDS in light sensor demo mode.
 ISR (TIMER1_COMPA_vect)
 TIMER1 compare A ISR used to time touch measurement.
 ISR (TIMER2_OVF_vect)
 TIMER2 overflow ISR used to indicate 32kHz crystal running.
int main (void)

Variables

struct {
   char   cmd [20]
   char   help [70]
   void(*   func )(void)
commands [NUM_COMMANDS]
uint16_t qt_measurement_period_msec = 25
 Touch acquisition timer period in msec.

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

application_flowchart.JPG

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

demo_mode_flowchart.JPG

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

terminal_mode_flowchart.JPG

Define Documentation

#define ADC_NUM_OVERSAMPLING   16
#define ASCII_BACKSPACE   8
#define ASCII_CR   13
#define ASCII_SPACE   32
#define CMD_PROMPT   "\r\nMEGA-1284P Xplained>"
#define EXTENDED_STANDBY   0x0F

Extended standby SMCR setting.

#define FLASHCOUNT   100
#define IDLE   0x01

Idle SMCR setting.

#define MAX_CMD_BUFFER_LEN   32
#define NUM_COMMANDS   12
#define NUMBER_OF_PORTS   1

Number of ports using touch.

#define POWER_DOWN   0x05

Power-Down SMCR setting.

#define POWER_SAVE   0x07

Power-Save SMCR setting.

#define QT_KEY_DETECT ( )    (qt_measure_data.qt_touch_status.sensor_states[0] & 0x01)

Macro used for touch key detection.

#define STANDBY   0x0D

Standby SMCR setting.


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

ISR ( TIMER2_OVF_vect  )

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.

ISR ( PCINT1_vect  )

PCINT8,9,10 ISR used for wake-up from sleep only.

ISR ( TIMER1_OVF_vect  )

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.

int main ( void  )

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

char cmd[20] [inherited]
struct { ... } commands[NUM_COMMANDS]
void(* func)(void) [inherited]
char help[70] [inherited]

Touch acquisition timer period in msec.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines