Sei sulla pagina 1di 38

FUENTE: http://www.mikroe.com/forum/viewtopic.php?

f=97&t=56860

GREETINGS

This module described here is based on ADS9850, a CMOS, 125MHz, and Complete DDS
Synthesizer.
The AD9850 is a highly integrated device that uses advanced DDS technology coupled with an
internal high speed, high performance, D/A converter and comparator, to form a complete
digitally programmable frequency synthesizer and clock generator function.
All the external components which are needed are integrated on the board and the designer
dont need to care more about the detailed design of ADS9850. The designer only needs to
add the power and control signals to this module to driver this module

Signal Frequency output range: 0-40MHz


4 Signal outputs:
2 sine wave outputs and 2 square wave outputs
DAC SFDR > 50 dB @ 40 MHz AOUT
32-Bit Frequency Tuning Word
Simplified Control Interface: Parallel Byte or Serial Loading Format
Phase Modulation Capability
+3.3 V or +5 V Single Supply Operation
Low Power: 380 mW @ 125 MHz (+5 V)
Low Power: 155 mW @ 110 MHz (+3.3 V)
Power-Down Function

AT THE END OF THE TOPIC IS DOWNLOADS SOURCE WRITTEN IN MIKROBASIC PRO 3.2
Pin definition
The assembly drawing
Schematic
Schematic
8-Bit Parallel-Load Data/Control Word Functional Assignment
The AD9850 contains a 40-bit register that is used to program the 32-bit frequency control
word, the 5-bit phase modulation word and the power-down function. This register can be
loaded in a parallel or serial mode.
In the parallel load mode, the register is loaded via an 8-bit bus; the full 40-bit word requires
five iterations of the 8-bit word. The W_CLK and FQ_UD signals are used to address and load
the registers. The rising edge of FQ_UD loads the (up to) 40-bit control data word into the
device and resets the address pointer to the first register. Subsequent W_CLK rising edges
load the 8-bit data on words [7:0] and move the pointer to the next register. After five loads,
W_CLK edges are ignored until either a reset or an FQ_UD rising edge resets the address
pointer to the first register.
In serial load mode, subsequent rising edges of W_CLK shift the 1-bit data on Lead 25 (D7)
through the 40 bits of programming information. After 40 bits are shifted through, an FQ_UD
pulse is required to update the output frequency (or phase).

Code: Select all


