big refactoring and features added
This commit is contained in:
64
App/Devices/ad9833_device.c
Normal file
64
App/Devices/ad9833_device.c
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* @file ad9833_device.c
|
||||
* @brief AD9833 waveform-generator control helpers.
|
||||
*/
|
||||
|
||||
#include "ad9833_device.h"
|
||||
|
||||
#include "board_io.h"
|
||||
#include "main.h"
|
||||
|
||||
static void ad9833_write_word(uint16_t word)
|
||||
{
|
||||
uint32_t timeout = 0u;
|
||||
|
||||
board_io_configure_spi2_mode(LL_SPI_POLARITY_HIGH, LL_SPI_PHASE_1EDGE);
|
||||
|
||||
HAL_GPIO_WritePin(AD9102_CS_GPIO_Port, AD9102_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(DAC_LD1_CS_GPIO_Port, DAC_LD1_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(DAC_TEC1_CS_GPIO_Port, DAC_TEC1_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(AD9833_CS_GPIO_Port, AD9833_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
while ((!LL_SPI_IsActiveFlag_TXE(SPI2)) && (timeout++ < 1000u))
|
||||
{
|
||||
}
|
||||
LL_SPI_TransmitData16(SPI2, word);
|
||||
|
||||
timeout = 0u;
|
||||
while ((!LL_SPI_IsActiveFlag_RXNE(SPI2)) && (timeout++ < 1000u))
|
||||
{
|
||||
}
|
||||
(void)SPI2->DR;
|
||||
|
||||
HAL_GPIO_WritePin(AD9833_CS_GPIO_Port, AD9833_CS_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void ad9833_apply(uint8_t enabled, uint8_t triangle_mode, uint32_t frequency_word)
|
||||
{
|
||||
uint16_t control = 0x2000u;
|
||||
uint16_t lsw;
|
||||
uint16_t msw;
|
||||
|
||||
if (triangle_mode != 0u)
|
||||
{
|
||||
control |= 0x0002u;
|
||||
}
|
||||
|
||||
control |= 0x0100u;
|
||||
|
||||
frequency_word &= 0x0FFFFFFFu;
|
||||
lsw = (uint16_t)(0x4000u | (frequency_word & 0x3FFFu));
|
||||
msw = (uint16_t)(0x4000u | ((frequency_word >> 14) & 0x3FFFu));
|
||||
|
||||
ad9833_write_word(control);
|
||||
ad9833_write_word(lsw);
|
||||
ad9833_write_word(msw);
|
||||
ad9833_write_word(0xC000u);
|
||||
|
||||
if (enabled != 0u)
|
||||
{
|
||||
control &= (uint16_t)(~0x0100u);
|
||||
}
|
||||
|
||||
ad9833_write_word(control);
|
||||
}
|
||||
Reference in New Issue
Block a user