AT91 SAM7S PWM
The
goal of this demonstration project is to demonstrate the use of the PWM
channels to implement a voice playback . This example has been build on the AT91SAM7S64-IAR
evaluation kit.
Many
embedded-microcontroller applications require generation of analog signals. An
integrated or stand-alone DAC fills the role. However, the SAM7S device does
not feature on-chip DAC but features some PWM channels. PWM channels can be
used for generating the required analog signals. PWM channels can be used to
create both, DC or AC analog signals. This software example shows how to use a
PWM channel to create a sinusoid, a ramp, DC voltage and to output audio
signal.
A PWM signal is a digital
signal with a fixed frequency but with a various duty cycle. If the duty cycle
of the PWM signal changes in time and that you are filtering this PWM signal,
the output of the filter will be an analog signal.
The PWM DAC
resolution is equivalent to the resolution of the PWM signal you use to create
the DAC.
The PWM
output signal requires a frequency that is equivalent to the update rate of the
DAC, because each change in PWM duty cycle is the equivalent of one DAC sample.
The
required frequency of the PWM timer depends on the required PWM signal
frequency and the desired resolution.
The
required frequency is the PWM Clock
Where PWM Clock FCLOCK is
the required PWM-timer frequency, Sampling frequency is the PWM sampling frequency,
and "n" is the desired DAC resolution
The SAM7S64-IAR
implementation uses a MCK at 48 MHz and uses a 8-bit resolution and a range of
256 values (from 0 to 255). The sampling range is also fixed at 8 KHz. For an
audio signal (from 0 to 4 KHz), the clock divider is therefore 23,43. The PWM
divider supports only an integer value and can be set to 23, then generates an
error of 1,74% only.
If the sampling frequency
is fixed at 8 KHz the hardware needs a good integrator to reject the basic
integrator filter frequency, to reduce the hardware implementation this
application example uses the over sampling method.
The choice of over sampling
rate can set at the maximum output PWM frequency.
For the 8-bit resolution
and the SAM7S is running at 48 MHz with an error which is lower than 2,5%, the
SAM7S PWM can be over sampled at 64 KHz.
Power on the board through the USB cable.
The different Push Buttons have been configured as described below:
PA19: Push Button 1, Open the PWM channel and Output a constant middle range.
PA20: Push Button 2, Open the PWM channel and Output a 800 Hz Sinusoidal.
PA15: Push Button 3, Open the PWM channel and Output an Audio file.
PA14: Push Button 4, Close the PWM channel
You can use a hyperterminal application on your PC through the DBGU to have access to a specific menu:
- Connect the DBGU board port with a RS232 null modem cable (female / female)
- Open a hyperterminal application on your host computer and configure it with: 115200, 8 bits, without Parity and one stop bit.
The following menu should appears:
ATMEL PWM
0)Info
1)MIPS
2)Open PWM
3)Close PWM
4)Const
5)Ramp
6)Sinus
7)Wave
The following commands are then available:
0) Display the PWM registers to check the PWM Controller configuration
1) Measure
the number of MIPS available (Thumb instructions running in flash).
2) Open
the PWM channel
3) Close
the PWM channel
4) Set
the value to output a constant (requires a DC value)
5) Set
the value to output a ramp (requires the ramp frequency).
6) Set
the value to output a Sinus (requires the Sinusoidal frequency)
7) Set
the value to output an audio file loaded in on-chip Flash at 0x104000. This
file must be an Audio file coded in 8-bit at 8 KHz.
In this project example, we are assuming to have the master clock MCK at 47.9232 MHz on the AT91SAM7S64-IAR
Hardware requirements:
- DBGU : DBGU Configuration (115200, 8, N, 1)
- Timer : Timer 0 & Timer 1
- PWM :
PWM0 Channel
- PIO : PIOA Controller
- PMC : Power Management Controller (PA11 outputs the
PWM Channnel 0)
- AIC :
Advanced Interrupt Controller
AT91SAM7S-EK Evaluation
Koard
Push Buttons and LEDs: The FIQ,
IRQ0, TIOA0 and TIOB switches are debounced and buffered.
Please note that the jumper CB6 must be open (SW1-4 inputs to the AT91 are
valid). By default, this jumper is not equipped (open)
- SW1 : (AT91C_PA19_FIQ) Used in peripheral mode for
the FIQ input
- SW2 : (AT91C_PA20_IRQ0) Used in peripheral mode for
the IRQ0 interrupt
- SW3 : (AT91C_PIO_PA15) Used in standard PIO mode for
the PIO input
- SW4 : (AT91C_PIO_PA16) Used in standard PIO for the
PIO interrupt
-
LED1
to LED4 : Used in
standard PIO output
Audio file:
An
audio file including the wave standard format
Mono 8 bits at 8 KHz
This file must be loaded at 0x104000
One example it’s available in the
src folder (check file 5400_8_1.*).
Hardware filtering
A basic analog filter it used for integrator
filtering.