'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
' * Project name:
' AD9850_SIGNALl_GENERATOR
' * Copyright:
' S59KB
' Thank microelectronics, 2013
' * Revision History:
' 20131019:
' * Description:
' This module described here is based on ADS9850, a CMOS, 125MHz, and Complete DDS Synthesizer.
' The AD9850 is a highly integrated device that uses advanced DDS technology coupled with an
' internal high speed, high performance, D/A converter and comparator, to form a complete
' digitally programmable frequency synthesizer and clock generator function.
' All the external components which are needed are integrated on the board and the designer
' dont need to care more about the detailed design of ADS9850. The designer only needs to
' add the power and control signals to this module to driver this module.
' * Test configuration:
' MCU: PIC18F2620
' Dev. Board: EasyPIC v5
' Oscillator: HS-PLL, 20.000 MHz Crystal
'
' ext. modules: AD9850
' http://www.eimodule.com/index.php?main_page=product_info&cPath=18_23&products_id=52
' http://www.analog.com/static/imported-files/data_sheets/AD9850.pdf
'
' SW: mikroBasic PRO for PIC
' v 3.20
' * NOTES:
' Signal Frequency output range: 0-40MHz
' 4 Signal outputs:
' 2 sine wave outputs and 2 square wave outputs
' DAC SFDR > 50 dB @ 40 MHz AOUT
' 32-Bit Frequency Tuning Word
' Simplified Control Interface: Parallel Byte or Serial Loading Format
' Phase Modulation Capability
' +3.3 V or +5 V Single Supply Operation
' Low Power: 380 mW @ 125 MHz (+5 V)
' Low Power: 155 mW @ 110 MHz (+3.3 V)
' Power-Down Function
'
' The AD9850 is a highly integrated device that uses advanced
' DDS technology coupled with an internal high speed, high
' performance, D/A converter and comparator, to form a complete
' digitally programmable frequency synthesizer and clock
' generator function. When referenced to an accurate clock
' source, the AD9850 generates a spectrally pure, frequency/
' phase-programmable, analog output sine wave. This sine wave
' can be used directly as a frequency source or converted to a
' square wave for agile-clock generator applications. The AD9850s
' innovative high speed DDS core provides a 32-bit frequency
' tuning word, which results in an output tuning resolution of
' 0.0291 Hz, for a 125 MHz reference clock input. The
' AD9850s circuit architecture allows the generation of output
' frequencies of up to one-half the reference clock frequency (or
' 62.5 MHz), and the output frequency can be digitally changed
' (asynchronously) at a rate of up to 23 million new frequencies
' per second.
' The device also provides five bits of digitally
' controlled phase modulation, which enables phase shifting of its
' output in increments of 180, 90, 45, 22.5, 11.25 and any
' combination thereof. The AD9850 also contains a high speed
' comparator that can be configured to accept the (externally)
' filtered output of the DAC to generate a low jitter square wave
' output. This facilitates the devices use as an agile clock generator
' function.
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
program AD9850_SIGNALl_GENERATOR
'---------------------------------------
include MB_PRO_LCD_HS_PLL
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
' Tested on 18F26200 @ 20 MHz....
' ______ _____
' ( (__) )
' BUTTON_RESET RE3 O (1 28) O RB7 D_7 EIM377_AD9850
' ( )
' LCD_EN RA0/AN0 O (2 27) O RB6 D_6 EIM377_AD9850
' ( )
' LCD_RS RA1/AN1 O (3 26) O RB5 D_5 EIM377_AD9850
' ( )
' LCD_D7 RA2/AN2 O (4 25) O RB4 D_4 EIM377_AD9850
' ( )
' LCD_D6 RA3/AN3 O (5 24) O RB3 D_3 EIM377_AD9850
' ( )
' LCD_D5 RA4 O (6 23) O RB2 D_2 EIM377_AD9850
' ( )
' LCD_D4 RA5/AN4 O (7 22) O RB1 D_1 EIM377_AD9850
' ( )
' 0 V VSS O (8 21) O RB0 D_0 EIM377_AD9850
' ( )
' [ OSC O (9 20) O VDD + 5 V
' 16 MHZ ( )
' [ OSC O (10 19) O VSS 0 V
' ( )
' BUTTON_DOWN RCO O (11 18) O RC7 BIPER SOUND
' ( )
' BUTTON_LEFT RC1 O (12 17) O RC6 W_CLK_EIM377_AD9850
' ( )
' BUTTON_UP RC2 O (13 16) O RC5 FQ_UD_EIM377_AD9850
' ( )
' BUTTON_RIGHT RC3 O (14 15) O RC4 RESET_EIM377_AD9850
' (______________)
'
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SYMBOL BUTTON_RESET = PORTE.3
SYMBOL BUTTON_DOWN = PORTC.0
SYMBOL BUTTON_LEFT = PORTC.1
SYMBOL BUTTON_UP = PORTC.2
SYMBOL BUTTON_RIGHT = PORTC.3
' AD9850 connections
SYMBOL AD9850_RESET = PORTC.4
SYMBOL AD9850_FQ_UD = PORTC.5
SYMBOL AD9850_W_CLK = PORTC.6
' SYMBOL BIPER = PORTC.7
SYMBOL AD9850_DATA = PORTB
SYMBOL AD9850_FREQUENCY_FACTOR = 34.35973837 ' ( 2^32 / 125000000 Hz)
' Lcd module connections
DIM LCD_RS as sbit at RA0_bit
DIM LCD_EN as sbit at RA1_bit
DIM LCD_D4 as sbit at RA5_bit
DIM LCD_D5 as sbit at RA4_bit
DIM LCD_D6 as sbit at RA3_bit
DIM LCD_D7 as sbit at RA2_bit
DIM LCD_RS_Direction as sbit at TRISA0_bit
DIM LCD_EN_Direction as sbit at TRISA1_bit
DIM LCD_D4_Direction as sbit at TRISA5_bit
DIM LCD_D5_Direction as sbit at TRISA4_bit
DIM LCD_D6_Direction as sbit at TRISA3_bit
DIM LCD_D7_Direction as sbit at TRISA2_bit
DIM FT101_TX AS Boolean
' ENKODER
DIM BR AS BYTE
DIM ROTARY_ENCODER_A_OLD AS BYTE
DIM ROTARY_ENCODER_B_OLD AS BYTE
DIM ROTARY_ENCODER_OUT_A AS BYTE
DIM ROTARY_ENCODER_OUT_B AS BYTE
DIM MULTIPLIER AS longword
DIM PHASE_SELECT AS BYTE
DIM SELECT_MULTIPLIER AS SHORT
DIM ROTARY_MULTIPLIER AS longword
DIM BLINK_FEQ AS BYTE
DIM BLINK_PHA AS BYTE
' OTHER
DIM FREQ_AD9850 AS longint
DIM PHASE_AD9850 AS byte
DIM CONFIG_AD9850 AS BYTE
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE BIP()
Sound_Play(1000, 50)
Delay_ms(100)
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE UP_DOWN_PHASE()
IF (BUTTON_UP = 1) AND (PHASE_SELECT = 1) THEN
PHASE_AD9850 = PHASE_AD9850 + 1
BIP()
END IF
IF (BUTTON_DOWN = 1) AND (PHASE_SELECT = 1) THEN
PHASE_AD9850 = PHASE_AD9850 - 1
BIP()
END IF
IF PHASE_AD9850 > 31 THEN PHASE_AD9850 = 0 END IF
IF PHASE_AD9850 < 0 THEN PHASE_AD9850 = 31 END IF
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE UP_DOWN_FREQ()
IF (BUTTON_UP = 1) AND (PHASE_SELECT = 0) THEN
FREQ_AD9850 = FREQ_AD9850 + ROTARY_MULTIPLIER
BIP()
END IF
IF (BUTTON_DOWN = 1) AND (PHASE_SELECT = 0) THEN
FREQ_AD9850 = FREQ_AD9850 - ROTARY_MULTIPLIER
BIP()
END IF
IF SELECT_MULTIPLIER > 7 THEN SELECT_MULTIPLIER = 1 END IF
IF FREQ_AD9850 > 40000000 THEN FREQ_AD9850 = 40000000 END IF
IF FREQ_AD9850 < 0 THEN FREQ_AD9850 = 1 END IF
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE PHASE_LCD(DIM RE, VR AS BYTE, DIM VREDNOST AS BYTE)
DIM ON_OFF AS BYTE
DIM PHASE_WORD AS STRING[6]
ON_OFF = 10
INC(BLINK_PHA)
' Phase-b7 Phase-b6 Phase-b5 Phase-b4 Phase-b3
' 180 90 45 22.5 11.25
select case VREDNOST
case %00000 PHASE_WORD = " 0"
case %00001 PHASE_WORD = " 11.25"
case %00010 PHASE_WORD = " 22.5"
case %00011 PHASE_WORD = " 33.75"
case %00100 PHASE_WORD = " 45"
case %00101 PHASE_WORD = " 56.25"
case %00110 PHASE_WORD = " 67.5"
case %00111 PHASE_WORD = " 78.75"
case %01000 PHASE_WORD = " 90"
case %01001 PHASE_WORD = "101.25"
case %01010 PHASE_WORD = " 112.5"
case %01011 PHASE_WORD = "123.75"
case %01100 PHASE_WORD = " 135"
case %01101 PHASE_WORD = "146.25"
case %01110 PHASE_WORD = " 157.5"
case %01111 PHASE_WORD = "168.75"
case %10000 PHASE_WORD = " 180"
case %10001 PHASE_WORD = "191.25"
case %10010 PHASE_WORD = " 202.5"
case %10011 PHASE_WORD = "213.75"
case %10100 PHASE_WORD = " 225"
case %10101 PHASE_WORD = "236.25"
case %10110 PHASE_WORD = " 247.5"
case %10111 PHASE_WORD = "258.75"
case %11000 PHASE_WORD = " 270"
case %11001 PHASE_WORD = "281.25"
case %11010 PHASE_WORD = " 292.5"
case %11011 PHASE_WORD = "303.75"
case %11100 PHASE_WORD = " 315"
case %11101 PHASE_WORD = "326.25"
case %11110 PHASE_WORD = " 337.5"
case %11111 PHASE_WORD = "348.75"
end select
IF (BLINK_PHA < ON_OFF) AND (PHASE_SELECT = 1) THEN
Lcd_PLL_Out(RE, VR, " ")
ELSE
Lcd_PLL_Out(RE, VR, PHASE_WORD)
Lcd_PLL_Out(RE, VR + 6, " DEG")
END IF
IF (BLINK_PHA > ON_OFF * 4) THEN BLINK_PHA = 0 END IF
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE FREC_LCD(DIM RE, VR AS BYTE, DIM VREDNOST AS longword)
DIM ON_OFF AS BYTE
DIM CH_BYTE AS longword
ON_OFF = 10
INC(BLINK_FEQ)
'--------------
CH_BYTE = (VREDNOST / 10000000)MOD 10 LCD_PLL_Chr(RE, VR, 48 + CH_BYTE) ' 10,000,000 Hz
'--------------
CH_BYTE = (VREDNOST / 1000000)MOD 10 LCD_PLL_Chr(RE, VR + 1, 48 + CH_BYTE) ' 1,000,000
Hz 7_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 7) THEN Lcd_PLL_Out(RE, VR + 1, " ") END IF
'--------------
LCD_PLL_Chr(RE, VR + 2, 46)
'--------------
CH_BYTE = (VREDNOST / 100000)MOD 10 LCD_PLL_Chr(RE, VR + 3, 48 + CH_BYTE) ' 100,000
Hz 6_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 6) THEN Lcd_PLL_Out(RE, VR + 3, " ") END IF
'--------------
CH_BYTE = (VREDNOST / 10000)MOD 10 LCD_PLL_Chr(RE, VR + 4, 48 + CH_BYTE) ' 10,000
Hz 5_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 5) THEN Lcd_PLL_Out(RE, VR + 4, " ") END IF
'--------------
CH_BYTE = (VREDNOST / 1000)MOD 10 LCD_PLL_Chr(RE, VR + 5, 48 + CH_BYTE) ' 1,000
Hz 4_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 4) THEN Lcd_PLL_Out(RE, VR + 5, " ") END IF
'--------------
LCD_PLL_Chr(RE, VR + 6, 46)
'--------------
CH_BYTE = (VREDNOST / 100)MOD 10 LCD_PLL_Chr(RE, VR + 7, 48 + CH_BYTE) ' 100
Hz 3_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 3) THEN Lcd_PLL_Out(RE, VR + 7, " ") END IF
'--------------
CH_BYTE = (VREDNOST / 10)MOD 10 LCD_PLL_Chr(RE, VR + 8, 48 + CH_BYTE) ' 10
Hz 2_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 2) THEN Lcd_PLL_Out(RE, VR + 8, " ") END IF
'--------------
CH_BYTE = (VREDNOST)MOD 10 LCD_PLL_Chr(RE, VR + 9, 48 + CH_BYTE) ' 1
Hz 1_MULTIPLIER
IF (BLINK_FEQ < ON_OFF) AND (SELECT_MULTIPLIER = 1) THEN Lcd_PLL_Out(RE, VR + 9, " ") END IF
'--------------
IF (BLINK_FEQ > ON_OFF * 4) THEN BLINK_FEQ = 0 END IF
Lcd_PLL_Out(RE, VR + 11, "Mhz")
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure SELECT_ROTARY_MULTIPLIER()
IF BUTTON_RIGHT = 1 THEN
SELECT_MULTIPLIER = SELECT_MULTIPLIER + 1
BIP()
END IF
IF BUTTON_LEFT = 1 THEN
SELECT_MULTIPLIER = SELECT_MULTIPLIER - 1
BIP()
END IF
IF SELECT_MULTIPLIER > 7 THEN SELECT_MULTIPLIER = 0 END IF
IF SELECT_MULTIPLIER < 0 THEN SELECT_MULTIPLIER = 7 END IF
select case SELECT_MULTIPLIER
case 0 PHASE_SELECT = 1 MULTIPLIER = MULTIPLIER
case 1 PHASE_SELECT = 0 MULTIPLIER = 1
case 2 PHASE_SELECT = 0 MULTIPLIER = 10
case 3 PHASE_SELECT = 0 MULTIPLIER = 100
case 4 PHASE_SELECT = 0 MULTIPLIER = 1000
case 5 PHASE_SELECT = 0 MULTIPLIER = 10000
case 6 PHASE_SELECT = 0 MULTIPLIER = 100000
case 7 PHASE_SELECT = 0 MULTIPLIER = 1000000
end select
ROTARY_MULTIPLIER = MULTIPLIER
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE Init_AD9850()
' Reset chip
AD9850_RESET = 1 Delay_ms(100)
AD9850_RESET = 0 Delay_ms(100)
' Reset register
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
SUB PROCEDURE SendToAD9850(DIM Phase AS byte, DIM Config AS byte, DIM Freq AS longword)
' data[7] data[6] data[5] data[4] data[3] data[2] data[1] data[0]
' W0 Phase-b7 Phase-b6 Phase-b5 Phase-b4 Phase-b3 Power-Down Control Control-b0
' W1 Freq-b31 Freq-b30 Freq-b29 Freq-b28 Freq-b27 Freq-b26 Freq-b25 Freq-b24
' W2 Freq-b23 Freq-b22 Freq-b21 Freq-b20 Freq-b19 Freq-b18 Freq-b17 Freq-b16
' W3 Freq-b15 Freq-b14 Freq-b13 Freq-b12 Freq-b11 Freq-b10 Freq-b9 Freq-b8
' W4 Freq-b7 Freq-b6 Freq-b5 Freq-b4 Freq-b3 Freq-b2 Freq-b1 Freq-b0
DIM Phase_Config AS BYTE
'--------------------------------
Phase_Config = (248 * Phase) + Config
' Freq = Freq * AD9850_FREQUENCY_FACTOR
Freq = Freq / 0.0291
'--------------------------------
AD9850_FQ_UD = 1 Delay_us(4)
AD9850_FQ_UD = 0 Delay_us(4)
AD9850_DATA = Phase_Config Delay_us(1) 'Phase_Config
AD9850_W_CLK = 1 Delay_us(2)
AD9850_W_CLK = 0 Delay_us(2)
'--------------------------------
AD9850_DATA = Highest(Freq) Delay_us(1)
AD9850_W_CLK = 1 Delay_us(2)
AD9850_W_CLK = 0 Delay_us(2)
'--------------------------------
AD9850_DATA = Higher(Freq) Delay_us(1)
AD9850_W_CLK = 1 Delay_us(2)
AD9850_W_CLK = 0 Delay_us(2)
'--------------------------------
AD9850_DATA = Hi(Freq) Delay_us(1)
AD9850_W_CLK = 1 Delay_us(2)
AD9850_W_CLK = 0 Delay_us(2)
'--------------------------------
AD9850_DATA = Lo(Freq) Delay_us(1)
AD9850_W_CLK = 1 Delay_us(2)
AD9850_W_CLK = 0 Delay_us(2)
'--------------------------------
AD9850_FQ_UD = 1 Delay_us(2)
AD9850_DATA = 0 Delay_us(1)
'--------------------------------
END SUB
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
main:
ADCON1 = %00001111 ' all inputs is digital
INTCON3 = 0xC0
RCON.IPEN = $00 ' Disable Priority Levels on interrupts
PIE1 = $00
PIE2 = $00
PIR1 = $00
PIR2 = $00
LATA = $00
LATB = $00
LATC = $00
TRISA = $00 ' set PORTA to be output
PORTA = $00
TRISB = $00 ' set PORTB to be output
PORTB = $00 ' set PORTB to be output
TRISC = $0F ' set PORTC to be output AND 0_1_2_3 INPUT
PORTC = $00
Delay_ms(10)
'-------------------------------------------------------------------------------
Sound_Init(PORTC, 7) ' Initialize sound at RD3
' POSTAVLJANJE DISPLEJA
LCD_PLL_INIT ' Initialize Lcd
LCD_PLL_CMD(_LCD_CURSOR_OFF)
LCD_PLL_CMD(_Lcd_Clear)
Delay_ms(10)
' VIDEO GREETINGS
Lcd_PLL_Out(1, 1, " SIGNAL GENERATOR ")
Lcd_PLL_Out(2, 1, "MODULE EIM377 AD9850")
Lcd_PLL_Out(3, 1, "Phase: 0 to 360 DEG")
Lcd_PLL_Out(4, 1, "Freq: 0 to 40 Mhz")
BIP()
Delay_ms(3000)
LCD_PLL_CMD(_Lcd_Clear)
BIP()
Lcd_PLL_Out(1, 1, " SIGNAL GENERATOR ")
Lcd_PLL_Out(2, 1, " sinus and square ")
Lcd_PLL_Out(3, 1, "Phase:")
Lcd_PLL_Out(4, 1, "Freq:")
'-------------------------------------------------------------------------------
SELECT_MULTIPLIER = 3
FREQ_AD9850 = 1000000
PHASE_AD9850 = %10000 ' 5 Bita
CONFIG_AD9850 = %000 ' 3 Bita
SELECT_MULTIPLIER = 0
Init_AD9850()
Delay_ms(250)
BIP()
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
WHILE TRUE
SELECT_ROTARY_MULTIPLIER()
UP_DOWN_PHASE()
UP_DOWN_FREQ()
PHASE_LCD(3, 7, PHASE_AD9850)
FREC_LCD(4, 7, FREQ_AD9850)
SendToAD9850(PHASE_AD9850, CONFIG_AD9850, FREQ_AD9850)
wend
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
end.
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************

