Wiblocks --- NCO Library

Numerically Controlled Oscillator (NCO) Library

The NCO (Numerically Controller Oscillator) library provides a set of procedures to enable the NB1A board to function as a four channel numerically controlled oscillator.

The library is setup with a 64 byte wave table and a sample frequency of 3750Hz. These values can be changed in the header file.

The following hardware needs to be setup in the main program prior to calling the library functions --

NCO/NCO.c File Reference

#include <NCO.h>
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include "WConstants.h"

Go to the source code of this file.

Defines

#define nco_dac_toggle_latch   { PORTB&=~(1<<NCO_DAC_LATCH); PORTB|=(1<<NCO_DAC_LATCH);}
 toggles the NB1A DAC latch bit low then high
#define nco_dac_toggle_load   { PORTB&=~(1<<NCO_DAC_LOAD); PORTB|=(1<<NCO_DAC_LOAD);}
 toggles the NB1A DAC load bit low then high

Functions

void nco_inc (void)
 Call this function to increment all of the phase accumulators.
void nco_set_freq (unsigned char ch, double freq)
 Sets the phase increment of an NCO channel.
void nco_init (void)
 Initializes the NCO structure.
void nco_update (void)
 Updates all of the NCO channels.

Variables

struct nco_struct nco [NCO_NUM_CHS-1]

Detailed Description

Definition in file NCO.c.

Function Documentation

void nco_inc ( void   ) 

Call this function to increment all of the phase accumulators.

Returns:
VOID

Definition at line 16 of file NCO.c.

void nco_init ( void   ) 

Initializes the NCO structure.

Resets the phase accumulator, phase increment and the DAC control bytes. This should be called once at the start of program before calling any other NCO functions or enabling interrupts.

Definition at line 42 of file NCO.c.

void nco_set_freq ( unsigned char  ch,
double  freq 
)

Sets the phase increment of an NCO channel.

The value of the frequency must be less than half the sampling rate.

Parameters:
[in] ch oscillator channel number (0..3)
[in] freq oscillator frequency
Returns:
VOID

Definition at line 31 of file NCO.c.

void nco_update ( void   ) 

Updates all of the NCO channels.

This function should be called every time the timer interrupt occurs.

Definition at line 74 of file NCO.c.