我用的是msp430f5529单片机,写了个DCO倍频到25M时pwm方波输出程序,我用JTAG供电,程序为啥掉电丢失啊,好像就是因为时钟源的问题,感觉是供电电压不够,求指教,下面是程序
#include <msp430.h>
void SetVcoreUp (unsigned int level);
int main(void)
{
volatile unsigned int i;
{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop WDT
P3SEL |= BIT5+BIT6; // P3.5-3.6 option select
P3DIR |= BIT5+BIT6; // P3.5-3.6 outputs // Increase Vcore setting to level3 to support fsystem=25MHz
// NOTE: Change core voltage one level at a time..
SetVcoreUp (0x01);
SetVcoreUp (0x02); SetVcoreUp (0x03); UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
P3SEL |= BIT5+BIT6; // P3.5-3.6 option select
P3DIR |= BIT5+BIT6; // P3.5-3.6 outputs // Increase Vcore setting to level3 to support fsystem=25MHz
// NOTE: Change core voltage one level at a time..
SetVcoreUp (0x01);
SetVcoreUp (0x02); SetVcoreUp (0x03); UCSCTL3 = SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_7; // Select DCO range 50MHz operation
UCSCTL2 = FLLD_0 + 762; // Set DCO Multiplier for 25MHz
// (N + 1) * FLLRef = Fdco
// (762 + 1) * 32768 = 25MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_7; // Select DCO range 50MHz operation
UCSCTL2 = FLLD_0 + 762; // Set DCO Multiplier for 25MHz
// (N + 1) * FLLRef = Fdco
// (762 + 1) * 32768 = 25MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop
// Worst-case settling time for the DCO when the DCO range bits have been
// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization.
// 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle
__delay_cycles(782000);
// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization.
// 32 x 32 x 25 MHz / 32,768 Hz ~ 780k MCLK cycles for DCO to settle
__delay_cycles(782000);
// Loop until XT1,XT2 & DCO stabilizes – In this case only DCO has to stabilize
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
while(1)
{ TBCCR0 = 1024; // PWM Period
TBCCTL5 = OUTMOD_7; // CCR5 reset/set
TBCCR5 = 512; // CCR5 PWM duty cycle
TBCCTL6 = OUTMOD_7; // CCR6 reset/set
TBCCR6 = 216; // CCR6 PWM duty cycle
TBCTL = TBSSEL_2+MC_1; // SMCLK, upmode
}
}
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag
while(1)
{ TBCCR0 = 1024; // PWM Period
TBCCTL5 = OUTMOD_7; // CCR5 reset/set
TBCCR5 = 512; // CCR5 PWM duty cycle
TBCCTL6 = OUTMOD_7; // CCR6 reset/set
TBCCR6 = 216; // CCR6 PWM duty cycle
TBCTL = TBSSEL_2+MC_1; // SMCLK, upmode
}
}
void SetVcoreUp (unsigned int level)
{
// Open PMM registers for write
PMMCTL0_H = PMMPW_H; // Set SVS/SVM high side new level
SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;
// Set SVM low side to new level
SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;
// Wait till SVM is settled
while ((PMMIFG & SVSMLDLYIFG) == 0);
// Clear already set flags
PMMIFG &= ~(SVMLVLRIFG + SVMLIFG);
// Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level;
// Wait till new level reached
if ((PMMIFG & SVMLIFG))
while ((PMMIFG & SVMLVLRIFG) == 0);
// Set SVS/SVM low side to new level
SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;
// Lock PMM registers for write access
PMMCTL0_H = 0x00;
}
{
// Open PMM registers for write
PMMCTL0_H = PMMPW_H; // Set SVS/SVM high side new level
SVSMHCTL = SVSHE + SVSHRVL0 * level + SVMHE + SVSMHRRL0 * level;
// Set SVM low side to new level
SVSMLCTL = SVSLE + SVMLE + SVSMLRRL0 * level;
// Wait till SVM is settled
while ((PMMIFG & SVSMLDLYIFG) == 0);
// Clear already set flags
PMMIFG &= ~(SVMLVLRIFG + SVMLIFG);
// Set VCore to new level
PMMCTL0_L = PMMCOREV0 * level;
// Wait till new level reached
if ((PMMIFG & SVMLIFG))
while ((PMMIFG & SVMLVLRIFG) == 0);
// Set SVS/SVM low side to new level
SVSMLCTL = SVSLE + SVSLRVL0 * level + SVMLE + SVSMLRRL0 * level;
// Lock PMM registers for write access
PMMCTL0_H = 0x00;
}
answer:
您好,请确保程序以写入ROM中,如果在RAM中运行,掉电即会丢失
user4973021:
回复 answer:
您好,请问怎么才能知道程序已经下载到ROM中,其他的程序就不会丢失,以用到25MHz时就丢失
user4973021:
回复 answer:
有没有可能是JTAG供电不足导致,我测了一下3.3V引脚只有2.12V,5v引脚只有2.99V,25M频率需要最低几V 电压支撑呢?
user4973021:
回复 user4973021:
顶一顶,求解答
灰小子:
回复 user4973021:
25MHz需要2.4v及以上电压
user4973021:
回复 灰小子:
哦。看来使板子供电电压没上去的问题
user5917571:
回复 answer:
若MCU 不含ROM单元(如MSP430G2230,仅有FLASH 和RAM),那如何让程序掉电不丢失呢?
灰小子:
回复 user5917571:
flash就是这个单片机的ROM