Code: Select all


'*******************************************************************************
'' EXAMPLE INCLUDING USE IN PLL
'' Oscillator: HS-PLL 10.0000 MHz UP TO 40.000 MHz
MODULE MB_PRO_LCD_HS_PLL
'' *
'' * Modul name:
'' Lcd_PLL_Test (Simple demonstration of the LCD_PLL Module sub functions)
'' * Copyright:
'' S59KB Thank microelectronics, 2012
'' * Revision History:
'' 20120726:
'' - initial release.
'' * Description:
'' EXAMPLE INCLUDING USE IN HS-PLL Oscillator
'' This is a simple demonstration of LCD_PLL library Module.
''
'' * Test configuration:
'' MCU: P18F2620 or any other
'' Dev.Board: EasyPIC5
'' Oscillator: HS-PLL 10.0000 MHz
'' Ext. Modules: me LCD 4x20 or any other
'' SW: mikroBasic Pro v 3.2
'' *
'' INCLUDE LCD_PLL_MODULE
'' Library Routines LCD_HS_PLL
'' Lcd_Init_______________________LCD_PLL_INIT
'' Lcd_Cmd________________________LCD_PLL_CMD
'' Lcd_Chr________________________LCD_PLL_CHR
'' Lcd_Chr_Cp_____________________LCD_PLL_CHR_CP
'' Lcd_Out________________________LCD_PLL_OUT
'' Lcd_Out_Cp_____________________LCD_PLL_OUT_CP
''
''
'' LCD_PLL_INIT Initializes LCD at port with default pin settings (see the connection scheme at
the end of the chapter)
''
'' LCD_PLL_CMD(_Lcd_Clear) Sends command to LCD. You can pass one of the predefined constants to the
function. The complete list of available commands is below.
'' _LCD_FIRST_ROW Move cursor to the 1st row
'' _LCD_SECOND_ROW Move cursor to the 2nd row
'' _LCD_THIRD_ROW Move cursor to the 3rd row
'' _LCD_FOURTH_ROW Move cursor to the 4th row
'' _LCD_CLEAR Clear display
'' _LCD_RETURN_HOME Return cursor to home position, returns a shifted display to its
original position. Display data RAM is unaffected.
'' _LCD_CURSOR_OFF Turn off cursor
'' _LCD_UNDERLINE_ON Underline cursor on
'' _LCD_BLINK_CURSOR_ON Blink cursor on
'' _LCD_MOVE_CURSOR_LEFT Move cursor left without changing display data RAM
'' _LCD_MOVE_CURSOR_RIGHT Move cursor right without changing display data RAM
'' _LCD_TURN_ON Turn Lcd display on
'' _LCD_TURN_OFF Turn Lcd display off
'' _LCD_SHIFT_LEFT Shift display left without changing display data RAM
'' _LCD_SHIFT_RIGHT Shift display right without changing display data RAM
''
'' LCD_PLL_CHR(1,5,51) Prints character on LCD at specified row and column (parameters row and col). Both
variables and literals can be passed as character.
''
'' LCD_PLL_CHR_CP(51) Prints character on LCD at current cursor position. Both variables and literals
can be passed as character.
''
'' LCD_PLL_OUT(1,1,"mikroBasic") Prints text on LCD at specified row and column (parameters row and col). Both
string variables and literals can be passed as text.
''
'' LCD_PLL_OUT_CP("mikroBasic") Prints text on LCD at current cursor position. Both string variables and literals
can be passed as text.
''
''------------------------------------------------------------------------------
''Example for the generation of new characters
'' const character1 as byte[8] = (21,14,21,4,21,14,21,0) 'KARAKTER 1 ... O O O
'' SUB PROCEDURE CustomChar1 dim i1 as byte O O O
'' DIM i1 AS BYTE O O O
'' LCD_PLL_INIT Delay_ms(250) O
'' LCD_PLL_CMD(64)for i1=0 to 7 LCD_PLL_CHR_CP(character1[i1])next i1 O O O
'' END SUB O O O
''------------------------- O O O
'' LCD_PLL_Cmd(64)for i1 = 0 to 7 LCD_PLL_Chr_Cp(character1[i1])next i1 'KARAKTER 1 ...
''------------------------------------------------------------------------------
'*******************************************************************************
'' Initializes LCD at port with default pin settings.
'' LCD_PLL_CONFIG(Port_x, d3, d2, d1, d0, Port_x, rs, ctrl_rw, enable) Not necessary to make the procedure.
''
'' WRITE YOUR OWN HERE TO CONTACT USE
''------------------------------------------------------------------------------
'' symbol LCD_RW = PORTA.1 'Not used in Module. USE FOR ANYTHING
DIM LCD_RS as sbit sfr external
DIM LCD_EN as sbit sfr external
DIM LCD_D4 as sbit sfr external
DIM LCD_D5 as sbit sfr external
DIM LCD_D6 as sbit sfr external
DIM LCD_D7 as sbit sfr external

