📄 cpux_04.c
字号:
//******************************************************************************
// MSP430xG461x Demo - R4 ptr, Rpt'd Blk to DAC0, Sine Out, TimerA0, DCO
//
// This program shows how register R4 can be locked to store a 20-bit address
// variable to access the data look-up table placed in the extended memory, to
// transfer the contents in the data table word by word to the DAC.
//
// Description: A 32 word Sine look-up table is stored in the extended memory
// location 0x10000 onwards by interfacing C with assembly code. Register R4 is
// used as a pointer to store the 20-bit address of the extended memory.
// ASM functions are provided to read and write the 20-bit address from/to
// register R4. The R4 pointer is used to access the data from the extended
// memory and transfer the contents of the Sine look-up table word-by-word as a
// repeating block to DAC12_0. And DAC12_0 outputs on P6.6 a 1-kHz Sine wave.
// Timer A operates in compare mode, where, TACCR0 sets Clk period and TACCR1
// sets PWM duty cycle. To get a 1-kHz Sine wave out, timer period is set to
// almost 32us (as 32us*32 words ~ 1ms) , with TimerA clock running at 1MHz.
// And during the TimerA0 ISR the data present at the address pointed by
// register R4, is loaded to the DAC12_0 data reg and the contents of R4 are
// incremented to point the next address. DAC12_0 uses internal 1.5V reference.
// ACLK = 32kHz, MCLK = SMCLK = default DCO 8MHz, TACLK = SMCLK/8 = 1MHZ
//
// MSP430xG461x
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|RST XOUT|-
// | |
// | DAC0/P6.6|--> ~ 1-kHz sine wave output
//
// Note 1: The linker file for this project has to be modified to create a
// new memory segment(CONST_HIGH with memory range [10000 to 1FFFF] in
// this example). The linker command -Z(CONST)CONST_HIGH=10000-1FFFF
// is used to create a new memory segment in the extended memory
// (0x10000 - 0x1FFFF).
// Note 2: This code example interfaces C with Assembler code, therefore, the
// project must include assembly file "ASM_func.s43".
// Note 3: Register R4 is used as a address variable by the user and should be
// locked so that the compiler doesnt use this register for its
// operations. Therefore, the compiler commnd line option --lock_r4 is
// to be used.
// Project>Options>C/C++ Compiler>Code>R4 utilization>Not used
//
// Bhargavi Nisarga
// Texas Instruments Inc.
// June 2007
// Built with IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include "msp430xG46x.h"
#include "intrinsics.h"
// Function prototypes for ASM functions
extern unsigned long __Get_Address20(void);
extern void __Write_R4(unsigned long value);
extern unsigned int __Read_at_R4_plus(void);
unsigned short Count, Size;
void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//Set DCO freq = 8MHz
FLL_CTL0 |= DCOPLUS + XCAP18PF; // DCO+ set, freq = xtal x D x N+1
SCFI0 |= FN_4; // x2 DCO freq, 8MHz nominal DCO
SCFQCTL = 121;
ADC12CTL0 = REFON; // Internal 1.5V reference
for (i = 0x3600; i; i--); // Delay for needed ref start-up.
// See datasheet for details.
// Initialize Pointer - R4 used as a pointer
__Write_R4(__Get_Address20()); // Call ASM func to write
// starting address of data table in
// extended memory to R4
Size = 0x0020; //Size in words
Count = 0;
// Configur DAC12_0
DAC12_0CTL = DAC12IR + DAC12AMP_5 + DAC12ENC;
// amp and i/p range setting,
// DAC enable
// Configure Timer A
TACCTL1 = OUTMOD_3; // TACCR1 set/reset
TACCR1 = 1; // TACCR1 PWM Duty Cycle
TACCR0 = 30; // Clock period of TACCR0
TACCTL0 = CCIE; // Interrupt enable
TACTL = TASSEL_2 + MC_1 + TACLR + ID_3; // SMCLK, upmode, (i/p clk/8)
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts
}
// TimerA interrupt service routine
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR(void)
{
// Get data at the address present in R4 to DAC data reg and incr ptr
DAC12_0DAT = __Read_at_R4_plus();
if (++Count >= Size) // Chk if count within memory range
{
// Repeat Block transfer from extended memory to DAC12_0
__Write_R4(__Get_Address20());
Count = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -