-
Notifications
You must be signed in to change notification settings - Fork 1
/
ad9850prog.c
59 lines (49 loc) · 1.31 KB
/
ad9850prog.c
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
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#define RST_PIN PC5 // Reset pin -- AD9850 <----> AtMega328
#define DATA_PIN PC4 // Data pin -- AD9850 <----> AtMega328
#define FU_UD_PIN PC3 // Freq_up pin -- AD9850 <----> AtMega328
#define W_CLK_PIN PC2 // Word Clock pin -- AD9850 <----> AtMega328
void pulse_high(uint8_t pin){
PORTC |= _BV(pin);
PORTC &= ~_BV(pin);
}
void send_byte(uint8_t byte){
for(uint8_t i = 0; i < 8; i++, byte >>= 1){
if( !(byte & 0x01) )
PORTC &= ~_BV(DATA_PIN);
else
PORTC |= _BV(DATA_PIN);
pulse_high(W_CLK_PIN);
}
}
void freq_send(uint64_t frequency){
uint32_t freq = (frequency * 4294967296) / (uint64_t)125E6;
for(uint8_t j = 0; j < 4; j++, freq >>= 8){
send_byte(freq & 0xff);
}
send_byte(0x0000);
pulse_high(FU_UD_PIN);
}
void ad9850_setup(void){
// Set AD9850 pins as output
DDRC |= (1 << RST_PIN) | (1 << DATA_PIN) | (1 << FU_UD_PIN) | (1 << W_CLK_PIN);
pulse_high(RST_PIN);
pulse_high(W_CLK_PIN);
pulse_high(FU_UD_PIN);
}
int main(void){
ad9850_setup();
for( ; ; ){
freq_send(2e6);
_delay_ms(3000);
freq_send(5e6);
_delay_ms(3000);
freq_send(10e6);
_delay_ms(3000);
freq_send(39e6);
_delay_ms(3000);
}
return 0;
}