Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AD9833 forgets the program

Status
Not open for further replies.

Angelo90

Newbie level 3
Newbie level 3
Joined
Nov 10, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
74
Hello everybody,

I am using AD9833 functional generator and it forgets the program everytime I turn it off and I have to program it again. Is it intentional or can you suggest some possible reasons/ errors in the programming or in the circuit for such a failure?

Thanks!

Angelo
 

It doesn't make much sense if it has to be reprogrammed every time.
 

you can store the last target used for AD9833 in EEprom area , to recover the same value at reset ou restart..
How do use it ...
Are you using a Frequency target value , then calculate the value of register ...
Show your code ..
and Tools for programming MPLAB,MIKROC ???
 

I am using MPLAB.
This is my code:


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
LIST P=18F2550          ;directive to define processor
        #include <P18F2550.INC> ;processor specific variable definitions
 
;******************************************************************************
;Configuration bits
 
 
        COMMAND1 equ B'00001111'
        COMMAND2 equ B'11110111'
 
        COMMAND3 equ B'11000101'
        COMMAND4 equ B'00001011'
 
        COMMAND5 equ B'11010000'
        COMMAND6 equ B'00000000'
 
        COMMAND7 equ B'00100000'
        COMMAND8 equ B'00100000'
 
        COMMAND9 equ B'00111000'
        COMMAND10 equ B'00000000'
 
        COMMAND11 equ B'00010000'
        COMMAND12 equ B'00100111'
 
 
;   Oscillator Selection:
    CONFIG      FOSC = HS            ;HS oscillator
 
 
;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used. 
; More variables may be needed to store other special function registers used
; in the interrupt routines.
 
                CBLOCK  0x060
                WREG_TEMP       ;variable used for context saving 
                STATUS_TEMP     ;variable used for context saving
                BSR_TEMP        ;variable used for context saving
                ENDC
 
                CBLOCK  0x000
                EXAMPLE         ;example of a variable in access RAM
                TMR0CNT            ; Holds TIMER0 overflow interrupt count.
                MYFLAG          ; Variable for holding flags
                SBYTE
                BITN
                ENDC
 
;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.
 
                code    0x0000
 
                goto    Main            ;go to start of main code
 
;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.
 
                org     0x0008
 
                bra     HighInt         ;go to high priority interrupt routine
 
;******************************************************************************
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.
 
                org     0x0018
 
                ;movff  STATUS,STATUS_TEMP      ;save STATUS register
                ;movff  WREG,WREG_TEMP          ;save working register
                ;movff  BSR,BSR_TEMP            ;save BSR register
 
;       *** low priority interrupt code goes here ***
 
 
                ;movff  BSR_TEMP,BSR            ;restore BSR register
                ;movff  WREG_TEMP,WREG          ;restore working register
                ;movff  STATUS_TEMP,STATUS      ;restore STATUS register
                retfie
 
;******************************** TIMER INTERRUPT *********************************
;High priority interrupt routine
; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.
 
                org 0x002A
HighInt:
;       *** high priority interrupt code goes here ***
    btfsc   INTCON, TMR0IF  ; Test TIMER0 Interrupt flag
    goto    intTMR0IF       ;  and goto correct code otherwise
    retfie                  ;  return.
 
intTMR0IF:
    decfsz  TMR0CNT         ; Decrement the overflow counter
    goto    intTMR0IF_Ret   ;  returning if not zero.
 
    movlw   0x1             ; Reset TIMER0 overflow counter
    movwf   TMR0CNT         ;  with value for 1 S.
 
    ;btg     PORTA, RA0      ; Toggle LED.
        bsf             MYFLAG, 0               ; Turn on flag to tell timer is done
 
intTMR0IF_Ret:
        movlw   0xE0
        movwf   TMR0L
    bcf     INTCON, TMR0IF  ; Clear TIMER0 interrupt flag.
 
    retfie                  ; Return from the interrupt.
 
                ;retfie FAST
 
delay:
        bsf             T0CON,TMR0ON    ; Turns on timer0
 
delay_LOOP:
        btfss   MYFLAG, 0               ; checks timer_done flag
        goto delay_LOOP                 ; loops until it's set
 
        bcf             T0CON,TMR0ON    ; Turns off timer0
        bcf             MYFLAG, 0               ; clears timer_don flag for next time
 
        return
 
send_byte1:
        bcf             PORTB, 0        ; Clear FSYNC bit
        call    delay           ; wait
 
 
; sending the data      bsf             PORTB, 0        ; Set FSYNC
 
