Created
October 17, 2017 18:36
-
-
Save RickKimball/d8f972ae2823c65b177f7cee3a708f44 to your computer and use it in GitHub Desktop.
nco example for fabooh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* nco.cpp - toggle pins at 60Hz and 50Hz using a 50kHz timer clock | |
*/ | |
#include <fabooh.h> | |
#include <main.h> | |
#include <nco.h> | |
RED_LED RED; | |
GREEN_LED GREEN; | |
void config_timer(); | |
void setup(void) { | |
RED.setmode_output(); | |
GREEN.setmode_output(); | |
} | |
struct toggle_red_led { | |
void tick(void) { | |
RED.toggle(); | |
} | |
}; | |
struct toggle_green_led { | |
void tick(void) { | |
GREEN.toggle(); | |
} | |
}; | |
const long clk_in_freq=50000; | |
NCO < 60*2, clk_in_freq, toggle_red_led > clk_60Hz; | |
NCO < 50*2, clk_in_freq, toggle_green_led > clk_50Hz; | |
void loop(void) { | |
config_timer(); | |
CPU::enable_clkout(); | |
_EINT(); | |
while (1) { | |
} | |
} | |
void config_timer() { | |
TA0CTL = TASSEL_2 | MC_1; // Timer A config: SMCLK, count up | |
TA0CCR0 = 320 - 1; // Setup Timer A CCR0 period for 50,000 Hz | |
TA0CCTL0 |= CCIE; // Enable PWM interrupt | |
} | |
#pragma vector = TIMER0_A0_VECTOR | |
__interrupt void timer_a_isr(void) | |
{ | |
clk_60Hz.rising_edge(); | |
clk_50Hz.rising_edge(); | |
} | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment