Hi All,
I am new to MSP430, and need some of your help in possibly a very simple problem.
I am trying to generate a sine wave using MSP430FG4618 experimenter's board. The MCU has a 8 MHz CPU, the MCLK= SMCLK=1MHz, and ACLK=32 kHZ.
I used the example program in the MSP430FG461X, to generate sine/cosine wave with 32 steps using DMA controller and DAC12. I successfully got the sine wave, but what I don't understand is how the frequency of the wave is determined. I tried to change/measure the frequency by changing the Clock periods of TACCR0, because thats what I thought was the way to change the frequency. The frequency of the sine wave I got was:
Clock Period of TACCR0 Frequency
2 4.096 kHz
20 1.645 kHz
100 328.9 Hz
I can't figure out whats determining the frequency, there doesn't seem to be a linear relationship. I would really appreciate any help in this matter
The program is:
//////////////////////////////////////////////////////
#include "msp430xG46x.h"
//------------------------------------------------------------------------------
// 12-bit Sine Lookup table with 32 steps
//------------------------------------------------------------------------------
// 12-bit Cosine Lookup table with 32 steps
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= XCAP14PF; // Configure load caps
ADC12CTL0 = REF2_5V + REFON; // Internal 2.5V ref
TACCR0 = 13600; // Delay to allow Ref to settle
TACCTL0 |= CCIE; // Compare-mode interrupt.
TACTL = TACLR + MC_1 + TASSEL_2; // Up mode, SMCLK
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
TACCTL0 &= ~CCIE; // Disable timer interrupt
__disable_interrupt(); // Disable Interrupts
DMACTL0 = DMA0TSEL_5 + DMA1TSEL_5; // DAC12IFG triggers
DMA0SA = (int)Sin_tab; // Source block address
DMA0DA = DAC12_0DAT_; // Destination single address
DMA0SZ = 0x020; // Block size
DMA0CTL = DMADT_4 + DMASRCINCR_3 + DMAEN; // Rpt, inc src, word-word
DMA1SA = (int)Cos_tab; // Source block address
DMA1DA = DAC12_1DAT_; // Destination single address
DMA1SZ = 0x020; // Block size
DMA1CTL = DMADT_4 + DMASRCINCR_3 + DMAEN; // Rpt, inc src, word-word
DAC12_0CTL = DAC12LSEL_2 + DAC12IR + DAC12AMP_5 + DAC12IFG + DAC12ENC + DAC12GRP;
DAC12_1CTL = DAC12LSEL_2 + DAC12IR + DAC12AMP_5 + DAC12IFG + DAC12ENC;
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 1; // TACCR1 PWM Duty Cycle
TACCR0 = 100-1; // Clock period of TACCR0
TACTL = TASSEL_2 + MC_1; // SMCLK, contmode
while(1)
{
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0
}
}
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
TACTL = 0; // Clear Timer_A control registers
__bic_SR_register_on_exit(LPM0_bits); // Exit LPMx, interrupts enabled
}
/////////////////////////////////////