send_byte2:
        movlw   8
        movwf   BITN
        bcf             MYFLAG, 1       ; Clears bits-done flag
 
send_LOOP:
        decfsz  BITN,1          ; Decrease bit number
        goto send_continue
        bsf             MYFLAG, 1       ; If N=0, sets flag for bits done
 
send_continue
        bcf             PORTC,7         ; SENT BIT IS LOW BY DEFAULT
        btfsc   SBYTE,7
        bsf             PORTC,7         ; SETS IT HIGH IF THE N-TH BIT IS HIGH
;ABI debug
        rlcf    SBYTE,1         ; Shift BYTE one bit to the left 
 
        bsf             PORTC,6         ; CLK-HIGH
        call delay
        bcf             PORTC,6         ; CLK-LOW
        call delay
 
        btfss   MYFLAG,1        ; Skips if bits-done flag is high
        goto send_LOOP
 
        return
;******************************************************************************
;Start of main program
; The main program code is placed here.
 
Main:
;       *** main code goes here ***
        nop
init:
;    bcf     OSCCON, IRCF0   ; Set internal oscillator
;    bsf     OSCCON, IRCF1   ;  frequency to 4 MHz.
;    bsf     OSCCON, IRCF2   ;  ...
 
    movlw   0x0F            ; Disable all ADC
    setf    ADCON1          ;  and comparator.
;    movlw   0x07            ;  ...
;    movwf   CMCON           ;  ...
 
    clrf    PORTA           ; Initialize PORTA to
    clrf    LATA            ;  all digital outputs.
    clrf    TRISA           ;  ...
 
    clrf    PORTB           ; Initialize PORTA to
    clrf    LATB            ;  all digital outputs.
    clrf    TRISB           ;  ...
 
    clrf    PORTC           ; Initialize PORTA to
    clrf    LATC            ;  all digital outputs.
    clrf    TRISC           ;  ...
 
        bsf             PORTB,0                 ; FSYNC starts in High
        
 
    bsf     RCON, IPEN      ; Enable priority levels, and
    bsf     INTCON, GIEH    ;  high priority interrupts.
 
    bcf     INTCON, TMR0IF  ; Clear the TIMER0 interrupt
    bsf     INTCON, TMR0IE  ;  flag, and enable the
                            ;  TIMER0 Interrupt.
 
    ;movlw   0xF             ; Load TIMER0 overflow counter
        movlw   0x1             ; Load TIMER0 overflow counter
    movwf   TMR0CNT         ;  with initial value for 1 S.
 
    ;movlw   b'11000111'     ; Configure and enable TIMER0.
    movlw   b'01000000'     ; Configure TIMER0.
    movwf   T0CON           ;  (See 11.0 TIMER0 Module
                            ;  in the datasheet for
                            ;  description of the bits
                            ;  set in this register.)   
 
        call delay
        call delay
        call delay
        call delay
 
 
        movlw   COMMAND1
        movwf   SBYTE
        call send_byte1
        movlw   COMMAND2
        movwf   SBYTE
        call send_byte2
 
        ;goto jump ; 
        ;bsf PORTB, 0   ;setting up fsync to go low now
        ;call   delay
        
        movlw   COMMAND3
        movwf   SBYTE
        call send_byte1
        movlw   COMMAND4
        movwf   SBYTE
        call send_byte2
 
        ;bsf    PORTB, 0        
        ;call   delay
 
        movlw   COMMAND5
        movwf   SBYTE
        call send_byte1 
        movlw   COMMAND6
        movwf   SBYTE
        call send_byte2
 
        ;bsf PORTB, 0   ;setting up fsync to go low now
        ;call   delay
 
        movlw   COMMAND7
        movwf   SBYTE
        call send_byte1
        movlw   COMMAND8
        movwf   SBYTE
        call send_byte2
 
        ;bsf PORTB, 0   ;setting up fsync to go low now
        ;call   delay
 
        movlw   COMMAND9
        movwf   SBYTE
        call send_byte1
        movlw   COMMAND10
        movwf   SBYTE
        call send_byte2
 
        
        ;bsf PORTB, 0   ;setting up fsync to go low now
        ;call   delay
 
        movlw   COMMAND11
        movwf   SBYTE
        call send_byte1
        movlw   COMMAND12
        movwf   SBYTE
        call send_byte2
 
 
 
 
        bsf     PORTB, 0        ;last word is programmed
 
jump:
 
        bsf             PORTB,3                 ; Turn on RB3 to tell wer're done
 
LOOP:
        goto LOOP
 
;******************************************************************************
;End of program
 
                END

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top