Er is nog wel iets raars aan de hand:
Ik moet de reset van de PIC laag houden, pas dan blijft de AD9833 output leveren.
Gisteren werkte het toevallig, omdat ik geen pull-up aan de Reset had hangen...
Wat zit er hier dan fout?
'====================================================================================================
Program Signal
'====================================================================================================
Dim DDS_Value As LongInt 'Divider value for the AD9833Dim DDS_SYNC As sBit At PortB.0
DDS_CLK As sBit At LATB.1 'Change if needed
DDS_DATA As sBit At LATB.2 '
DDS_SYNC As sBit At LATB.3 '
DDS As Word 'DDS ctrl register. Bits used
DDS_Array As Byte[2] At DDS
Const DDS_Mode = 1 'in the AD9833 control register
DDS_Div2 = 3 '
DDS_OpBiten = 5 '
DDS_Sleep12 = 6 '
DDS_Sleep1 = 7 '
DDS_Reset = 8 '
DDS_PSelect = 10 '
DDS_FSelect = 11 '
DDS_HLB = 12 '
DDS_B28 = 13 '
DDS_Freq0 = 14 '
DDS_Freq1 = 15
'==================================================================================================
Sub Procedure ChangeBit(Dim pBitnr As Byte, Dim pValue As Byte)
'==================================================================================================
DDS_Array[pBitnr And 0x1000].(pBitnr And 0x0111) = pValue 'And 0x0111 = pValue
End Sub
'==================================================================================================
Sub Procedure SoftSpi_Write(Dim pVal As Word)
'==================================================================================================
Dim lCnt As Byte
DDS_SYNC = 1
DDS_CLK = 1
DDS_SYNC = 0
For lCnt = 0 to 15
DDS_DATA = (pVal >> lCnt) And 0x0001
DDS_CLK = 0
DDS_CLK = 1
Next lCnt
DDS_CLK = 0
DDS_SYNC = 1
End Sub
'==================================================================================================
Sub Procedure DDS_Init() 'Init the DDS chip
'==================================================================================================
DDS_SYNC = 0 'Select DDS chip (spi #1)
DDS = 0 'All Flags are '0'
ChangeBit(DDS_Reset, 1) '(except the reset flag)
SoftSpi_Write(DDS) '
ChangeBit(DDS_Reset, 0) '
SoftSpi_Write(DDS) '
DDS_SYNC = 1 'Disable chip
End Sub '
'==================================================================================================
Sub Procedure DDS_Set() 'Set value from DDS_Value into the DSS chip
'==================================================================================================
DDS_SYNC = 0 'Select DDS chip (spi #1)
SoftSpi_Write(0x2000) 'Set 2x14bits cmd mode
SoftSpi_Write((DDS_Value And 0x00003FFF) Or 0x4000) 'Low 14 bit word first
SoftSpi_Write((DDS_Value >> 14) Or 0x4000) 'Hi 14 bits
DDS_SYNC = 1 '
End Sub '
Main:
ANSELA = %00000000 'All Port A Digital
ANSELB = %00000000 'All Port B Digital
TRISA = %00100000 'Port A.5 input
TRISB = %00000000 'All Port B Output
OSCCON = %01111000 '16 MHz internal
DDS_INIT()
DDS_SET()
End.