2024-06-13 14:52:23 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <msp430g2553.h>
|
|
|
|
#include "generator.h"
|
|
|
|
|
|
|
|
|
2024-06-13 17:53:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const float BASE_FREQUENCY = 2457600.0;
|
|
|
|
const float MAIN_DIVIDER = 8388606.0; // 2^23
|
|
|
|
|
|
|
|
|
2024-06-15 23:16:26 +02:00
|
|
|
static uint16_t frequencyToDivider(float freq) {
|
|
|
|
float n = (freq * MAIN_DIVIDER) / BASE_FREQUENCY;
|
2024-06-13 17:53:12 +02:00
|
|
|
uint16_t i = (uint16_t) n;
|
|
|
|
if (n - i >= 0.5) {
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2024-06-13 14:52:23 +02:00
|
|
|
void generatorInit() {
|
|
|
|
P1DIR |= BIT0 | BIT1 | BIT2 | BIT3;
|
|
|
|
P1OUT |= BIT0 | BIT1 | BIT2 | BIT3;
|
|
|
|
|
2024-06-15 23:16:26 +02:00
|
|
|
genShifter(0, frequencyToDivider(1000));
|
|
|
|
genShifter(1, frequencyToDivider(10));
|
2024-06-13 14:52:23 +02:00
|
|
|
}
|
|
|
|
|