Need some solutions for Xmega256A3BU Board

Status
Not open for further replies.

kkkkkk

Newbie level 1
Joined
Jan 17, 2014
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
Hi guys, I am new to the AVR Studio programming environment and i am using the Xmega256 A3BU board to work a project on signal sine wave generation. As shown below is a code which i am using through DAC to generate a 25khz step sine wave. I am able to change the frequency easily.
By using the DAC output on xmega256a3bu board which is on Header J2,
is it possible to set a time delay, lets say 1second? Example: such that the output will give a 25khz sine wave, and after 1second a 28khz sine wave?
I am not sure how to set up the time delay so as to implement a 28khz sine wave in. I appreciate any help that can be given by anybody, Thanks!


Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include "avr/dac_driver.h"
#include "avr/clksys_driver.h"
#include "avr/avr_compiler.h"
#include "avr/board.h"
#include "avr/tc_driver.h" // Include timer counter driver

#define TIMER_C0_PERIOD 160

char i = 0;
static inline uint8_t arr[8]=
{
	0x7F, 0xD9, 0xFF, 0xD9, 0x7F, 0x25, 0x00, 0x25
};
ISR(TCC0_OVF_vect)
{
DACB.CH0DATAH = arr[i++];
if( i == 8 )
{
i = 0;
}
}
static inline void init_32MhzClock(void)
{
OSC.CTRL = OSC_RC32MEN_bm; // 32 MHz Internal RC Oscillator Enable
while( ! ( OSC.STATUS & OSC_RC32MRDY_bm ) );
CCP = CCP_IOREG_gc;
CLK.CTRL = CLK_SCLKSEL_RC32M_gc; // System Clock Selection: 32 MHz Internal RC Oscillator
}
static inline void init_timer()
{
TCC0.CTRLA = 0x01; // Set: Prescaler (Change)

TCC0.CTRLB = 0; // Set: Normal Mode, Update on Top
TCC0.CTRLC = 0; // Disabled: Waveform
TCC0.CTRLD = 0; // Disabled: Event System
TCC0.CTRLE = 0; // 8]Bit Mode is off; word mode active;
TCC0.INTCTRLA = 0x01; // Enabled: Overflow interrupt with LOW Priority on port C
TCC0.INTCTRLB = 0; // Disabled: Disable ABCD Capture/Compare interrupts
TCC0.INTFLAGS = 0x00; // Reset: Overflow Flag in bit 0; Clear any initial interrupt flags
TCC0.CNT = 0; // Init: Counter register
TCC0.PER = TIMER_C0_PERIOD; // Set: Period register (Change)
}
static inline void init_pmic(void)
{
PMIC.CTRL |= PMIC_LOLVLEN_bm;
}
static inline void init_port()
{
init_32MhzClock();
init_timer();
init_pmic();
}
static inline void DACInit(void)
{
DAC_SingleChannel_Enable( &DACB, DAC_REFSEL_AVCC_gc, 1);
}
void main(void)
{
cli();
init_port();
DACInit() ;
sei();
while(1);
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…