Analyzing Circuits Using the Espotek Labrador: Measuring Servo Control

Where I demonstrate different methods of measuring a servo pulse to ensure it meets requirements.

Introduction#

In the entry on servos I discussed the specific pulse requirements to make a servo move. In a nutshell, a servo needs a positive pulse .5ms to 2.3ms in a 60Hz signal. Or to put it another way, it requires a 60Hz signal with a duty cycle ranging from 3% to ~14%.

Hardware Debug: Command and Configuration Reference for Bloom and gdb

Reference page for Bloom configuration and commonly used avr-gdb commands.

Sources#

Bloom Configuration#

Atmel ICE Debugger Configuration#

environments:
  default:
    debugTool:
      name: "atmel-ice"

    target:
      name: "atmega328p"
      physicalInterface: "debug-wire"
      disableDebugWirePreDisconnect: false
      manageDwenFuseBit: true
      variantName: "atmega328p-pu"

    debugServer:
      name: "avr-gdb-rsp"
      ipAddress: "127.0.0.1"
      port: 1442

insight:
  enabled: true

avr-gdb Configuration#

.gdbinit#

set history save on
set history size 10000
set history filename ~/.gdb_history

file main.elf
target remote :1442
set listsize 0

define cll
make 
load main.elf
mon reset
refresh
list
end

Developing in C for the ATmega328P: Servos

Where I describe how to use the servos() interface in AVR C.

Sources#

Introduction#

Servos are a powerful addition to the embedded programming toolkit as they enable motion. Not high-speed motion as in a electric motor, however, motion which can be easily controlled and typically in an arc or as angles. Servos are much more precise as to how they can move in comparison to electric motors. See Sources above for a few example tutorials as to how to use them.

Developing in C for the ATmega328P: Pointers

Where I describe how to develop use pointers in AVR_C.

Introduction#

Pointers are introduced by “K&R” with the following comment “Pointers have been lumped with the goto statement as a marvelous way to create impossible- to-understand programs.” While pointers are simple in nature, they can become quite complex, quickly. I recommend going through the examples on this page, slowly and methodically as well as making changes and determine if the change had the effects you believed it would. I also recommend having a C Language reference manual open as well, as I won’t got through the usage.

Developing in C for the ATmega328P: struct

Where I demonstrate how to use the C Language data type struct and how to use it to simplify a program.

Introduction#

As programs become more complicated, its desirable to group common elements into a “block”, then debug that block and have the block serve as a single debugged element. For example, a function can serve as a block of code which performs a set of commands commonly used together. Once debugged, the function can be called instead of the individual commands, simplifying debugging and code management.

Developing in C for the ATmega328P: Example Code

Where I list all of the examples found in the examples folder for easy reference.

Introduction#

When using a specific function or while attempting to understand a C programming concept, it is helpful to see a working example. The examples below, (except where noted), have all been tested and work on an Arduino Uno.

Examples#

AVR C Code on Github

analogRead#

Demonstrates analogRead() which reads the 10bit Analog-Digital Converter (ADC).

Developing in C for the ATmega328: Using PROGMEM

Where I discuss how to use PROGMEM (storing values in Flash memory) for storage.

Introduction#

Storing message strings in AVR RAM can become prohibitively expensive, very quickly. With only 2KB of RAM, the Uno needs as much RAM available for dynamic storage, while message strings are best stored in Flash memory. Due to the AVR microcontroller’s different architecture, you can’t simply read the Flash memory as reading RAM. You also can’t simply “embed” strings in Flash, by making them a constant, there are very specific commands to do both of these tasks.

Developing in C for the ATmega328: Marking Time and Measuring Time

Where I discuss marking time and measuring program execution time.

Introduction#

The Arduino has two time routines, millis() and micros(). The former provides the ability to measure time in milliseconds for a long period of time (50 days) and the latter provides the ability to measure in microseconds (kinda) for a far shorter period of time, 70 minutes. The kinda arises from this comment from the arduino reference on micros()On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution of eight microseconds.

Developing in C for the ATmega328P: Function - tone()

Where I describe the function - tone() as well as noTone() and how to play music on the Uno.

Introduction#

Using the function tone() allows us to play musical notes via the Uno and a speaker. Using tone() is more difficult than understanding the command. It requires having a understanding of music, songs and melodies to use tone() to its fullest.

We are also somewhat spoiled in this era of polyphonic speakers, that is speakers which are able to play multiple notes at once. The Uno and a simple cone speaker is only capable of playing a single tone, which limits the melodies and fidelity of the music played.