Compare commits

...

2 commits

Author SHA1 Message Date
c4272c5230 Improve lcd_write_integer_page()
The procedure `lcd_write_integer_page()` is improved by increasing the
possible values of the `comperator` variable and adding comments.
2021-09-27 21:31:12 +02:00
0395da78de Generate default clock signals
The "demo" from Adafruits Si5351 library is used to produce a working
proof of concept which sets PLLA to 720MHz, PLLB to 705MHz and then
Multisynth0, Multisynth1 and Multisynth2 to 120MHz, 12MHz and 13.56MHz
respectively.
2021-09-27 21:29:11 +02:00

View file

@ -24,6 +24,9 @@
#define SI5351_ADDRESS 0x60
#define SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL 3
#define SI5351_REGISTER_177_PLL_RESET 177
#define SYM_ENTRY(SYM) { SYM, sizeof(SYM) / 2 }
static uint8_t EEMEM eeprom_contrast = 8;
@ -171,6 +174,69 @@ static volatile uint8_t enc = 0;
static volatile uint8_t value_contrast;
static volatile uint8_t value_backlight;
static const uint8_t m_si5351_regs_15to92_149to170[100][2] = {
// Init
{3, 0xFF},
{16, 0x4F}, /* CLK0 Control: 8mA drive, Multisynth 0 as CLK0 source, Clock
not inverted, Source = PLLA, Multisynth 0 in integer mode,
clock powered up */
{17, 0x4F}, /* CLK1 Control: 8mA drive, Multisynth 1 as CLK1 source, Clock
not inverted, Source = PLLA, Multisynth 1 in integer mode,
clock powered up */
{18, 0x6F}, /* CLK2 Control: 8mA drive, Multisynth 2 as CLK2 source, Clock
not inverted, Source = PLLB, Multisynth 2 in integer mode,
clock powered up */
{19, 0x80}, /* CLK3 Control: Not used ... clock powered down */
{20, 0x80}, /* CLK4 Control: Not used ... clock powered down */
{21, 0x80}, /* CLK5 Control: Not used ... clock powered down */
{22, 0x80}, /* CLK6 Control: Not used ... clock powered down */
{23, 0x80}, /* CLK7 Control: Not used ... clock powered down */
// PLL_A Setup (720MHz)
{26, 0x00},
{27, 0x05},
{28, 0x00},
{29, 0x0C},
{30, 0x66},
{31, 0x00},
{32, 0x00},
{33, 0x02},
// PLL_B Setup (705MHz)
{34, 0x02},
{35, 0x71},
{36, 0x00},
{37, 0x0C},
{38, 0x1A},
{39, 0x00},
{40, 0x00},
{41, 0x86},
// Multisynth0 Setup (120MHz)
{42, 0x00},
{43, 0x01},
{44, 0x00},
{45, 0x01},
{46, 0x00},
{47, 0x00},
{48, 0x00},
{49, 0x00},
// Multisynth1 Setup (12MHz)
{50, 0x00},
{51, 0x01},
{52, 0x00},
{53, 0x1C},
{54, 0x00},
{55, 0x00},
{56, 0x00},
{57, 0x00},
// Multisynth2 Setup (13.56MHz)
{58, 0x00},
{59, 0x01},
{60, 0x00},
{61, 0x18},
{62, 0x00},
{63, 0x00},
{64, 0x00},
{65, 0x00}};
static void spi_init(void) {
SPI_DDR |= (1 << SPI_SCK) | (1 << SPI_MOSI) | (1 << SPI_SS);
SPI_PORT |= (1 << SPI_SS);
@ -304,15 +370,18 @@ static void lcd_write_integer_page(const uint32_t integer,
const bool invert) {
if (digits != 0 || integer != 0) {
uint8_t input_digits = 0;
uint16_t comperator = 1;
uint32_t comperator = 1;
// Get digits
for (; comperator <= integer; comperator *= 10, input_digits++);
// Print leading zeroes
for (int8_t i = digits - input_digits; i > 0; i--) {
lcd_write_kerning(2, invert);
lcd_write_digit_page(0, page, invert);
}
// Print number itself
for (; comperator >= 10; comperator /= 10) {
lcd_write_kerning(2, invert);
lcd_write_digit_page((integer % comperator) / (comperator / 10),
@ -809,6 +878,13 @@ int main(void) {
(void) &twi_read_register;
(void) &twi_write_register;
for (uint16_t i = 0; i < sizeof(m_si5351_regs_15to92_149to170) / 2; i++)
twi_write_register(SI5351_ADDRESS, m_si5351_regs_15to92_149to170[i][0],
m_si5351_regs_15to92_149to170[i][1]);
twi_write_register(SI5351_ADDRESS, SI5351_REGISTER_177_PLL_RESET, 0xAC);
twi_write_register(SI5351_ADDRESS, SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL, 0x00);
// Enable interrupts
sei();