LTlib LaurTec Library
4.0.3
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
AD9833.h
Go to the documentation of this file.
1
/*******************************************************************************
2
3
Author : Dario Di Turi
4
Version : 1.3
5
Date : 08/12/2012
6
7
Last Update: Mauro Laurenti
8
Last Update: 16/03/2016
9
10
********************************************************
11
SOFTWARE LICENSE AGREEMENT
12
********************************************************
13
14
The usage of the supplied software imply the acceptance of the following license.
15
16
The software supplied herewith by Dario Di Turi (the Author) is intended for
17
use solely and exclusively on Microchip PIC Microcontroller (registered mark).
18
The software is owned by the Author, and is protected under applicable
19
copyright laws. All rights are reserved.
20
Any use in violation of the foregoing restrictions may subject the
21
user to criminal sanctions under applicable laws, as well as to civil liability
22
for the breach of the terms and conditions of this license.
23
Commercial use is forbidden without a written acknowledgement with the Author.
24
Personal or educational use is allowed if the application containing the
25
following software doesn't aim to commercial use or monetary earning of any kind.
26
27
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
28
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
29
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
31
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33
34
35
********************************************************
36
PURPOSES
37
********************************************************
38
39
This library contains all functions needed to control the DDS waveform generator
40
AD9833. Information on the AD9833 can be found on the website
41
Analog Devices www.analog.com
42
43
More details and pictures can be downloaded from www.LaurTec.com
44
45
*******************************************************************************/
46
47
48
#ifndef LTLIB_AD9833_H
49
#define LTLIB_AD9833_H
50
51
#ifdef __XC8
52
#include <xc.h>
53
#endif
54
55
56
//*****************************************
57
// Library Test
58
//*****************************************
59
#include "
LTlib.h
"
60
61
#ifndef LTLIB_SPI_MODULE_H
62
#error The AD9833 Library requires the "module_SPI" library to be included.
63
#endif
64
65
66
//*****************************************
67
// SPI Module Switch
68
//*****************************************
69
#if defined (AD9833_SPI_MODULE_1) || defined (AD9833_SPI_MODULE_2)
70
71
#else
72
#define AD9833_SPI_MODULE_1
73
#endif
74
75
#ifdef AD9833_SPI_MODULE_1
76
#define AD9833_SPI_open SPI1_open
77
#define AD9833_SPI_baudrate SPI1_baudrate
78
#define AD9833_SPI_mode SPI1_mode
79
#define AD9833_SPI_write_byte SPI1_write_byte
80
#endif
81
82
#ifdef AD9833_SPI_MODULE_2
83
#define AD9833_SPI_open SPI2_open
84
#define AD9833_SPI_baudrate SPI2_baudrate
85
#define AD9833_SPI_mode SPI2_mode
86
#define AD9833_SPI_write_byte SPI2_write_byte
87
#endif
88
89
90
//**************************************************
91
// PIN CONNECTIONS
92
// Use the default pin to SPI connection
93
// SDATA(SDO) --> It depends on the MCU
94
// SCLK(SCK) --> It depends on the MCU
95
// FSYNC(SS) --> free to be chosen
96
//
97
//**************************************************
98
99
#ifdef _PIC18
100
#define FSYNC LATAbits.LATA5
101
#define FSYNC_DIRECTION TRISAbits.RA5
102
#endif
103
104
#ifndef _PIC18
105
#define FSYNC PORTAbits.RA5
106
#define FSYNC_DIRECTION TRISAbits.TRISA5
107
#endif
108
109
110
//**************************************************
111
// COSTANTS
112
//**************************************************
113
114
#define AD9833_RESET 0b0000000100000000
115
#define AD9833_REG0 0
116
#define AD9833_REG1 1
117
#define AD9833_DOWN 0
118
#define AD9833_UP 1
119
#define AD9833_SIN 1
120
#define AD9833_TRIANGLE 2
121
#define AD9833_SQUARE 3
122
#define AD9833_FREQUENCY0_OUT 4
123
#define AD9833_FREQUENCY1_OUT 5
124
#define AD9833_PHASE0_OUT 6
125
#define AD9833_PHASE1_OUT 7
126
#define AD9833_SLEEP_MODE 9
127
#define AD9833_POWER_ON 10
128
129
130
//****************************************************************************************************
131
// PRIVATE FUNCTIONS (The user should not use it)
132
//****************************************************************************************************
133
144
void
AD9833_write_data
(
unsigned
int
data);
145
#define write_data_AD9833 AD9833_write_data
146
147
157
unsigned
int
AD9833_compose_control_word
(
unsigned
char
function_type);
158
#define compose_AD9833_control_word AD9833_compose_control_word
159
160
161
//****************************************************************************************************
162
// PUBLIC FUNCTIONS
163
//****************************************************************************************************
164
175
void
AD9833_initialize
(
unsigned
char
fmclk);
176
#define initialize_AD9833 AD9833_initialize
177
178
190
void
AD9833_set_frequency
(
unsigned
long
freq_value,
unsigned
char
frequency_register);
191
#define set_frequency_AD9833 AD9833_set_frequency
192
193
210
void
AD9833_tuning_frequency
(
unsigned
char
tuning_step,
unsigned
char
direction,
unsigned
char
frequency_register );
211
#define tuning_frequency_AD9833 AD9833_tuning_frequency
212
213
225
void
AD9833_set_phase
(
unsigned
long
phase_value,
unsigned
char
phase_register);
226
#define set_phase_AD9833 AD9833_set_phase
227
228
246
void
AD9833_set_function
(
unsigned
char
function_type);
247
#define set_function_AD9833 AD9833_set_function
248
249
250
#endif
251
252
253
254
255
LTlib_v_4.0.3
inc
AD9833.h
Generated on Wed Aug 3 2016 19:57:31 for LTlib LaurTec Library by
1.8.3.1