Customizing the Microcontroller

When generating code many parameters are automatically configured or based on default values. These can be modified by specifying them to the microcontroller.

General Parameters

"Microcontroller"microcontroller to generate code for
"OperatingVoltage"operating voltage of the microcontroller
"ClockFrequency"frequency of the microcontroller's system clock
"I2CAddress"I2C address when operating as a I2C slave device
"SlaveSelect"slave select pin when operating as a SPI slave device

General parameters.

Load the package.
Specify the microcontroller explicitly.
Specify the operating voltage.
Specify the system clock frequency.

Timer Parameter

At each sampling instant the microcontroller reads the input signals, updates the states, computes the outputs, and sends the outputs out. When the sampling period is reached, the timer is reset and the process is repeated all over again. During each sampling period the microcontroller is busy for some time and idle for the remaining time, except if it has to deal with any interrupts that are triggered.

The sampling period can be a critical factor in determining the performance of the system. Choosing the sampling period is usually a tradeoff between performance and power consumption.

The information to set up the microcontoller to sample at each sampling instant can be found in its datasheet. By default, a timer and its parameters are automatically chosen. They can also explicitly set.

Specify the timer and its parameters.
The error is the difference between the desired and actual sampling period.
Automatically determine the timer.
The parameters when the timer was automatically configured.

The following special values for timer can be specified.

"delay"uses the delay function from the Arduino library
"delayMicroseconds"uses the delayMicroseconds function from the Arduino library
"millis"uses the millis function from the Arduino library
"micros"uses the micros function from the Arduino library
Nonecontinuous operation

Special timer settings.

The settings "delay", "delayMicroseconds", "millis" or "micros" uses functions from the Arduino libraries. The microcontroller first completes all its tasks, delays for τ seconds, and then starts all over again.

Use the "delay" function from the Arduino library.
The timer parameters are all set as Automatic.
The Arduino libraries to use can be specified if needed.

The setting None can be used for continuous operation. The new set of inputs are read immediately after the outputs are sent out. This can be used when the sampling period can be safely neglected. The timer is not set up in this case.

Continuously adjust the LED's brightness based on the potentiometer setting at A0.
The error in sampling is the sampling period.

Shared Parameters

"ADC"A/D conversion specifications
"Serial"serial communication specifications
"SerialOverUSB"serial over USB specifications
"IncludeFiles"files to include
"Definitions"definition of macros
"Declarations"function declarations
"Utilities"utility functions and variables
"Initializations"program initialization
"Loop"execute at each sampling instant
"PreLoop"execute before "Loop"
"PostLoop"execute after "Loop"
"UntimedLoop"execute repeatedly whenever the processor is free

Shared parameters.

In some cases several pins, input, or output channels share a common functionality. For example, the analog to digital conversion is multiplexed among several input pins, or the same serial communication pins are used by several inputs and outputs. The setting in the microcontroller suboptions such as "ADC" and "Serial" will apply to all these channels.

ADC Example

Consider a system that has analog inputs and one output.

A system whose output is the average of 3 inputs.

All the 3 inputs use AVCC as the reference value.

Embed code that uses AVCC as reference.

This common reference can be specified as a microcontroller suboption.

Embed code that uses the same reference and outputs the average analog value.

It may sometimes be possible to customize the functionality for an individual channel by specifying the setting directly for the channel.

The channel "A2" uses the internal reference value.
The remaining channels use the common specification.
This will very likely result in larger code.

SPI Example

Consider a setup where two MAX6675 thermocouples are reading data. They both use the same SPI bus, and the exchange sequences are also the same. However different pins are used to select them as slaves.

The same exchange sequence is used.

The utility to convert the bytes to a temperature value is also the same.

The C code that converts the incoming bytes to temperature in °C.

The input and output specifications are also the same, except for the slave select pins.

The input specifications.
Output specifications.

Since the utilities for by both thermocouples are the same, it can be given as a common utility code snippet that needs to be executed by the microcontroller.

Embed the code that runs a common utility function for both the inputs.

Misc Parameters

Some microcontroller boards such as the Arduino Yun rely on being configured as a Communications Device Class (CDC) device to automatically upload new programs on to the board. This functionality also is useful during the operation of the device in cases such as virtual serial communication. With the "CDC" option you may choose to eliminate this functionality to reduce the program footprint and upload new programs by manually resetting the board.

"Basic", Automaticadd basic CDC functionality
Nonedo not add CDC functionality

"CDC" parameter values.

Since removing the CDC functionality could result in the board going into a locked state, be sure of the consequences before evaluating the following inputs. If unsure, you can safely evaluate them without physically connecting the Arduino Yun.

Remove the CDC functionality.
Quickly press the reset button twice and upload again.
With the CDC functionality the code footprint is larger.
The larger footprint comes primarily from the additional files.
Delete the temporary directory and all intermediate files.