LTlib LaurTec Library  4.0.1
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
 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: 02/12/2015
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 #define AD9833_SPI_MODULE_1
70 //#define AD9833_SPI_MODULE_2
71 
72 #ifdef AD9833_SPI_MODULE_1
73  #define AD9833_SPI_open SPI1_open
74  #define AD9833_SPI_baudrate SPI1_baudrate
75  #define AD9833_SPI_mode SPI1_mode
76  #define AD9833_SPI_write_byte SPI1_write_byte
77 #endif
78 
79 #ifdef AD9833_SPI_MODULE_2
80  #define AD9833_SPI_open SPI2_open
81  #define AD9833_SPI_baudrate SPI2_baudrate
82  #define AD9833_SPI_mode SPI2_mode
83  #define AD9833_SPI_write_byte SPI2_write_byte
84 #endif
85 
86 
87 //**************************************************
88 // PIN CONNECTIONS
89 // Use the default pin to SPI connection
90 // SDATA(SDO) --> It depends on the MCU
91 // SCLK(SCK) --> It depends on the MCU
92 // FSYNC(SS) --> free to be chosen
93 //
94 //**************************************************
95 
96 #ifdef _PIC18
97  #define FSYNC LATAbits.LATA5
98  #define FSYNC_DIRECTION TRISAbits.RA5
99 #endif
100 
101 #ifndef _PIC18
102  #define FSYNC PORTAbits.RA5
103  #define FSYNC_DIRECTION TRISAbits.TRISA5
104 #endif
105 
106 
107 //**************************************************
108 // COSTANTS
109 //**************************************************
110 
111 #define AD9833_RESET 0b0000000100000000
112 #define AD9833_REG0 0
113 #define AD9833_REG1 1
114 #define AD9833_DOWN 0
115 #define AD9833_UP 1
116 #define AD9833_SIN 1
117 #define AD9833_TRIANGLE 2
118 #define AD9833_SQUARE 3
119 #define AD9833_FREQUENCY0_OUT 4
120 #define AD9833_FREQUENCY1_OUT 5
121 #define AD9833_PHASE0_OUT 6
122 #define AD9833_PHASE1_OUT 7
123 #define AD9833_SLEEP_MODE 9
124 #define AD9833_POWER_ON 10
125 
126 
127 //****************************************************************************************************
128 // PRIVATE FUNCTIONS (The user should not use it)
129 //****************************************************************************************************
130 
141 void AD9833_write_data (unsigned int data);
142 #define write_data_AD9833 AD9833_write_data
143 
144 
154 unsigned int AD9833_compose_control_word (unsigned char function_type);
155 #define compose_AD9833_control_word AD9833_compose_control_word
156 
157 
158 //****************************************************************************************************
159 // PUBLIC FUNCTIONS
160 //****************************************************************************************************
161 
172 void AD9833_initialize (unsigned char fmclk);
173 #define initialize_AD9833 AD9833_initialize
174 
175 
187 void AD9833_set_frequency (unsigned long freq_value, unsigned char frequency_register);
188 #define set_frequency_AD9833 AD9833_set_frequency
189 
190 
207 void AD9833_tuning_frequency (unsigned char tuning_step, unsigned char direction,unsigned char frequency_register );
208 #define tuning_frequency_AD9833 AD9833_tuning_frequency
209 
210 
222 void AD9833_set_phase (unsigned long phase_value, unsigned char phase_register);
223 #define set_phase_AD9833 AD9833_set_phase
224 
225 
243 void AD9833_set_function (unsigned char function_type);
244 #define set_function_AD9833 AD9833_set_function
245 
246 
247 #endif
248 
249 
250 
251 
252