|
|
 |
 |
|
$regfile = "m168def.dat" $crystal = 10000000 Dim Send As Word , Low_word As Word , High_word As Word , Freq As Long Dim Tmp As Single , Tmp_l As Single , Tmp_h As Single , Tmp1 As Single
'Starting frequency Freq = 3690000
' 2^28 / MCLK ( for 16MHz it is about 16.7772) Const Vak = 16.7772
'Ports´ directions and pull up Ddrb = &B00000111 Portb = &B00000111 Ddrd = &B10011111 Portd = &B11111111 'LCD ports Config Lcdpin = Pin , Db4 = Portb.2 , Db5 = Portb.1 , Db6 = Portb.0 , Db7 = Portd.7 , E = Portd.0 , Rs = Portd.1
'Subroutines Declare Sub Ser_out Declare Sub Up Declare Sub Dn Declare Sub Laske
'DDS ports Fsync Alias Portd.2 Sdata Alias Portd.4 Sclk Alias Portd.3
'DDS ports up Set Fsync Set Sclk Set Sdata
'Debounce time for frequency keys Config Debounce = 50
Main: 'Starting frequency and init values Cls Lcd "3.690000 Hz" Send = &H2100 Gosub Ser_out Send = &H639C Gosub Ser_out Send = &H4EC2 Gosub Ser_out Send = &HC000 Gosub Ser_out Send = &H2000 Gosub Ser_out 'Loop for check keys Do Debounce Pind.6 , 0 , Up , Sub Debounce Pind.5 , 0 , Dn , Sub Loop
End
' 'Send data ' Ser_out: Reset Fsync Shiftout Sdata , Sclk , Send , 0 Set Fsync Return ' 'Frequence up ' Up: Freq = Freq + 100 If Freq > 6000000 Then Freq = 6000000 End If Gosub Laske Return ' 'Frequence down ' Dn: Freq = Freq - 100 If Freq < 3500000 Then Freq = 3500000 End If Gosub Laske Return ' 'Count data for a dds ' Laske: Tmp1 = Freq * Vak Tmp_h = Tmp1 / 16384 High_word = Int(tmp_h) Tmp = High_word * 16384 Tmp_l = Tmp1 - Tmp Low_word = Int(tmp_l) Low_word.15 = 0 Low_word.14 = 1 Send = Low_word Gosub Ser_out High_word.15 = 0 High_word.14 = 1 Send = High_word Gosub Ser_out
'Show a frequency on a LCD Cls Waitms 10 Lcd Freq , ; " Hz" Waitms 10 Return
|
 |
 |
 |
 |
|
OHJELMA 2
Tein toisen ohjelman Atmega8 ja AD9833 Sekin tuntui toimiva. Mulla on siinä encoderi ja se pieni 2x12 merkkinen sininen näyttö. Lisäsin taajuusaskelluksen säädön, mutta sitä en kokeillut vielä. Tämäkin on tekstitiedostona ja ohjeita on siinä ohjelmassa. OP
|
|
|
Koodi 2
|
|
|
|
 |
 |
|
' 22/11/2010 ' A DDS control program for AD9833 and Atmega8. ' An encoder and LCD. ' There are some pins out of use so you can add switches, analogue inputs ' or use as outputs to control something else... ' By: Olavi Parkka ' OH6KWV ' $regfile = "m8def.dat" $crystal = 11980800 Dim Send As Word , Low_word As Word , High_word As Word , Freq As Long Dim Tmp As Single , Tmp_l As Single , Tmp_h As Single , Tmp1 As Single Dim B As Byte , Stp As Long
'Starting frequency and step
Freq = 3690000 Stp = 100
'Calculate 2^28 / MCLK ( for 22MHz it is about 12.2016)
Const Vak = 12.2016
'Ports directions and pull up
Ddrc = &B00000111 Portc = &B00000111 Ddrd = &B11100000 Portd = &B11111111
'LCD ports
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portd.7 , Db6 = Portd.6 , Db7 = Portd.5 , E = Portb.2 , Rs = Portb.1
'Subroutines
Declare Sub Ser_out Declare Sub Up Declare Sub Dn Declare Sub Laske Declare Sub Stp_up Declare Sub Stp_dn
Config Int0 = Falling
On Int0 Enc Enable Interrupts Enable Int0 ' 'Aliasis for DDS ports and set DDS ports ' Fsync Alias Portc.2 Sdata Alias Portc.0 Sclk Alias Portc.1
Set Fsync Set Sclk Set Sdata
Main: ' 'Starting frequency and init values. Freq_reg 0, Phase0 =0...and so on ' Cls Lcd "3690000 Hz" Send = &H2100 Gosub Ser_out Send = &H42A0 Gosub Ser_out Send = &H4ABC Gosub Ser_out Send = &HC000 Gosub Ser_out Send = &H2000 Gosub Ser_out ' 'Loop to check frequency_step_keys ' Do If Pind.0 = 0 Then Gosub Stp_up End If If Pind.1 = 0 Then Gosub Stp_dn End If Loop
End
' 'Send data ' Ser_out: Reset Fsync Shiftout Sdata , Sclk , Send , 0 Set Fsync Return ' 'Frequency up ' Up: Freq = Freq + Stp If Freq > 6000000 Then Freq = 6000000 End If
Gosub Laske Return ' 'Frequency down ' Dn: Freq = Freq - Stp If Freq < 3500000 Then Freq = 3500000 End If Gosub Laske Return ' 'Count data for a dds ' Laske: Tmp1 = Freq * Vak Tmp_h = Tmp1 / 16384 High_word = Int(tmp_h) Tmp = High_word * 16384 Tmp_l = Tmp1 - Tmp Low_word = Int(tmp_l) Low_word.15 = 0 Low_word.14 = 1 Send = Low_word Gosub Ser_out High_word.15 = 0 High_word.14 = 1 Send = High_word Gosub Ser_out
'Show a frequency on a LCD Cls Waitms 10 Lcd Freq ; " Hz" Lowerline Lcd Stp ; " Hz" Waitms 10 Return ' 'Encoder routine. An encoder is connected to pins PD2,PD3 and PD4. 'PD2 and PD3 are together, so if you want more speed to your encoder take 'another interrupts INT1 to use. Enc: Disable Int0 Disable Interrupts
If Pind.2 = 0 Then If Pind.4 = 0 Then Gosub Dn End If End If If Pind.2 = 0 Then If Pind.4 = 1 Then
Gosub Up End If End If Enable Interrupts Enable Int0
Return ' 'A freguency_step up ' Stp_up: Stp = Stp * 10 If Stp > 1000000 Then Stp = 1000000 End If Return ' 'A freguency_step down ' Stp_dn: Stp = Stp \ 10 If Stp < 10 Then Stp = 10 End If Return
|
|
|
|