aggiunto oscillatore
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <arm_math.h>
|
||||
// #include <arm_math.h>
|
||||
#include "main.h"
|
||||
#include "rx.h"
|
||||
#include "tx.h"
|
||||
|
||||
#define TX_TYPE_NONE 0
|
||||
#define TX_TYPE_DAC 1
|
||||
#define TX_TYPE_PWM 2
|
||||
#define TX_TYPE_SI5351 3
|
||||
// #define TX_TYPE TX_TYPE_SI5351
|
||||
#define TX_TYPE TX_TYPE_NONE
|
||||
|
||||
#define IF_TYPE_NOIF 0
|
||||
#define IF_TYPE_LOMIX 1
|
||||
#define IF_TYPE IF_TYPE_NOIF
|
||||
|
||||
#define LO_TYPE_FIX 0
|
||||
#define LO_TYPE_SI5351 1
|
||||
#define LO_TYPE LO_TYPE_SI5351
|
||||
|
||||
#define CLOCK (168000000UL)
|
||||
|
||||
// RX ADC
|
||||
@@ -19,67 +34,15 @@
|
||||
#define TX_DAC_BUFFER_SIZE (1024)
|
||||
#define TX_DAC_BUFFER_RATE (TX_DAC_SAMPLE_RATE/TX_DAC_BUFFER_SIZE)
|
||||
|
||||
// =========== HBF ==========
|
||||
// #define MS_HBF_TAP_NUM (15)
|
||||
|
||||
|
||||
// #define DECIMATION_FACTOR (ADC_BUFFER_SIZE/ST2_BUFFER_SIZE)
|
||||
// #define DECIMATION_FACTOR_MASK (DECIMATION_FACTOR - 1)
|
||||
|
||||
/*
|
||||
// 1° stadio
|
||||
// decimazione del singolo stadio
|
||||
#define MS_DECIMATION_FACTOR (2)
|
||||
#define MS_DECIMATION_FACTOR_MASK (MS_DECIMATION_FACTOR - 1)
|
||||
// ringbuf
|
||||
#define MIXED_SAMPLES_RINGBUFFER_SIZE (64) // l'ultimo deve essere grande almeno come MS_HBF_TAP_NUM
|
||||
#define MIXED_SAMPLES_RINGBUFFER_SIZE_MASK (MIXED_SAMPLES_RINGBUFFER_SIZE - 1)
|
||||
#define MIXED_SAMPLES_2M_RINGBUFFER_SIZE (MIXED_SAMPLES_RINGBUFFER_SIZE / 2)
|
||||
#define MIXED_SAMPLES_2M_RINGBUFFER_SIZE_MASK (MIXED_SAMPLES_2M_RINGBUFFER_SIZE - 1)
|
||||
|
||||
#define ST1_OUT_SAMPLE_RATE (ADC_SAMPLE_RATE/(MS_DECIMATION_FACTOR*2))
|
||||
|
||||
// 2° stadio
|
||||
#define ST2_BUFFER_SIZE (256)
|
||||
#define ST2_DECIMATION_FACTOR (4)
|
||||
#define ST2_OUT_SAMPLE_RATE (ST1_OUT_SAMPLE_RATE/ST2_DECIMATION_FACTOR)
|
||||
#define ST2_FILTER_BLOCK_SIZE (ST2_BUFFER_SIZE)
|
||||
#define ST2_FILTER_TAP_NUM (128)
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
// =========== DEMOD ==========
|
||||
|
||||
// DAC_SAMPLE_RATE/((2^32)/(incremento)) = freq
|
||||
// (2^32)/(DAC_SAMPLE_RATE/freq) = incremento
|
||||
#define NCO2_INCREMENT (343597383L)
|
||||
#define NCO2_FREQUENCY (DAC_SAMPLE_RATE/((0xFFFFFFFF)/NCO2_INCREMENT))
|
||||
#define LF_BUFFER_SIZE (ST2_BUFFER_SIZE/ST2_DECIMATION_FACTOR)
|
||||
|
||||
// audio filter
|
||||
#define AUDIO_FILTER_TAP_NUM 128
|
||||
#define AUDIO_FILTER_FREQ_DEF (1350)
|
||||
#define AUDIO_FILTER_FREQ_MAX (DAC_SAMPLE_RATE/2)
|
||||
#define AUDIO_FILTER_BW_DEF (2000)
|
||||
#define AUDIO_FILTER_BW_MAX (DAC_SAMPLE_RATE/2)
|
||||
#define AUDIO_FILTER_BETA_DEF (16)
|
||||
#define AUDIO_FILTER_BLOCK_SIZE LF_BUFFER_SIZE
|
||||
*/
|
||||
// statemask
|
||||
/*
|
||||
#define FREQUENCY_OFFSET 0
|
||||
#define GAIN_OFFSET 1
|
||||
#define VOLUME_OFFSET 2
|
||||
#define FILTER_OFFSET 3
|
||||
#define MODULATION_OFFSET 4
|
||||
*/
|
||||
|
||||
#define MOD_DC 0
|
||||
#define MOD_LSB 1
|
||||
#define MOD_USB 2
|
||||
#define MOD_AM 3
|
||||
|
||||
#define STATUS_RX 0
|
||||
#define STATUS_TX 1
|
||||
#define STATUS_SQ 2
|
||||
|
||||
// === DAC ===
|
||||
#define DAC_DIVISOR 7680
|
||||
#define DAC_SAMPLE_RATE (CLOCK/DAC_DIVISOR)
|
||||
@@ -96,6 +59,8 @@
|
||||
extern uint8_t receive, transmit;
|
||||
extern q31_t nco1_increment;
|
||||
extern uint32_t frequency;
|
||||
extern int32_t rit;
|
||||
extern uint16_t pwm_tx_period;
|
||||
extern int32_t modulation;
|
||||
extern int32_t gain;
|
||||
extern int32_t peak, oldpeak, peakset;
|
||||
@@ -105,9 +70,11 @@ extern int32_t mic_gain;
|
||||
extern int32_t scan;
|
||||
extern uint32_t audio_filter_freq, audio_filter_bw, audio_filter_beta;
|
||||
extern uint16_t state_changed;
|
||||
|
||||
extern char tabstring[15];
|
||||
extern CORDIC_HandleTypeDef hcordic;
|
||||
|
||||
extern uint8_t s_meter;
|
||||
|
||||
// uartz
|
||||
extern char uart_rx_buf[2], rx_cmd_rb[RX_CMD_RB_SIZE];
|
||||
extern uint8_t rx_cmd_rb_in_idx, rx_cmd_rb_out_idx;
|
||||
@@ -130,6 +97,7 @@ extern q31_t if_Q[LF_BUFFER_SIZE];
|
||||
extern uint8_t lf_buffer_toggle;
|
||||
extern q31_t prefilter_lf_buffer[LF_BUFFER_SIZE];
|
||||
extern q31_t lf_buffer[2][LF_BUFFER_SIZE];
|
||||
// extern q31_t lf_buffer_test[2][LF_BUFFER_SIZE];
|
||||
|
||||
// ======== FUNZIONI ========
|
||||
|
||||
@@ -147,3 +115,8 @@ q31_t sat_mult_q31(q31_t a, q31_t b);
|
||||
|
||||
// diag
|
||||
void diag(void);
|
||||
|
||||
uint32_t get_pwm_freq(uint16_t pwm_period);
|
||||
uint16_t get_pwm_period(uint32_t pwm_frequency);
|
||||
|
||||
uint8_t measure_log_abs_mean(q31_t *samples, uint16_t size);
|
||||
|
||||
@@ -31,30 +31,22 @@
|
||||
#define TYP_FLOAT 1
|
||||
#define TYP_ALPHA 2
|
||||
#define TYP_LIST 3
|
||||
#define TYP_NED 4
|
||||
#define TYP_HID 5
|
||||
|
||||
/*
|
||||
#define MOD_DC 0
|
||||
#define MOD_LSB 1
|
||||
#define MOD_USB 2
|
||||
#define MOD_AM 3
|
||||
*/
|
||||
#define MENU_PAGE_SOM 0
|
||||
#define MENU_PAGE_DEFAULT 0
|
||||
#define MENU_PAGE_AUDIO 1
|
||||
#define MENU_PAGE_EOM 1
|
||||
|
||||
#define MENU_PAGE_MEM 2
|
||||
#define MENU_PAGE_ALL 255
|
||||
|
||||
#define SAT 0
|
||||
#define WRAP 1
|
||||
|
||||
/*
|
||||
#define MENU_SELECT_FREQ 0
|
||||
#define MENU_SELECT_VOL 1
|
||||
#define MENU_SELECT_MODUL 2
|
||||
#define MENU_SELECT_FILTER_F 3
|
||||
#define MENU_SELECT_FILTER_BW 4
|
||||
*/
|
||||
|
||||
// #define MENU_SELECT_DEFAULT MENU_SELECT_FREQ
|
||||
// #define MENU_SELECT_EOM MENU_SELECT_FILTER_BW
|
||||
|
||||
#define MENU_NAME_ROW 0
|
||||
#define MENU_NAME_COL 1
|
||||
#define MENU_NAME_COL 0
|
||||
|
||||
#define DISPLAY_BL_DIM 0
|
||||
#define DISPLAY_ROWS 6
|
||||
@@ -70,6 +62,7 @@ typedef void (*menu_set_function)(void);
|
||||
typedef void (*menu_print_function)(uint8_t a);
|
||||
|
||||
struct menu_item {
|
||||
uint8_t page;
|
||||
char name[14];
|
||||
uint8_t type;
|
||||
uint8_t size;
|
||||
@@ -79,19 +72,24 @@ struct menu_item {
|
||||
uint32_t min;
|
||||
uint32_t max;
|
||||
uint8_t wrap;
|
||||
char prefix[4];
|
||||
char suffix[4];
|
||||
uint32_t *varptr;
|
||||
menu_set_function set_function_ptr;
|
||||
menu_print_function print_function_ptr;
|
||||
};
|
||||
|
||||
extern uint8_t menu_mode, current_tab;
|
||||
extern uint8_t menu_item, menu_page;
|
||||
extern uint8_t menu_last_item[MENU_PAGE_EOM + 1];
|
||||
|
||||
extern char modulation_list[4][4];
|
||||
extern char status_list[3][3];
|
||||
|
||||
extern struct menu_item items[];
|
||||
extern struct menu_item tabs[];
|
||||
// extern struct menu_item tabs[];
|
||||
|
||||
extern uint8_t menu_item_count;
|
||||
extern uint8_t tabs_count;
|
||||
// extern uint8_t tabs_count;
|
||||
|
||||
// funcs
|
||||
|
||||
@@ -99,9 +97,10 @@ void encoder_increment(void);
|
||||
void encoder_decrement(void);
|
||||
void joystick_dx(void);
|
||||
void joystick_sx(void);
|
||||
void set_menu_mode(uint8_t mode);
|
||||
void set_menu_item(uint8_t mode);
|
||||
|
||||
void print_integer(uint8_t item_idx);
|
||||
void print_string(uint8_t item_idx);
|
||||
void print_modulation(uint8_t item_idx);
|
||||
void print_bar(uint8_t item_idx);
|
||||
void print_frequency(uint8_t item_idx);
|
||||
@@ -109,3 +108,5 @@ void print_frequency(uint8_t item_idx);
|
||||
char * valToStr(uint32_t val, char *buf, uint8_t bufSize, char sepChar);
|
||||
|
||||
uint8_t sat_subu8b(uint8_t x, uint8_t y);
|
||||
void menu_item_up(void);
|
||||
void menu_item_down(void);
|
||||
|
||||
@@ -59,14 +59,16 @@ void set_gain(void);
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define NC1_Pin GPIO_PIN_0
|
||||
#define NC1_GPIO_Port GPIOA
|
||||
#define NC2_Pin GPIO_PIN_2
|
||||
#define NC2_GPIO_Port GPIOA
|
||||
#define OUT_Pin GPIO_PIN_12
|
||||
#define OUT_GPIO_Port GPIOA
|
||||
#define T_SWDIO_Pin GPIO_PIN_13
|
||||
#define T_SWDIO_GPIO_Port GPIOA
|
||||
#define T_SWCLK_Pin GPIO_PIN_14
|
||||
#define T_SWCLK_GPIO_Port GPIOA
|
||||
#define T_SWO_Pin GPIO_PIN_3
|
||||
#define T_SWO_GPIO_Port GPIOB
|
||||
#define OUT_Pin GPIO_PIN_5
|
||||
#define OUT_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
@@ -76,5 +78,3 @@ void set_gain(void);
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#define NCO2_INCREMENT (343597383L)
|
||||
#define NCO2_FREQUENCY (DAC_SAMPLE_RATE/((0xFFFFFFFF)/NCO2_INCREMENT))
|
||||
#define LF_BUFFER_SIZE (ST2_BUFFER_SIZE/ST2_DECIMATION_FACTOR)
|
||||
|
||||
// 1° stadio
|
||||
// decimazione del singolo stadio
|
||||
@@ -28,16 +27,21 @@
|
||||
#define ST2_FILTER_BLOCK_SIZE (ST2_BUFFER_SIZE)
|
||||
#define ST2_FILTER_TAP_NUM (128)
|
||||
|
||||
#define LF_BUFFER_SIZE (ST2_BUFFER_SIZE/ST2_DECIMATION_FACTOR)
|
||||
|
||||
// audio filter
|
||||
#define AUDIO_FILTER_TAP_NUM 128
|
||||
#define AUDIO_FILTER_FREQ_DEF (1350)
|
||||
#define AUDIO_FILTER_FREQ_DEF (1250)
|
||||
#define AUDIO_FILTER_FREQ_MAX (DAC_SAMPLE_RATE/2)
|
||||
#define AUDIO_FILTER_BW_DEF (2000)
|
||||
#define AUDIO_FILTER_BW_MAX (DAC_SAMPLE_RATE/2)
|
||||
#define AUDIO_FILTER_BETA_DEF (16)
|
||||
#define AUDIO_FILTER_BLOCK_SIZE LF_BUFFER_SIZE
|
||||
|
||||
extern int32_t rx_signal;
|
||||
#define RX_SMETER_SCALE 4
|
||||
|
||||
extern uint8_t rx_signal, rx_signal_last;
|
||||
extern q31_t rx_nco1_increment;
|
||||
|
||||
// filtro st2
|
||||
extern arm_fir_decimate_instance_q31 st2_filter_I_struct;
|
||||
@@ -67,6 +71,4 @@ void audio_filter_init(void);
|
||||
void audio_filter_generate_coeffs(int32_t *Coeffs, uint32_t freq, uint32_t bw, uint8_t beta);
|
||||
q31_t hb_fir15(q31_t * samples_ringbuf, uint8_t sample_index, uint8_t buff_size_mask, q31_t * coefficients);
|
||||
|
||||
void rx_measure_signal(q31_t *samples, uint16_t size);
|
||||
|
||||
#endif
|
||||
|
||||
27
codice/Core/Inc/si5351.h
Normal file
27
codice/Core/Inc/si5351.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#define SI5351_ADDRESS (0x60)
|
||||
|
||||
#define SI5351_CRYSTAL_FREQ 24000000
|
||||
|
||||
#define SI5351_MIN_FREQ 3000
|
||||
#define SI5351_MAX_FREQ 200000000
|
||||
|
||||
#define SI5351_OUT_ENABLE 3
|
||||
#define SI5351_OUT_DIS_STATE 24
|
||||
|
||||
#define SI5351_INPUT_SOURCE 15
|
||||
|
||||
#define SI5351_CLK0_CONTROL 16
|
||||
#define SI5351_CLK1_CONTROL 17
|
||||
#define SI5351_CLK2_CONTROL 18
|
||||
|
||||
#define SI5351_PLLA 26
|
||||
#define SI5351_PLLB 34
|
||||
|
||||
#define SI5351_MULTISYNTH0 42
|
||||
#define SI5351_MULTISYNTH1 50
|
||||
#define SI5351_MULTISYNTH2 58
|
||||
|
||||
#define SI5351_RESET 177
|
||||
#define SI5351_CRYSTAL_LOAD 183
|
||||
|
||||
extern I2C_HandleTypeDef hi2c1;
|
||||
@@ -1,21 +1,22 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file stm32g4xx_hal_conf.h
|
||||
* @author MCD Application Team
|
||||
* @brief HAL configuration file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
* Copyright (c) 2019 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software component is licensed by ST under BSD 3-Clause license,
|
||||
* the "License"; You may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at:
|
||||
* opensource.org/licenses/BSD-3-Clause
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef STM32G4xx_HAL_CONF_H
|
||||
@@ -46,7 +47,7 @@
|
||||
/*#define HAL_HRTIM_MODULE_ENABLED */
|
||||
/*#define HAL_IRDA_MODULE_ENABLED */
|
||||
/*#define HAL_IWDG_MODULE_ENABLED */
|
||||
/*#define HAL_I2C_MODULE_ENABLED */
|
||||
#define HAL_I2C_MODULE_ENABLED
|
||||
/*#define HAL_I2S_MODULE_ENABLED */
|
||||
/*#define HAL_LPTIM_MODULE_ENABLED */
|
||||
/*#define HAL_NAND_MODULE_ENABLED */
|
||||
@@ -377,5 +378,3 @@ void assert_failed(uint8_t *file, uint32_t line);
|
||||
#endif
|
||||
|
||||
#endif /* STM32G4xx_HAL_CONF_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -72,5 +72,3 @@ void TIM7_IRQHandler(void);
|
||||
#endif
|
||||
|
||||
#endif /* __STM32G4xx_IT_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#define TX_AUDIO_FILTER_BLOCK_SIZE (1024)
|
||||
#define TX_AUDIO_FILTER_TAP_NUM (128)
|
||||
|
||||
extern uint8_t tx_signal, tx_signal_last;
|
||||
extern q31_t tx_nco1_increment;
|
||||
|
||||
// buffer
|
||||
extern volatile uint8_t half_tx_dac_buffer_empty, tx_dac_buffer_toggle;
|
||||
extern volatile uint8_t tx_adc_buffer_ready;
|
||||
|
||||
Reference in New Issue
Block a user