Digital Programmable Oscillator: Connecting the LTC6903 to STM32.
In one of my designs I needed to vary a clock frequency over a wide range, and as the title suggests, I chose the LTC6903. The LTC6903 and LTC6904 are digital programmable oscillators with a frequency range from 1KHz to 68MHz; the only difference is that the LTC6903 is controlled via SPI and the LTC6904 via I2C. They are quite easy to connect and only require bypass capacitors on the supply.
Let's look at their main characteristics:
This chip comes in an MS8 package.

Pin functions:
To connect the oscillator via SPI, open STM32CUBE and select the controller, in my case the STM32F103VE; then select the SPI you want to use and see which pins it uses. You can enlarge the picture by clicking on it.
As for the SEN pin, at first I tied it to ground, and the LTC6903 worked unreliably: when a command was sent, oscillation didn't always start, and sometimes it started at the wrong frequency. After paging through the datasheet a couple more times, I noticed the Min Latch Time – SEN to SEN parameter, i.e. the minimum time between toggles of the SEN pin is 400nS; from this we can conclude that this pin should be actively controlled rather than simply tied to ground. And that really turned out to be the case.
Since SEN must stay low for a certain time, we'll control it with an ordinary pin configured as an open-collector output rather than with the NSS pin.
Connection according to the datasheet

Pull all SPI pins up to the supply with 10K resistors.
Now about the command word itself


The picture above makes it clear that it consists of 16 bits; the upper 4 bits determine the range our oscillation frequency will be in

The next 10 bits set the frequency; to find their value, use the formula

OCT - the value from the table, f - the frequency
And the last two bits determine which outputs the oscillation will appear on.

I should say that after power-up, all registers are zero, and both CLK pins output a 1.03KHz square wave.
Now let's look at an example of how to start the oscillator at the frequency we need. If we want the oscillation frequency to be 6.5MHz, first we find the value of OCT from the table.

OCT = 12, or 1100; now, substituting the OCT value into the formula, we get DAC

Rounding the resulting value to an integer, DAC = 707, or 1011000011. All that's left is to choose which output the oscillation will appear on; let it be CLK (CNF1 = 1, CNF0 = 0).
Now let's put all the resulting digits side by side: 1100 1011 0000 1110; converting this number to hexadecimal gives 0xCB0E, the number that needs to be sent to start the oscillator at 6.5MHz, or thereabouts, since we rounded a little.
Writing the code.
I should mention that at frequencies above 1MHz, the load capacitance must be minimized to 5 pF, otherwise the oscillation frequency will drift from the calculated value. A high-speed buffer can be used for this. For our measurement, it's enough to set the probe switch to 1:10.
Let's check the result.

The calculated frequency differs from the real one, and the difference exceeds the 1.1% error stated by the manufacturer. In my project this chip clocks an ADC and the frequencies I need are known in advance, so it's no problem for me to trim the frequency to the required value via DAC, but it can't be used as a local oscillator.
The overshoots on the edges are caused by the length of the ground clip wire; let's replace it with a special probe tip.

That's all.
Let's look at their main characteristics:
- supply voltage range from 2.7V — 5.5V
- current consumption of 1.7mA at 2.7V and an output frequency < 1MHz
- frequency error < 1.1% over the entire frequency range
- temperature drift of 10ppm/°C
This chip comes in an MS8 package.

Pin functions:
- V, GND – power pins
- SDI (Serial Data Input), SCK (Serial Clock), SEN (Serial Enable) – SPI connection pins
- CLK – oscillator outputs
- OE – asynchronous input; when this pin is set to logic zero, the oscillator output is set to logic zero
To connect the oscillator via SPI, open STM32CUBE and select the controller, in my case the STM32F103VE; then select the SPI you want to use and see which pins it uses. You can enlarge the picture by clicking on it.
As for the SEN pin, at first I tied it to ground, and the LTC6903 worked unreliably: when a command was sent, oscillation didn't always start, and sometimes it started at the wrong frequency. After paging through the datasheet a couple more times, I noticed the Min Latch Time – SEN to SEN parameter, i.e. the minimum time between toggles of the SEN pin is 400nS; from this we can conclude that this pin should be actively controlled rather than simply tied to ground. And that really turned out to be the case.
Since SEN must stay low for a certain time, we'll control it with an ordinary pin configured as an open-collector output rather than with the NSS pin.
Connection according to the datasheet

