Пн окт 15, 2018 14:03:15
Procedure Clock();
begin
SoftSPI_CLK := 0; delay_us(1);
SoftSPI_CLK := 1; delay_us(1);
end;
// Отправка 16 бит по SPI
Procedure SPI_Out(var s:word);
begin
Chip_Select := 0;
delay_us(1);
SoftSPI_CLK := 1;
delay_us(1);
SoftSPI_SDO := s.15; Clock;
SoftSPI_SDO := s.14; Clock;
SoftSPI_SDO := s.13; Clock;
SoftSPI_SDO := s.12; Clock;
SoftSPI_SDO := s.11; Clock;
SoftSPI_SDO := s.10; Clock;
SoftSPI_SDO := s.9; Clock;
SoftSPI_SDO := s.8; Clock;
SoftSPI_SDO := s.7; Clock;
SoftSPI_SDO := s.6; Clock;
SoftSPI_SDO := s.5; Clock;
SoftSPI_SDO := s.4; Clock;
SoftSPI_SDO := s.3; Clock;
SoftSPI_SDO := s.2; Clock;
SoftSPI_SDO := s.1; Clock;
SoftSPI_SDO := s.0; Clock;
SoftSPI_CLK := 1;
delay_us(1);
Chip_Select := 1;
delay_us(1);
end;
// Изменяем частоту
procedure Send_freq(var freq:DWord; var reg: byte);
var temp_MSB, temp_LSB: Word;
begin
if reg = 0 then // FREQ0
begin
temp_LSB := LoWord(freq); // adjust with 01
temp_MSB := HiWord(freq shl 2); // adjust with 01
temp_LSB := (temp_LSB and $3FFF) or $4000;
temp_MSB := (temp_MSB and $3FFF) or $4000;
SPI_Out(temp_LSB);
SPI_Out(temp_MSB);
end;
if reg = 1 then // FREQ1
begin
temp_LSB := LoWord(freq); // adjust with 10
temp_MSB := HiWord(freq shl 2); // adjust with 10
temp_LSB := (temp_LSB and $3FFF) or $8000;
temp_MSB := (temp_MSB and $3FFF) or $8000;
SPI_Out(temp_LSB);
SPI_Out(temp_MSB);
end;
end;
// Инициализация AD9837
procedure InitSintezator();
var f_sortie: Dword;
freq0, Phase0: Dword;
begin
//init registers
CONTROL_REGISTER:=0x2060;
SPI_Out(CONTROL_REGISTER);
delay_ms(5);
f_sortie := 10000;
ref := 0;
Send_freq(freq0,ref); //первый регистр частоты
delay_ms(10);
ref := 1;
freq0 := 0;
Send_freq(freq0,ref); // второй регистр частоты
delay_ms(5);
Phase0 := 0xC000;
SPI_Out(phase0); // первый регистр фазы
delay_ms(5);
Phase0 := 0xE000; // второй регистр фазы
SPI_Out(phase0);
delay_ms(5);
CONTROL_REGISTER:=0x2060;
SPI_Out(CONTROL_REGISTER);
delay_ms(20);
end;
Ср окт 24, 2018 09:03:00