init commit
This commit is contained in:
5
lc-meter-stm32-arduino/.gitignore
vendored
Normal file
5
lc-meter-stm32-arduino/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
10
lc-meter-stm32-arduino/.vscode/extensions.json
vendored
Normal file
10
lc-meter-stm32-arduino/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
5
lc-meter-stm32-arduino/.vscode/settings.json
vendored
Normal file
5
lc-meter-stm32-arduino/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.cpp3": "cpp"
|
||||
}
|
||||
}
|
||||
BIN
lc-meter-stm32-arduino/AD9951.pdf
Normal file
BIN
lc-meter-stm32-arduino/AD9951.pdf
Normal file
Binary file not shown.
37
lc-meter-stm32-arduino/include/README
Normal file
37
lc-meter-stm32-arduino/include/README
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the convention is to give header files names that end with `.h'.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
46
lc-meter-stm32-arduino/lib/README
Normal file
46
lc-meter-stm32-arduino/lib/README
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into the executable file.
|
||||
|
||||
The source code of each library should be placed in a separate directory
|
||||
("lib/your_library_name/[Code]").
|
||||
|
||||
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
Example contents of `src/main.c` using Foo and Bar:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries by scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
62
lc-meter-stm32-arduino/platformio.ini
Normal file
62
lc-meter-stm32-arduino/platformio.ini
Normal file
@@ -0,0 +1,62 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
;[env:bluepill_f103c8]
|
||||
;platform = ststm32
|
||||
;board = bluepill_f103c8
|
||||
;framework = arduino
|
||||
;upload_protocol = stlink
|
||||
;debug_tool = stlink
|
||||
;monitor_speed = 115200
|
||||
|
||||
[env:bluepill_f103c8]
|
||||
platform = ststm32
|
||||
board = bluepill_f103c8
|
||||
framework = arduino
|
||||
|
||||
|
||||
# Ключевая настройка: используем протокол HID
|
||||
upload_protocol = hid
|
||||
# Важные флаги для работы USB CDC (виртуального COM-порта)
|
||||
build_flags =
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
-D PIO_FRAMEWORK_ARDUINO_ENABLE_HID ; Может потребоваться
|
||||
-D USBCON
|
||||
-D USBD_VID=0x0483
|
||||
-D USBD_PID=0x5740
|
||||
-D USB_MANUFACTURER="Unknown"
|
||||
-D USB_PRODUCT="BLUEPILL_XAH"
|
||||
|
||||
;upload_port = \\.\HID\VID_1209&PID_BEBA
|
||||
|
||||
; Включение USB Serial (CDC)
|
||||
;build_flags =
|
||||
; -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
|
||||
; -D USBCON
|
||||
; -D USBD_VID=0x0483
|
||||
; -D USBD_PID=0x5740
|
||||
; -D USB_MANUFACTURER="Unknown"
|
||||
; -D USB_PRODUCT="BLUEPILL_XAH"
|
||||
; -D HAL_PCD_MODULE_ENABLED
|
||||
|
||||
; Важно для работы Serial Monitor в PlatformIO
|
||||
monitor_dtr = 1
|
||||
|
||||
;board_build.core = maple
|
||||
; Change microcontroller
|
||||
board_build.mcu = stm32f103c8t6
|
||||
; Change MCU frequency
|
||||
board_build.f_cpu = 72000000L
|
||||
; may be needed for the first code download
|
||||
;board_upload.require_upload_port = no
|
||||
;board_upload.use_1200bps_touch = no
|
||||
;upload_protocol = dfu
|
||||
monitor_speed = 115200
|
||||
monitor_encoding = utf-8
|
||||
302
lc-meter-stm32-arduino/src/main.cpp
Normal file
302
lc-meter-stm32-arduino/src/main.cpp
Normal file
@@ -0,0 +1,302 @@
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define PIN_ADC A6
|
||||
|
||||
#define AD9951_RESET PB1
|
||||
#define AD9951_IO_UPDATE PB10
|
||||
|
||||
const float MAX_FREQUENCY = 400e6; // Максимальная частота (400 МГц)
|
||||
// Частота системного генератора (без PLL)
|
||||
#define SYSTEM_CLOCK 100e6 // 100 МГц
|
||||
|
||||
void resetAD9951()
|
||||
{
|
||||
digitalWrite(AD9951_RESET, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(AD9951_RESET, LOW);
|
||||
}
|
||||
|
||||
// Функция для записи в регистр AD9951
|
||||
void writeAD9951Register(byte address, byte data[], byte numBytes)
|
||||
{
|
||||
// digitalWrite(AD9951_CS, LOW);
|
||||
SPI.transfer(address); // Отправляем адрес регистра
|
||||
for (byte i = 0; i < numBytes; i++)
|
||||
{
|
||||
SPI.transfer(data[i]); // Отправляем данные
|
||||
}
|
||||
// digitalWrite(AD9951_CS, HIGH);
|
||||
|
||||
// Обновление вывода
|
||||
digitalWrite(AD9951_IO_UPDATE, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(AD9951_IO_UPDATE, LOW);
|
||||
}
|
||||
|
||||
// Функция для настройки частоты
|
||||
void setFrequency(double frequency)
|
||||
{
|
||||
// Рассчитываем значение для регистра частоты (32 бита)
|
||||
// unsigned long freqWord = (unsigned long)((frequency * pow(2, 32)) / (SYSTEM_CLOCK * 4));
|
||||
|
||||
// Clock rate = 100MHz
|
||||
// unsigned long freqWord = (unsigned long)frequency * 42.94967296;
|
||||
|
||||
// Clock rate = 400MHz
|
||||
unsigned long freqWord = (unsigned long)frequency * 10.73741824;
|
||||
|
||||
byte freqData[4];
|
||||
freqData[0] = (freqWord >> 24) & 0xFF; // MSB
|
||||
freqData[1] = (freqWord >> 16) & 0xFF;
|
||||
freqData[2] = (freqWord >> 8) & 0xFF;
|
||||
freqData[3] = freqWord & 0xFF; // LSB
|
||||
|
||||
// Отправка регистра частоты
|
||||
// SPI.transfer((frequencyWord >> 24) & 0xFF); // MSB
|
||||
// SPI.transfer((frequencyWord >> 16) & 0xFF);
|
||||
// SPI.transfer((frequencyWord >> 8) & 0xFF);
|
||||
// SPI.transfer(frequencyWord & 0xFF); // LSB
|
||||
|
||||
writeAD9951Register(0x04, freqData, 4); // Запись в регистр частоты (CFR)
|
||||
}
|
||||
|
||||
// Функция для настройки амплитуды (0-1023 соответствует 0-полная амплитуда)
|
||||
void setAmplitude(unsigned int amplitude)
|
||||
{
|
||||
if (amplitude > 1023)
|
||||
amplitude = 1023;
|
||||
|
||||
byte ampData[2];
|
||||
ampData[0] = (amplitude >> 8) & 0x03; // Только 2 младших бита
|
||||
ampData[1] = amplitude & 0xFF;
|
||||
|
||||
writeAD9951Register(0x03, ampData, 2); // Запись в регистр амплитуды (ACR)
|
||||
}
|
||||
|
||||
// Функция для настройки PLL (множитель 4)
|
||||
// Функция для настройки PLL (множитель 4)
|
||||
void configurePLL()
|
||||
{
|
||||
byte cfr1Data[2];
|
||||
// CFR1: PLL множитель 4 (биты D7-D4 = 0011)
|
||||
cfr1Data[0] = 0x00; // PLL=4x, VCO gain=high (бит D3=0)
|
||||
cfr1Data[1] = 0x30; // 0011 в старших битах для PLL=4x
|
||||
|
||||
writeAD9951Register(0x01, cfr1Data, 2);
|
||||
}
|
||||
|
||||
/********************************************************************************************* */
|
||||
// void RESET2()
|
||||
// {
|
||||
// digitalWrite(AD9951_RESET, HIGH);
|
||||
// delayMicroseconds(10);
|
||||
// digitalWrite(AD9951_RESET, LOW);
|
||||
// }
|
||||
|
||||
uint32_t multiplier = 4;
|
||||
|
||||
void CONFIG()
|
||||
{ // Множитель от 4 до 20
|
||||
uint32_t cfr1_value = (multiplier - 4) << 4; // Сдвиг битов для D7-D4
|
||||
// spi_send_byte(0x24);// 0x04 << 3
|
||||
|
||||
// CS_LOW();
|
||||
|
||||
SPI.transfer(0x01);
|
||||
|
||||
// SPI.transfer(cfr1_value);
|
||||
SPI.transfer(0);
|
||||
SPI.transfer(0);
|
||||
SPI.transfer(0x24); // Младший байт
|
||||
|
||||
// CS_HIGH();
|
||||
|
||||
// Обновить регистры (IO_UPDATE)
|
||||
digitalWrite(AD9951_IO_UPDATE, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(AD9951_IO_UPDATE, LOW);
|
||||
}
|
||||
|
||||
void setFrequency2(unsigned long ftw)
|
||||
{
|
||||
// Активировать выбор микросхемы
|
||||
// CS_LOW();
|
||||
|
||||
// Передать адрес регистра FTW (0x04)
|
||||
SPI.transfer(0x04);
|
||||
|
||||
// Передать 32-битное значение FTW
|
||||
SPI.transfer((ftw >> 24) & 0xFF); // Старший байт
|
||||
SPI.transfer((ftw >> 16) & 0xFF);
|
||||
SPI.transfer((ftw >> 8) & 0xFF);
|
||||
SPI.transfer(ftw & 0xFF); // Младший байт
|
||||
|
||||
// Деактивировать выбор микросхемы
|
||||
// CS_HIGH();
|
||||
|
||||
// Обновить регистры (IO_UPDATE)
|
||||
digitalWrite(AD9951_IO_UPDATE, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(AD9951_IO_UPDATE, LOW);
|
||||
}
|
||||
/********************************************************************************************* */
|
||||
|
||||
// void setPLLMultiplier(byte multiplier)
|
||||
// {
|
||||
// byte cfr1Data[3] = {0};
|
||||
|
||||
// // Установка множителя PLL (биты D7-D4 регистра CFR1)
|
||||
// switch (multiplier)
|
||||
// {
|
||||
// case 1:
|
||||
// cfr1Data[2] = 0x00; // 0000
|
||||
// break;
|
||||
// case 2:
|
||||
// cfr1Data[2] = 0x10; // 0001
|
||||
// break;
|
||||
// case 4:
|
||||
// cfr1Data[2] = 0x30; // 0011 (для 4x)
|
||||
// break;
|
||||
// case 8:
|
||||
// cfr1Data[2] = 0x50; // 0101
|
||||
// break;
|
||||
// case 16:
|
||||
// cfr1Data[2] = 0x70; // 0111
|
||||
// break;
|
||||
// case 20:
|
||||
// cfr1Data[2] = 0x90; // 1001
|
||||
// break;
|
||||
// default:
|
||||
// cfr1Data[2] = 0x30; // по умолчанию 4x
|
||||
// }
|
||||
|
||||
// // Дополнительные настройки CFR1:
|
||||
// cfr1Data[0] |= 0x00; // VCO gain (0 = high, 1 = low)
|
||||
// cfr1Data[2] |= 0x01; // PLL enabled (бит D0)
|
||||
|
||||
// writeAD9951Register(0x01, cfr1Data, 3); // Адрес CFR1 = 0x01
|
||||
// }
|
||||
void setPLLMultiplier(byte multiplier)
|
||||
{
|
||||
byte cfr1Data[3] = {0};
|
||||
|
||||
// Правильная настройка PLL множителя (биты D7-D4)
|
||||
switch (multiplier)
|
||||
{
|
||||
case 1:
|
||||
cfr1Data[0] = 0x00; // PLL bypass (0x0)
|
||||
cfr1Data[2] = 0x00; // PLL disabled
|
||||
break;
|
||||
case 2:
|
||||
cfr1Data[0] = 0x00; // VCO gain high
|
||||
cfr1Data[2] = 0x11; // 0001 (2x) + PLL enabled
|
||||
break;
|
||||
case 4:
|
||||
cfr1Data[0] = 0x00; // VCO gain high
|
||||
cfr1Data[2] = 0x31; // 0011 (4x) + PLL enabled
|
||||
break;
|
||||
case 8:
|
||||
cfr1Data[0] = 0x00; // VCO gain high
|
||||
cfr1Data[2] = 0x51; // 0101 (8x) + PLL enabled
|
||||
break;
|
||||
case 16:
|
||||
cfr1Data[0] = 0x00; // VCO gain high
|
||||
cfr1Data[2] = 0x71; // 0111 (16x) + PLL enabled
|
||||
break;
|
||||
case 20:
|
||||
cfr1Data[0] = 0x00; // VCO gain high
|
||||
cfr1Data[2] = 0x91; // 1001 (20x) + PLL enabled
|
||||
break;
|
||||
default:
|
||||
cfr1Data[0] = 0x00; // по умолчанию 4x
|
||||
cfr1Data[2] = 0x31; // 0011 (4x) + PLL enabled
|
||||
}
|
||||
|
||||
writeAD9951Register(0x01, cfr1Data, 3); // Адрес CFR1 = 0x01
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(500);
|
||||
Serial.begin(115200); // Инициализация последовательного порта
|
||||
while (!Serial)
|
||||
{
|
||||
// yield;
|
||||
}
|
||||
Serial.println("");
|
||||
Serial.println("hello");
|
||||
|
||||
delay(500);
|
||||
return;
|
||||
|
||||
// pinMode(CS_PIN, OUTPUT);
|
||||
pinMode(AD9951_RESET, OUTPUT);
|
||||
pinMode(AD9951_IO_UPDATE, OUTPUT);
|
||||
// digitalWrite(CS_PIN, HIGH);
|
||||
|
||||
// Инициализация SPI
|
||||
SPI.begin();
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0); // !!!!!!!
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV32);
|
||||
|
||||
delay(500);
|
||||
/***********************************************************************************/
|
||||
|
||||
resetAD9951();
|
||||
CONFIG();
|
||||
// setPLLMultiplier(4);
|
||||
setFrequency(10e6);
|
||||
|
||||
// setAmplitude(1023);
|
||||
|
||||
return;
|
||||
|
||||
// Сброс AD9951
|
||||
resetAD9951();
|
||||
delay(100);
|
||||
|
||||
// Настройка PLL (множитель 4)
|
||||
configurePLL();
|
||||
delay(100);
|
||||
|
||||
// Настройка частоты (например, 10 МГц)
|
||||
setFrequency(10e6);
|
||||
delay(100);
|
||||
|
||||
// Настройка амплитуды (максимальная)
|
||||
// setAmplitude(1023);
|
||||
|
||||
// // Обновление вывода
|
||||
// digitalWrite(AD9951_IO_UPDATE, HIGH);
|
||||
// delay(1);
|
||||
// digitalWrite(AD9951_IO_UPDATE, LOW);
|
||||
|
||||
Serial.println("ready");
|
||||
}
|
||||
|
||||
int cnt = 0;
|
||||
void loop()
|
||||
{
|
||||
Serial.println(cnt++);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
void loop2()
|
||||
{
|
||||
if (Serial.available() > 0)
|
||||
{
|
||||
long frequency = Serial.parseInt(); // Чтение частоты из UART
|
||||
if (frequency > 0 && frequency <= MAX_FREQUENCY)
|
||||
{
|
||||
setFrequency(frequency);
|
||||
Serial.print("Frequency set to: ");
|
||||
Serial.println(frequency);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Invalid frequency. Please enter a value between 0 and 400000000.");
|
||||
}
|
||||
}
|
||||
}
|
||||
95
lc-meter-stm32-arduino/src/main.cpp2
Normal file
95
lc-meter-stm32-arduino/src/main.cpp2
Normal file
@@ -0,0 +1,95 @@
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
// #include "main.h"
|
||||
|
||||
// Определение пинов
|
||||
// const int CS_PIN = 4; // Chip Select !!!!!!
|
||||
const int IO_UPDATE_PIN = PB10; // IO_UPDATE
|
||||
const int RESET_PIN = PB1; // RESET
|
||||
|
||||
// Настройки
|
||||
const long REF_CLOCK = 100e6; // Частота опорного генератора (100 MГц)
|
||||
|
||||
void resetAD9951();
|
||||
void setFrequency(long frequency);
|
||||
void writeRegister(uint8_t registerAddress, uint8_t data);
|
||||
void configureAD9951();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200); // Инициализация последовательного порта
|
||||
// pinMode(CS_PIN, OUTPUT);
|
||||
pinMode(IO_UPDATE_PIN, OUTPUT);
|
||||
pinMode(RESET_PIN, OUTPUT);
|
||||
|
||||
// digitalWrite(CS_PIN, HIGH);
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
|
||||
SPI.begin(); // Инициализация SPI
|
||||
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); // Настройки SPI
|
||||
|
||||
// Сброс AD9951
|
||||
resetAD9951();
|
||||
|
||||
// Конфигурация AD9951
|
||||
configureAD9951();
|
||||
|
||||
// Установка начальной частоты
|
||||
setFrequency(10e6); // Установка частоты 10 МГц
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Основной цикл
|
||||
}
|
||||
|
||||
void resetAD9951()
|
||||
{
|
||||
digitalWrite(RESET_PIN, LOW); // Установить RESET в LOW
|
||||
delay(10); // Задержка для сброса
|
||||
digitalWrite(RESET_PIN, HIGH); // Установить RESET в HIGH
|
||||
}
|
||||
|
||||
void configureAD9951()
|
||||
{
|
||||
// Конфигурация регистра управления (Control Register)
|
||||
uint8_t controlRegister = 0b00000000; // Пример настройки
|
||||
// Настройте биты в зависимости от ваших требований
|
||||
// Например, включение синхронизации, выбор режима работы и т.д.
|
||||
|
||||
writeRegister(0x00, controlRegister); // Запись в Control Register
|
||||
}
|
||||
|
||||
void setFrequency(long frequency)
|
||||
{
|
||||
// Расчет значения для AD9951
|
||||
unsigned long frequencyWord = (unsigned long)((double)frequency / REF_CLOCK * (1 << 32));
|
||||
|
||||
// Отправка данных в AD9951
|
||||
// digitalWrite(CS_PIN, LOW);
|
||||
|
||||
// Отправка регистра частоты
|
||||
SPI.transfer((frequencyWord >> 24) & 0xFF); // MSB
|
||||
SPI.transfer((frequencyWord >> 16) & 0xFF);
|
||||
SPI.transfer((frequencyWord >> 8) & 0xFF);
|
||||
SPI.transfer(frequencyWord & 0xFF); // LSB
|
||||
|
||||
// digitalWrite(CS_PIN, HIGH);
|
||||
|
||||
// Обновление
|
||||
digitalWrite(IO_UPDATE_PIN, LOW);
|
||||
digitalWrite(IO_UPDATE_PIN, HIGH);
|
||||
}
|
||||
|
||||
void writeRegister(uint8_t registerAddress, uint8_t data)
|
||||
{
|
||||
// digitalWrite(CS_PIN, LOW);
|
||||
|
||||
// Запись адреса регистра
|
||||
SPI.transfer(registerAddress);
|
||||
|
||||
// Запись данных
|
||||
SPI.transfer(data);
|
||||
|
||||
// digitalWrite(CS_PIN, HIGH);
|
||||
}
|
||||
253
lc-meter-stm32-arduino/src/main.cpp3
Normal file
253
lc-meter-stm32-arduino/src/main.cpp3
Normal file
@@ -0,0 +1,253 @@
|
||||
#include <Arduino.h>
|
||||
// #include <EEPROM.h>
|
||||
#include <SPI.h>
|
||||
// #include "utils.h"
|
||||
// #include "GyverPWM.h"
|
||||
|
||||
// #define PIN_PWM PB1
|
||||
#define PIN_ADC A6
|
||||
|
||||
const unsigned int oreset = PB1; // PD3 // 43;
|
||||
const unsigned int ioupdate = PB10; // A3; // PC3 // 11;
|
||||
// const unsigned int cs = 4; // PD4 // 41;
|
||||
|
||||
unsigned long quartz = 0;
|
||||
float rate = 1;
|
||||
|
||||
// void setPwm(int currentPwm);
|
||||
|
||||
void RESET2()
|
||||
{
|
||||
digitalWrite(oreset, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(oreset, LOW);
|
||||
}
|
||||
|
||||
void CS_LOW()
|
||||
{
|
||||
// digitalWrite(cs, LOW);
|
||||
}
|
||||
void CS_HIGH()
|
||||
{
|
||||
// digitalWrite(cs, HIGH);
|
||||
}
|
||||
void IO_UPDATE_LOW()
|
||||
{
|
||||
digitalWrite(ioupdate, LOW);
|
||||
}
|
||||
void IO_UPDATE_HIGH()
|
||||
{
|
||||
digitalWrite(ioupdate, HIGH);
|
||||
}
|
||||
|
||||
void setFrequency(unsigned long ftw)
|
||||
{
|
||||
// Активировать выбор микросхемы
|
||||
CS_LOW();
|
||||
|
||||
// Передать адрес регистра FTW (0x04)
|
||||
SPI.transfer(0x04);
|
||||
|
||||
// Передать 32-битное значение FTW
|
||||
SPI.transfer((ftw >> 24) & 0xFF); // Старший байт
|
||||
SPI.transfer((ftw >> 16) & 0xFF);
|
||||
SPI.transfer((ftw >> 8) & 0xFF);
|
||||
SPI.transfer(ftw & 0xFF); // Младший байт
|
||||
|
||||
// Деактивировать выбор микросхемы
|
||||
CS_HIGH();
|
||||
|
||||
// Обновить регистры (IO_UPDATE)
|
||||
IO_UPDATE_HIGH();
|
||||
delayMicroseconds(1);
|
||||
IO_UPDATE_LOW();
|
||||
}
|
||||
|
||||
void CONFIG()
|
||||
{
|
||||
uint32_t multiplier = 10; // Множитель от 4 до 20
|
||||
uint32_t cfr1_value = (multiplier - 4) << 4; // Сдвиг битов для D7-D4
|
||||
|
||||
CS_LOW();
|
||||
|
||||
SPI.transfer(0x01);
|
||||
|
||||
SPI.transfer(cfr1_value);
|
||||
SPI.transfer(0);
|
||||
SPI.transfer(0); // Младший байт
|
||||
|
||||
CS_HIGH();
|
||||
|
||||
// Обновить регистры (IO_UPDATE)
|
||||
IO_UPDATE_HIGH();
|
||||
delayMicroseconds(1);
|
||||
IO_UPDATE_LOW();
|
||||
}
|
||||
|
||||
// Функция для расчета FTW (Frequency Tuning Word)
|
||||
uint32_t calculateFTW(float frequency, float refClock)
|
||||
{
|
||||
return (uint32_t)((frequency / refClock) * 4294967296UL); // 2^32
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("");
|
||||
Serial.println("hello");
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
// pinMode(PIN_PWM, OUTPUT);
|
||||
pinMode(PIN_ADC, INPUT);
|
||||
|
||||
pinMode(oreset, OUTPUT); // RESET
|
||||
digitalWrite(oreset, LOW);
|
||||
|
||||
pinMode(ioupdate, OUTPUT); // IO_UPDATE
|
||||
digitalWrite(ioupdate, LOW);
|
||||
|
||||
// pinMode(cs, OUTPUT); // CS
|
||||
// digitalWrite(cs, HIGH);
|
||||
|
||||
// PWM_frequency(3, 10000, FAST_PWM);
|
||||
// setPwm(50);
|
||||
|
||||
SPI.begin();
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0); // !!!!!!!
|
||||
SPI.setClockDivider(SPI_CLOCK_DIV32);
|
||||
|
||||
Serial.println("start");
|
||||
|
||||
// EEPROM.get(0, quartz);
|
||||
// Serial.print("quartz :: ");
|
||||
// Serial.println(quartz);
|
||||
// rate = 4294967296.0 / quartz;
|
||||
// Serial.print("rate :: ");
|
||||
// Serial.println(rate);
|
||||
|
||||
delay(500);
|
||||
|
||||
RESET2();
|
||||
delay(100);
|
||||
CONFIG();
|
||||
|
||||
delay(100);
|
||||
|
||||
float frequency = 20e6;
|
||||
float refClock = 100e6; // Опорная частота (100 МГц)
|
||||
uint32_t ftw = calculateFTW(frequency, refClock);
|
||||
// setFrequency(ftw);
|
||||
}
|
||||
|
||||
int getAdc()
|
||||
{
|
||||
int val = analogRead(PIN_ADC);
|
||||
return val;
|
||||
}
|
||||
|
||||
// void setPwm(int currentPwm)
|
||||
// {
|
||||
// long level = map(currentPwm, 0, 100, 0, 255);
|
||||
// PWM_set(3, level);
|
||||
// }
|
||||
|
||||
// void pool()
|
||||
// {
|
||||
|
||||
// if (Serial.available())
|
||||
// {
|
||||
// String cmd = Serial.readString();
|
||||
|
||||
// // $$|sr|10000|150000|500|50
|
||||
// if (cmd.startsWith(F("$$|sr")))
|
||||
// {
|
||||
// // $$|sr|start|stop|step|pwm|
|
||||
// unsigned long start = (splitString(cmd, '|', 2)).toInt();
|
||||
// unsigned long stop = (splitString(cmd, '|', 3)).toInt();
|
||||
// unsigned long step = (splitString(cmd, '|', 4)).toInt();
|
||||
// unsigned int pwm = (splitString(cmd, '|', 5)).toInt();
|
||||
|
||||
// setPwm(pwm);
|
||||
// // speedrun(start, stop, step); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
// }
|
||||
// if (cmd.startsWith(F("set q="))) // сохраняем частоту кварца
|
||||
// {
|
||||
// String _intStr = cmd.substring(cmd.indexOf("=") + 1, cmd.length());
|
||||
// unsigned long quartz = _intStr.toInt() * 1000 * 1000;
|
||||
// EEPROM.put(0, quartz);
|
||||
// delay(10);
|
||||
// EEPROM.get(0, quartz);
|
||||
// Serial.print("quartz :: ");
|
||||
// Serial.println(quartz);
|
||||
// rate = 4294967296.0 / quartz;
|
||||
// Serial.print("rate :: ");
|
||||
// Serial.println(rate);
|
||||
// }
|
||||
// if (cmd.startsWith(F("set f="))) // установить частоту
|
||||
// {
|
||||
// unsigned long freq = 0;
|
||||
// String _intStr = cmd.substring(cmd.indexOf("=") + 1, cmd.length());
|
||||
// if (_intStr == "R")
|
||||
// {
|
||||
// // for (byte i = 0; i <= 80; i += 10)
|
||||
// for (unsigned long i = 100000; i <= 2500000; i += 10000)
|
||||
// {
|
||||
// // freq = 10000 + i;
|
||||
// // setF(freq * 1000);
|
||||
// setF(i);
|
||||
// delay(500);
|
||||
// }
|
||||
// setF(2500000);
|
||||
// // setF(5000000);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// freq = _intStr.toInt();
|
||||
// setF(freq * 1000);
|
||||
// }
|
||||
// if (cmd.startsWith(F("set p="))) // установить ШИМ
|
||||
// {
|
||||
// String _intStr = cmd.substring(cmd.indexOf("=") + 1, cmd.length());
|
||||
// int pwm = _intStr.toInt();
|
||||
// setPwm(pwm);
|
||||
// Serial.println("pwm :: " + (String)pwm + "%");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
float refClock = 100e6; // Опорная частота (100 МГц)
|
||||
|
||||
void loop()
|
||||
{
|
||||
// RESET2();
|
||||
// CONFIG();
|
||||
|
||||
// uint32_t ftw = calculateFTW(10 * 1e6, refClock);
|
||||
// setFrequency(ftw);
|
||||
|
||||
// return;
|
||||
|
||||
int i = 0;
|
||||
for (i = 5; i <= 50; i += 5)
|
||||
{
|
||||
// delay(2500);
|
||||
float frequency = i * 1e6;
|
||||
uint32_t ftw = calculateFTW(frequency, refClock);
|
||||
RESET2();
|
||||
CONFIG();
|
||||
// delay(100);
|
||||
setFrequency(ftw);
|
||||
Serial.print("F = ");
|
||||
Serial.println(i);
|
||||
delay(5000);
|
||||
|
||||
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
|
||||
}
|
||||
// pool();
|
||||
|
||||
// delay(500);
|
||||
// digitalWrite(LED_BUILTIN, LOW);
|
||||
// delay(500);
|
||||
// digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
5
lc-meter-stm32-arduino/src/main.h
Normal file
5
lc-meter-stm32-arduino/src/main.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
void resetAD9951();
|
||||
void setFrequency(long frequency);
|
||||
void writeRegister(uint8_t registerAddress, uint8_t data);
|
||||
196761
lc-meter-stm32-arduino/temp/INI/Autosave.mbm
Normal file
196761
lc-meter-stm32-arduino/temp/INI/Autosave.mbm
Normal file
File diff suppressed because it is too large
Load Diff
524296
lc-meter-stm32-arduino/temp/INI/Autosave.mbs
Normal file
524296
lc-meter-stm32-arduino/temp/INI/Autosave.mbs
Normal file
File diff suppressed because it is too large
Load Diff
BIN
lc-meter-stm32-arduino/temp/INI/ColorsDPPB.col
Normal file
BIN
lc-meter-stm32-arduino/temp/INI/ColorsDPPB.col
Normal file
Binary file not shown.
266
lc-meter-stm32-arduino/temp/INI/tbk.ini
Normal file
266
lc-meter-stm32-arduino/temp/INI/tbk.ini
Normal file
@@ -0,0 +1,266 @@
|
||||
[Form1]
|
||||
Edit1Text=
|
||||
sRadioButton1=0
|
||||
sRadioButton2=1
|
||||
sRadioButton3=1
|
||||
sRadioButton4=0
|
||||
sRadioButton5=1
|
||||
sRadioButton6=0
|
||||
sComboBox1ItIn=10
|
||||
sComboBox2ItIn=1
|
||||
sComboBox3ItIn=6
|
||||
sComboBox5ItIn=0
|
||||
sComboBox6ItIn=2
|
||||
sComboBox7ItIn=2
|
||||
sChBox1=1
|
||||
sChBox2=0
|
||||
sChBox3=0
|
||||
sChBox4=0
|
||||
sChBox6=1
|
||||
sChBox12=1
|
||||
sChBox13=0
|
||||
sChBox14=0
|
||||
sChBox15=1
|
||||
sChBox16=0
|
||||
sChBox17=0
|
||||
sChBox18=0
|
||||
sChBox19=0
|
||||
sChBox20=0
|
||||
sChBox21=0
|
||||
sChBox22=0
|
||||
N32=0
|
||||
N36=0
|
||||
N37=1
|
||||
SG7TopRow=1
|
||||
SG7_ColWidths_1=220
|
||||
SG7_ColWidths_2=700
|
||||
M.Name=MS Sans Serif
|
||||
M.Color=0
|
||||
M.Size=8
|
||||
M.Bold=0
|
||||
M.Italic=0
|
||||
LOG_filename=
|
||||
PTF_DLRB=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\DLRB
|
||||
PTF_STRINGS=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\STRINGS
|
||||
PTF_PROGRAMS=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\PROGRAMS
|
||||
PTF_LOG=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\LOG
|
||||
PTF_SAVE=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\SAVE
|
||||
PTF_AUTOSAVE=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\AUTOSAVE
|
||||
PTF_SendFile=
|
||||
FN_TableMacros=d:\_!_prj\XAH\lc-meter-stm32-arduino\temp\MACROS\Default.mcs
|
||||
NbCOMA=8
|
||||
NbCOMB=8
|
||||
NomCOMA=5
|
||||
NomCOMB=0
|
||||
VidOformSave=1
|
||||
KolSimvOtstupaSave=10
|
||||
SimvolOtstupaSave=9
|
||||
VidOformASave=1
|
||||
KolSimvOtstupaASave=40
|
||||
SimvolOtstupaASave=32
|
||||
VidOformLOG=1
|
||||
KolSimvOtstupaLOG=40
|
||||
SimvolOtstupaLOG=32
|
||||
Timer3_TOcomA=100000
|
||||
Timer3_TOcomB=100000
|
||||
bigTimer3_TOcomA=1000000
|
||||
bigTimer3_TOcomB=1000000
|
||||
ColorSelect=12500735
|
||||
SG1_width=707
|
||||
SG2_width=5
|
||||
SG3_width=5
|
||||
SG4_width=693
|
||||
SG5_width=5
|
||||
SG6_width=5
|
||||
M1_width=59
|
||||
M2_width=59
|
||||
M3_width=59
|
||||
M4_width=59
|
||||
M5_width=59
|
||||
M6_width=59
|
||||
Form1_Maximized=0
|
||||
Form1_Left=268
|
||||
Form1_Top=171
|
||||
Form1_Width=1418
|
||||
Form1_Height=739
|
||||
[Form6]
|
||||
RadioGroup1=3
|
||||
RadioGroup2=0
|
||||
RadioGroup3=0
|
||||
RadioGroup4=3
|
||||
RadioGroup5=0
|
||||
RadioGroup6=0
|
||||
RadioGroup7=1
|
||||
RadioGroup8=0
|
||||
RadioGroup9=0
|
||||
RadioGroup10=2
|
||||
RadioGroup11=1
|
||||
RadioGroup12=0
|
||||
RadioGroup13=1
|
||||
RadioGroup14=0
|
||||
RadioGroup17=0
|
||||
LANG=1
|
||||
sRadioGroup2=0
|
||||
ChBox1=0
|
||||
ChBox2=1
|
||||
ChBox3=0
|
||||
ChBox22=0
|
||||
sChBox1=0
|
||||
sChBox2=0
|
||||
sChBox3=0
|
||||
sChBox4=0
|
||||
sChBox5=0
|
||||
sChBox6=0
|
||||
sChBox7=0
|
||||
sChBox8=0
|
||||
sChBox10=0
|
||||
sChBox11=0
|
||||
sChBox12=0
|
||||
sChBox13=1
|
||||
sChBox14=1
|
||||
sChBox15=0
|
||||
sChBox16=1
|
||||
sChBox17=0
|
||||
sChBox22=1
|
||||
sChBox23=0
|
||||
RadioButton1=0
|
||||
RadioButton2=0
|
||||
RadioButton3=1
|
||||
sRadioButton4=1
|
||||
sRadioButton5=0
|
||||
sRadioButton6=0
|
||||
RadioButton13=1
|
||||
RadioButton14=0
|
||||
RadioButton15=0
|
||||
Form6Edit1Text=9600
|
||||
Form6Edit2Text=9600
|
||||
Form6Edit3Text=200
|
||||
Form6Edit8Text=0
|
||||
Form6sEdit1Text=
|
||||
Form6sEdit2Text=
|
||||
sComboBox1ItIn=0
|
||||
SpEd1=0
|
||||
SpEd2=200
|
||||
sSpEd1=1
|
||||
sSpEd2=1
|
||||
KolStrScrolTables=3
|
||||
TipScrolTables=1
|
||||
[Form13]
|
||||
sRadioGroup1=0
|
||||
[Form5]
|
||||
FN_Program=
|
||||
[Form4]
|
||||
SelectColor=14474460
|
||||
sComboBox1ItIn=32
|
||||
[Form14]
|
||||
PeriodPovtora=1000
|
||||
[Form15]
|
||||
ChBox1=0
|
||||
ChBox2=0
|
||||
ChBox3=1
|
||||
FN_SendFile=
|
||||
sEdit1Text=0
|
||||
[ARGUMENTS]
|
||||
AIM00=0
|
||||
AIM01=0
|
||||
AIM02=0
|
||||
AIM03=0
|
||||
AIM04=0
|
||||
AIM05=0
|
||||
AIM06=0
|
||||
AIM07=0
|
||||
AIM10=0
|
||||
AIM11=0
|
||||
AIM12=0
|
||||
AIM13=0
|
||||
AIM14=0
|
||||
AIM15=0
|
||||
AIM16=0
|
||||
AIM17=0
|
||||
AIM20=0
|
||||
AIM21=0
|
||||
AIM22=0
|
||||
AIM23=0
|
||||
AIM24=0
|
||||
AIM25=0
|
||||
AIM26=0
|
||||
AIM27=0
|
||||
AIM30=0
|
||||
AIM31=0
|
||||
AIM32=0
|
||||
AIM33=0
|
||||
AIM34=0
|
||||
AIM35=0
|
||||
AIM36=0
|
||||
AIM37=0
|
||||
AIM40=0
|
||||
AIM41=0
|
||||
AIM42=0
|
||||
AIM43=0
|
||||
AIM44=0
|
||||
AIM45=0
|
||||
AIM46=0
|
||||
AIM47=0
|
||||
AIM50=0
|
||||
AIM51=0
|
||||
AIM52=0
|
||||
AIM53=0
|
||||
AIM54=0
|
||||
AIM55=0
|
||||
AIM56=0
|
||||
AIM57=0
|
||||
AIM60=0
|
||||
AIM61=0
|
||||
AIM62=0
|
||||
AIM63=0
|
||||
AIM64=0
|
||||
AIM65=0
|
||||
AIM66=0
|
||||
AIM67=0
|
||||
AIM70=0
|
||||
AIM71=0
|
||||
AIM72=0
|
||||
AIM73=0
|
||||
AIM74=0
|
||||
AIM75=0
|
||||
AIM76=0
|
||||
AIM77=0
|
||||
AIM80=0
|
||||
AIM81=0
|
||||
AIM82=0
|
||||
AIM83=0
|
||||
AIM84=0
|
||||
AIM85=0
|
||||
AIM86=0
|
||||
AIM87=0
|
||||
AIM90=0
|
||||
AIM91=0
|
||||
AIM92=0
|
||||
AIM93=0
|
||||
AIM94=0
|
||||
AIM95=0
|
||||
AIM96=0
|
||||
AIM97=0
|
||||
ATIP0=0
|
||||
ATIP1=0
|
||||
ATIP2=0
|
||||
ATIP3=0
|
||||
ATIP4=0
|
||||
ATIP5=0
|
||||
ATIP6=0
|
||||
ATIP7=0
|
||||
ATIP8=0
|
||||
ATIP9=0
|
||||
ANAME0=
|
||||
ANAME1=
|
||||
ANAME2=
|
||||
ANAME3=
|
||||
ANAME4=
|
||||
ANAME5=
|
||||
ANAME6=
|
||||
ANAME7=
|
||||
ANAME8=
|
||||
ANAME9=
|
||||
[Form17]
|
||||
sChBox1=0
|
||||
sUD1=1
|
||||
BIN
lc-meter-stm32-arduino/temp/KovalTerminal.exe
Normal file
BIN
lc-meter-stm32-arduino/temp/KovalTerminal.exe
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/KovalTerminal_v2.99_passw1234567.zip
Normal file
BIN
lc-meter-stm32-arduino/temp/KovalTerminal_v2.99_passw1234567.zip
Normal file
Binary file not shown.
2000
lc-meter-stm32-arduino/temp/MACROS/Default.mcs
Normal file
2000
lc-meter-stm32-arduino/temp/MACROS/Default.mcs
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/Terminal_by_Koval-main.zip
Normal file
BIN
lc-meter-stm32-arduino/temp/Terminal_by_Koval-main.zip
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/generic_boot20_pc13.bin
Normal file
BIN
lc-meter-stm32-arduino/temp/generic_boot20_pc13.bin
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/hid_generic_pc13.bin
Normal file
BIN
lc-meter-stm32-arduino/temp/hid_generic_pc13.bin
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/jre-8u471-windows-x64.exe
Normal file
BIN
lc-meter-stm32-arduino/temp/jre-8u471-windows-x64.exe
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/jssc-2.10.2.zip
Normal file
BIN
lc-meter-stm32-arduino/temp/jssc-2.10.2.zip
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/stm32_binaries.zip
Normal file
BIN
lc-meter-stm32-arduino/temp/stm32_binaries.zip
Normal file
Binary file not shown.
BIN
lc-meter-stm32-arduino/temp/zadig-2.9.exe
Normal file
BIN
lc-meter-stm32-arduino/temp/zadig-2.9.exe
Normal file
Binary file not shown.
11
lc-meter-stm32-arduino/test/README
Normal file
11
lc-meter-stm32-arduino/test/README
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||
BIN
lc-meter-stm32-arduino/ХАН 37 -32.pcb
Normal file
BIN
lc-meter-stm32-arduino/ХАН 37 -32.pcb
Normal file
Binary file not shown.
Reference in New Issue
Block a user