Pull all SPI pins up to the supply with 10K resistors.
Now about the command word itself


The picture above makes it clear that it consists of 16 bits; the upper 4 bits determine the range our oscillation frequency will be in

The next 10 bits set the frequency; to find their value, use the formula

OCT - the value from the table, f - the frequency
And the last two bits determine which outputs the oscillation will appear on.

I should say that after power-up, all registers are zero, and both CLK pins output a 1.03KHz square wave.
Now let's look at an example of how to start the oscillator at the frequency we need. If we want the oscillation frequency to be 6.5MHz, first we find the value of OCT from the table.

OCT = 12, or 1100; now, substituting the OCT value into the formula, we get DAC

Rounding the resulting value to an integer, DAC = 707, or 1011000011. All that's left is to choose which output the oscillation will appear on; let it be CLK (CNF1 = 1, CNF0 = 0).
Now let's put all the resulting digits side by side: 1100 1011 0000 1110; converting this number to hexadecimal gives 0xCB0E, the number that needs to be sent to start the oscillator at 6.5MHz, or thereabouts, since we rounded a little.
Writing the code.
#include "stm32f10x.h"
void Spi_Init (void)
{
//enable clocking of Port B and alternate functions
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN | | RCC_APB2ENR_AFIOEN;
//pins 13 and 15 - alternate function, push pull, pin 10 - output, open drain
GPIOB->CRH &= ~(GPIO_CRH_CNF13_0 | GPIO_CRH_CNF15_0);
GPIOB->CRH |= GPIO_CRH_CNF13_1 | GPIO_CRH_CNF15_1;
GPIOB->CRH |= GPIO_CRH_MODE10_0 | GPIO_CRH_MODE13_1 | GPIO_CRH_MODE15_1;
//enable SPI2 clocking
RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
SPI2->CR1 |= SPI_CR1_BR; //Baud rate = Fpclk/256
SPI2->CR1 |= SPI_CR1_CPOL; //Polarity cls signal CPOL = 1;
SPI2->CR1 |= SPI_CR1_CPHA; //Phase cls signal CPHA = 1;
SPI2->CR1 |= SPI_CR1_DFF; //16 bit data
SPI2->CR1 &= ~SPI_CR1_LSBFIRST; //MSB will be first
SPI2->CR1 |= SPI_CR1_SSM | SPI_CR1_SSI; //Software slave management & Internal slave select
SPI2->CR1 |= SPI_CR1_MSTR; //Mode Master
SPI2->CR1 |= SPI_CR1_SPE; //Enable SPI2
}
void delay(uint32_t delayTime)
{
uint32_t i;
for(i = 0; i < delayTime; i++);
}
void Spi_Transmit(uint16_t data)
{
while(!(SPI2->SR & SPI_SR_TXE));
GPIOB->BSRR = GPIO_BSRR_BR10;
SPI2->DR = data;
delay(10000);
GPIOB->BSRR = GPIO_BSRR_BS10;
}
int main(void)
{
delay(720000);
Spi_Init();
//after initialization, the LTC6903 only starts responding after the second command
Spi_Transmit(0X0000);
Spi_Transmit(0XCB0E);
while(1)
{
}
}
I should mention that at frequencies above 1MHz, the load capacitance must be minimized to 5 pF, otherwise the oscillation frequency will drift from the calculated value. A high-speed buffer can be used for this. For our measurement, it's enough to set the probe switch to 1:10.
Let's check the result.

The calculated frequency differs from the real one, and the difference exceeds the 1.1% error stated by the manufacturer. In my project this chip clocks an ADC and the frequencies I need are known in advance, so it's no problem for me to trim the frequency to the required value via DAC, but it can't be used as a local oscillator.
The overshoots on the edges are caused by the length of the ground clip wire; let's replace it with a special probe tip.

That's all.