DIM K1,K2,KR0,KR1,KR2,KR3 AS BYTE


DIM BAR0,BAR00 AS WORD
const character0 as byte[8] = (0,0,0,21,0,0,0,0) 'KARAKTER 0 ...
const character1 as byte[8] = (16,16,16,21,16,16,16,0) 'KARAKTER 1 /..
const character2 as byte[8] = (20,20,20,21,20,20,20,0) 'KARAKTER 2 //.
const character3 as byte[8] = (21,21,21,21,21,21,21,0) 'KARAKTER 3 ///
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji_nib(DIM RS, NIB AS BYTE)
SUB PROCEDURE LCD_poslji(DIM RS, NIB AS BYTE)
SUB PROCEDURE LCD_PLL_INIT()
SUB PROCEDURE LCD_RED_POZ_OUT(DIM KO,VR AS BYTE)
SUB PROCEDURE LCD_PLL_CMD(DIM TEKST AS BYTE)
SUB PROCEDURE LCD_PLL_CHR(DIM KO,VR AS BYTE,DIM ZNAK AS BYTE)
SUB PROCEDURE LCD_PLL_CHR_CP(DIM ZNAK AS BYTE)
SUB PROCEDURE LCD_PLL_OUT(DIM KO,VR AS BYTE, DIM BYREF TEKST as STRING[20])
SUB PROCEDURE LCD_PLL_OUT_CP(DIM BYREF ZNAK AS STRING[20])
''-----------
sub procedure CustomChar0()
sub procedure CustomChar1()
sub procedure CustomChar2()
sub procedure CustomChar3()
SUB PROCEDURE LCD_NEW_INIT()
SUB PROCEDURE LCD_BAR_METAR(DIM K1,K2,PO AS BYTE,DIM BAR0,BAR00 AS WORD)
implements
''------------------------------------------------------------------------------
'' The initialization of the following adjusted
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji_nib(DIM RS, NIB AS BYTE)
LCD_RS = RS '// namesti RS
LCD_D4 = NIB.0 '// namesti nibbla na izlaz
LCD_D5 = NIB.1
LCD_D6 = NIB.2
LCD_D7 = NIB.3
LCD_EN = 1 '// slanje enable LCD modulu
delay_us(200)
LCD_EN = 0
delay_us(200)
LCD_EN = 1
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_poslji(DIM RS, NIB AS BYTE)
LCD_RS = RS '// slanje gornjeg nibbla
LCD_D4 = NIB.4
LCD_D5 = NIB.5
LCD_D6 = NIB.6
LCD_D7 = NIB.7
delay_us(80)
LCD_EN = 0
delay_us(20)
LCD_EN = 1
LCD_RS = RS '// slanje doljneg nibbla
LCD_D4 = NIB.0
LCD_D5 = NIB.1
LCD_D6 = NIB.2
LCD_D7 = NIB.3
delay_us(80)
LCD_EN = 0
delay_us(80)
LCD_EN = 1
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_INIT() '// Initializes LCD at port with default pin settings.
LCD_EN = 0 delay_ms(200)
LCD_poslji_nib(0,0x03) delay_ms(200)'// 3 puta init
LCD_poslji_nib(0,0x03) delay_ms(80)
LCD_poslji_nib(0,0x03) delay_ms(80)
LCD_poslji_nib(0,0x02) delay_ms(12) '// namesti 4 bita prenos podataka
LCD_poslji(0,0x01) delay_ms(12) '// obrisi displaj
LCD_poslji(0,0x28) delay_ms(4) '// nastavi znakove sa 5x7 font
LCD_poslji(0,0x0C) delay_ms(4) '// ukljuci displj, izkljuci kursor i blinkanje
LCD_poslji(0,0X06) delay_ms(4) '// namesti smer pomeranja kursora i shift displaj
delay_ms(100)
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_RED_POZ_OUT(DIM KO,VR AS BYTE)
if (KO = 1) THEN LCD_poslji(0,128 + VR) ELSE END IF
if (KO = 2) THEN LCD_poslji(0,192 + VR) ELSE END IF
if (KO = 3) THEN LCD_poslji(0,148 + VR) ELSE END IF
if (KO = 4) THEN LCD_poslji(0,212 + VR) ELSE END IF
delay_us(100)
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_CMD(DIM TEKST AS BYTE)
LCD_poslji(0,TEKST)
delay_ms(100)
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_CHR(DIM KO,VR AS BYTE,DIM ZNAK AS BYTE)
LCD_RED_POZ_OUT(KO,VR-1)
LCD_poslji (1,ZNAK)
delay_us(100)
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_CHR_CP(DIM ZNAK AS BYTE)
LCD_poslji (1,ZNAK)
delay_us(100)
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_OUT(DIM KO,VR AS BYTE, DIM BYREF TEKST as STRING[20])
DIM LOOP_INDEX AS BYTE
DIM INDEX AS BYTE
INDEX = Strlen(TEKST)- 1
FOR LOOP_INDEX = 0 TO INDEX
LCD_PLL_CHR(KO,VR+LOOP_INDEX , TEKST[LOOP_INDEX])
NEXT LOOP_INDEX
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_PLL_OUT_CP(DIM BYREF ZNAK AS STRING[20])
DIM LOOP_INDEX AS BYTE
DIM INDEX AS BYTE
INDEX = Strlen(ZNAK)- 1
FOR LOOP_INDEX = 0 TO INDEX
LCD_PLL_CHR_CP(ZNAK[LOOP_INDEX])
NEXT LOOP_INDEX
delay_us(100)
END SUB
''------------------------------------------------------------------------------
' START GENERISANJA NOVA 4 ZNAKA LCD BOKI
''------------------------------------------------------------------------------
sub procedure CustomChar0()
dim i0 as byte
LCD_PLL_CMD(64)for i0=0 to 7 LCD_PLL_CHR_CP(character0[i0])next i0
end sub
''------------------------------------------------------------------------------
sub procedure CustomChar1()
dim i1 as byte
LCD_PLL_CMD(72)for i1=0 to 7 LCD_PLL_CHR_CP(character1[i1])next i1
end sub
''------------------------------------------------------------------------------
sub procedure CustomChar2()
dim i2 as byte
LCD_PLL_CMD(80)for i2=0 to 7 LCD_PLL_CHR_CP(character2[i2])next i2
end sub
''------------------------------------------------------------------------------
sub procedure CustomChar3()
dim i3 as byte
LCD_PLL_CMD(88)for i3=0 to 7 LCD_PLL_CHR_CP(character3[i3])
next i3 end sub
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_NEW_INIT
DIM i0,i1,i2,i3 AS BYTE
LCD_PLL_CMD(64)for i0 = 0 to 7 LCD_PLL_CHR_CP(character0[i0])next i0 'KARAKTER 0 ...
LCD_PLL_CMD(72)for i1 = 0 to 7 LCD_PLL_CHR_CP(character1[i1])next i1 'KARAKTER 1 /.
LCD_PLL_CMD(80)for i2 = 0 to 7 LCD_PLL_CHR_CP(character2[i2])next i2 'KARAKTER 2 //.
LCD_PLL_CMD(88)for i3 = 0 to 7 LCD_PLL_CHR_CP(character3[i3])next i3 'KARAKTER 3 ///
LCD_PLL_CMD(_LCD_CLEAR)
LCD_PLL_CMD(_LCD_CURSOR_OFF)
END SUB
''------------------------------------------------------------------------------
SUB PROCEDURE LCD_BAR_METAR(DIM K1,K2,PO AS BYTE,DIM BAR0,BAR00 AS WORD)
DIM KR AS BYTE
FOR KR=1 TO PO ' PO=19
IF BAR0>BAR00* (KR*3) THEN LCD_PLL_CHR(K1,K2+KR-1,3) ELSE
IF BAR0>BAR00*((KR*3)-1)THEN LCD_PLL_CHR(K1,K2+KR-1,2) ELSE
IF BAR0>BAR00*((KR*3)-2)THEN LCD_PLL_CHR(K1,K2+KR-1,1) ELSE
LCD_PLL_CHR(K1,K2+KR-1,0) END IF END IF END IF
NEXT KR
END SUB
''------------------------------------------------------------------------------
END. ' and ENJOY :)
''------------------------------------------------------------------------------

