Microchip® Advanced Software Framework

sinewave_example.c File Reference

DAC Sinewave Example.

Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_dacc_sinewave_example.h"

Macros

#define DACC_ANALOG_CONTROL
 Analog control value. More...
 
#define DEFAULT_FREQUENCY   1000
 Default frequency. More...
 
#define MAX_AMPLITUDE   (DACC_MAX_DATA)
 The maximal (peak-peak) amplitude value. More...
 
#define MAX_DIGITAL   (0x7ff)
 The maximal sine wave sample data (no sign) More...
 
#define MAX_FREQUENCY   3000
 Max frequency. More...
 
#define MIN_AMPLITUDE   (100)
 The minimal (peak-peak) amplitude value. More...
 
#define MIN_FREQUENCY   200
 Min frequency. More...
 
#define SAMPLES   (100)
 SAMPLES per cycle. More...
 
#define STRING_EOL   "\r"
 
#define STRING_HEADER
 
#define VAL_INVALID   0xFFFFFFFF
 Invalid value. More...
 
#define wave_to_dacc(wave, amplitude, max_digital, max_amplitude)   (((int)(wave) * (amplitude) / (max_digital)) + (max_amplitude / 2))
 

Functions

static void configure_console (void)
 Configure console. More...
 
static void display_menu (void)
 Display main menu. More...
 
static uint32_t get_input_value (uint32_t ul_lower_limit, uint32_t ul_upper_limit)
 Get input from user, and the biggest 4-digit decimal number is allowed. More...
 
int main (void)
 DAC Sinewave application entry point. More...
 
void SysTick_Handler (void)
 SysTick IRQ handler. More...
 

Variables

int32_t g_l_amplitude = 0
 Amplitude. More...
 
uint8_t g_uc_wave_sel = 0
 Waveform selector. More...
 
uint32_t g_ul_frequency = 0
 Frequency. More...
 
uint32_t g_ul_index_sample = 0
 Current g_ul_index_sample. More...
 
const int16_t gc_us_sine_data [SAMPLES]
 100 points of sinewave samples, amplitude is MAX_DIGITAL*2 More...
 

#define DACC_ANALOG_CONTROL
Value:
(DACC_ACR_IBCTLCH0(0x02) \
| DACC_ACR_IBCTLCH1(0x02) \
| DACC_ACR_IBCTLDACCORE(0x01))

Analog control value.

Referenced by main().

#define DEFAULT_FREQUENCY   1000

Default frequency.

Referenced by main().

#define MAX_AMPLITUDE   (DACC_MAX_DATA)

The maximal (peak-peak) amplitude value.

Referenced by display_menu(), main(), and SysTick_Handler().

#define MAX_DIGITAL   (0x7ff)

The maximal sine wave sample data (no sign)

Referenced by SysTick_Handler().

#define MAX_FREQUENCY   3000

Max frequency.

Referenced by display_menu(), and main().

#define MIN_AMPLITUDE   (100)

The minimal (peak-peak) amplitude value.

Referenced by display_menu(), and main().

#define MIN_FREQUENCY   200

Min frequency.

Referenced by display_menu(), and main().

#define SAMPLES   (100)

SAMPLES per cycle.

Referenced by main(), and SysTick_Handler().

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"-- DAC Sinewave Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Name of the board.
Definition: sam4l_ek.h:47
#define STRING_EOL
Definition: sinewave_example.c:125

Referenced by main().

#define VAL_INVALID   0xFFFFFFFF

Invalid value.

Referenced by get_input_value(), and main().

#define wave_to_dacc (   wave,
  amplitude,
  max_digital,
  max_amplitude 
)    (((int)(wave) * (amplitude) / (max_digital)) + (max_amplitude / 2))

Convert wave data to DACC value Put the sinewave to an offset of max_amplitude/2.

Parameters
waveWaveform data
amplitudeAmplitude value
max_digitalMaximal digital value of input data (no sign)
max_amplitudeMaximal amplitude value

Referenced by SysTick_Handler().

static void display_menu ( void  )
static
static uint32_t get_input_value ( uint32_t  ul_lower_limit,
uint32_t  ul_upper_limit 
)
static

Get input from user, and the biggest 4-digit decimal number is allowed.

Parameters
ul_lower_limitThe lower limit of input
ul_upper_limitThe upper limit of input

References CONSOLE_UART, usart_serial_getchar(), and VAL_INVALID.

Referenced by main().

int32_t g_l_amplitude = 0

Amplitude.

Referenced by display_menu(), main(), and SysTick_Handler().

uint8_t g_uc_wave_sel = 0

Waveform selector.

Referenced by display_menu(), main(), and SysTick_Handler().

uint32_t g_ul_frequency = 0

Frequency.

Referenced by display_menu(), and main().

uint32_t g_ul_index_sample = 0

Current g_ul_index_sample.

Referenced by SysTick_Handler().

const int16_t gc_us_sine_data[SAMPLES]
Initial value:
= {
0x0, 0x080, 0x100, 0x17f, 0x1fd, 0x278, 0x2f1, 0x367, 0x3da, 0x449,
0x4b3, 0x519, 0x579, 0x5d4, 0x629, 0x678, 0x6c0, 0x702, 0x73c, 0x76f,
0x79b, 0x7bf, 0x7db, 0x7ef, 0x7fb, 0x7ff, 0x7fb, 0x7ef, 0x7db, 0x7bf,
0x79b, 0x76f, 0x73c, 0x702, 0x6c0, 0x678, 0x629, 0x5d4, 0x579, 0x519,
0x4b3, 0x449, 0x3da, 0x367, 0x2f1, 0x278, 0x1fd, 0x17f, 0x100, 0x080,
-0x0, -0x080, -0x100, -0x17f, -0x1fd, -0x278, -0x2f1, -0x367, -0x3da, -0x449,
-0x4b3, -0x519, -0x579, -0x5d4, -0x629, -0x678, -0x6c0, -0x702, -0x73c, -0x76f,
-0x79b, -0x7bf, -0x7db, -0x7ef, -0x7fb, -0x7ff, -0x7fb, -0x7ef, -0x7db, -0x7bf,
-0x79b, -0x76f, -0x73c, -0x702, -0x6c0, -0x678, -0x629, -0x5d4, -0x579, -0x519,
-0x4b3, -0x449, -0x3da, -0x367, -0x2f1, -0x278, -0x1fd, -0x17f, -0x100, -0x080
}

100 points of sinewave samples, amplitude is MAX_DIGITAL*2

Referenced by SysTick_Handler().