AN123 Silicon_Laboratories, AN123 Datasheet - Page 5

no-image

AN123

Manufacturer Part Number
AN123
Description
Using THE DAC AS A Function Generator
Manufacturer
Silicon_Laboratories
Datasheet
Software Example
//-----------------------------------------------------------------------------
// DAC1_fgen1.c
//-----------------------------------------------------------------------------
//
// AUTH: BW,FB
// DATE: 2 OCT 01
//
// Target: C8051F02x
// Tool chain: KEIL C51
//
// Description:
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f020.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
//-----------------------------------------------------------------------------
// 16-bit SFR Definitions for ‘F02x
//-----------------------------------------------------------------------------
Example source code which outputs waveforms on DAC1.
scheduled to update at a rate determined by the constant
<SAMPLE_RATE_DAC>, managed and timed by Timer4.
Implements a 256-entry full-cycle sine table of 16-bit precision. Other
waveforms supported are square, triangle, and saw tooth.
The output frequency is determined by a 16-bit phase adder.
At each DAC update cycle, the phase adder value is added to a running
phase accumulator, <phase_accumulator>, the upper bits of which are used
to access the sine lookup table.
The program is controlled through UART using HyperTerminal running on a
PC. All commands are two characters in length and have optional
frequency and amplitude arguments. Note that the amplitude parameter
cannot be specified unless the frequency is also specified.
Command Format:
Command List:
SQ - Square Wave
SI - Sine Wave
TR - Triangle Wave
SA - Saw Tooth Wave
OF - Output OFF
?? - Help
XX [frequency] [amplitude]
where XX denotes the command
// SFR declarations
Rev. 1.1
DAC1’s output is
AN123
5

Related parts for AN123