MY HOME MADE SIGNAL GENERATOR

Pictures for working module


Pictures for working module
SINUS

SQUARE
#########################################################################################
#########################################################################################

IF YOU WANT WITH SERIAL CHIP TO COMMUNICATE USING THE FOLLOWING


FOR CHANGE JUNCTION BETWEEN CHIP AND MODULES
40-Bit Serial-Load Word Function Assignment
Code: Select all
' AD9850 connections
SYMBOL AD9850_W_CLK = BY YOUR CHOICE FOR EXAMPLE PORTB.0
SYMBOL AD9850_FQ_UD = BY YOUR CHOICE FOR EXAMPLE PORTB.1
SYMBOL AD9850_RESET = BY YOUR CHOICE FOR EXAMPLE PORTB.2
SYMBOL AD9850_DATA = BY YOUR CHOICE FOR EXAMPLE PORTC.3
40-Bit Serial-Load Word Function Assignment

Code: Select all


SUB PROCEDURE SendToAD9850Serial(DIM Phase AS byte, DIM Config AS byte, DIM Freq AS longword)
' W0 Freq-b0 W1 Freq-b1 W2 Freq-b2 W3 Freq-b3
' W4 Freq-b4 W5 Freq-b5 W6 Feq-b6 W7 Freq-b7
' W8 Freq-b8 W9 Freq-b9 W10 Freq-b10 W11 Freq-b11
' W12 Freq-b12 W13 Freq-b13 W28 Freq-b28 W29 Freq-b29
' W30 Freq-b30 W31 Freq-b31
' W32 Control W33 Control W34 Power-Down W35 Phase-b0
' W36 Phase-b1 W37 Phase-b2 W38 Phase-b3 W39 Phase-b4
DIM Phase_Config AS BYTE
DIM BR AS BYTE
DIM DATA_0 AS byte
DIM DATA_1 AS byte
DIM DATA_2 AS byte
DIM DATA_3 AS byte
DIM DATA_4 AS byte
'--------------------------------
Phase_Config = (248 * Phase) + Config
' Freq = Freq * AD9850_FREQUENCY_FACTOR
Freq = Freq / 0.0291
'--------------------------------
DATA_0 = Lo(Freq)
DATA_1 = Hi(Freq)
DATA_2 = Higher(Freq)
DATA_3 = Highest(Freq)
DATA_4 = Phase_Config
'--------------------------------
AD9850_FQ_UD = 1 Delay_us(8)
AD9850_FQ_UD = 0
FOR BR = 0 TO 7
AD9850_DATA = DATA_0.BR
AD9850_W_CLK = 1 Delay_us(4)
AD9850_W_CLK = 0 Delay_us(4)
NEXT BR
FOR BR = 0 TO 7
AD9850_DATA = DATA_1.BR
AD9850_W_CLK = 1 Delay_us(4)
AD9850_W_CLK = 0 Delay_us(4)
NEXT BR
FOR BR = 0 TO 7
AD9850_DATA = DATA_2.BR
AD9850_W_CLK = 1 Delay_us(4)
AD9850_W_CLK = 0 Delay_us(4)
NEXT BR
FOR BR = 0 TO 7
AD9850_DATA = DATA_3.BR
AD9850_W_CLK = 1 Delay_us(4)
AD9850_W_CLK = 0 Delay_us(4)
NEXT BR
FOR BR = 0 TO 7
AD9850_DATA = DATA_4.BR
AD9850_W_CLK = 1 Delay_us(4)
AD9850_W_CLK = 0 Delay_us(4)
NEXT BR
AD9850_FQ_UD = 0 Delay_us(8)
AD9850_FQ_UD = 1
END SUB

DOWNLOADS CODE

http://www.libstock.com/projects/view/8 ... tor-module

Best regards radio amateurs, 73


S59KB

Potrebbero piacerti anche