/**********************************************************************//**
 * @brief  Set function for MCLK frequency.
 * 
 * @param  systemClockSpeed Intended frequency of operation - SYSCLK_xxMHZ.
 * 
 * @return none
 *************************************************************************/
void halBoardSetSystemClock(unsigned char systemClockSpeed)
{
  unsigned char setDcoRange, setVCore;
  unsigned int  setMultiplier;

  halBoardGetSystemClockSettings( systemClockSpeed, &setDcoRange,  \
                                  &setVCore, &setMultiplier);
  	
  halBoardSetVCore( setVCore );   

  __bis_SR_register(SCG0);                  // Disable the FLL control loop    
  UCSCTL0 = 0x00;                           // Set lowest possible DCOx, MODx
  UCSCTL1 = setDcoRange;                    // Select suitable range
  
  UCSCTL2 = setMultiplier + FLLD_1;         // Set DCO Multiplier
  UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV  |  SELM__DCOCLKDIV ;
  __bic_SR_register(SCG0);                  // Enable the FLL control loop
  
  // Loop until XT1,XT2 & DCO fault flag is cleared
  do
  {
    UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
                                            // Clear XT2,XT1,DCO fault flags
    SFRIFG1 &= ~OFIFG;                      // Clear fault flags
  }while (SFRIFG1&OFIFG);                   // Test oscillator fault flag
  
  // Worst-case settling time for the DCO when the DCO range bits have been 
  // changed is n x 32 x 32 x f_FLL_reference. See UCS chapter in 5xx UG 
  // for optimization.
  // 32 x 32 x / f_FLL_reference (32,768 Hz) = .03125 = t_DCO_settle
  // t_DCO_settle / (1 / 25 MHz) = 781250 = counts_DCO_settle
  __delay_cycles(781250);  
}
/************************************************************************
 * @brief  Set function for MCLK frequency.
 * 
 * @param  systemClockSpeed Intended frequency of operation - SYSCLK_xxMHZ.
 * 
 * @return none
 *************************************************************************/
void halBoardSetSystemClock(unsigned char systemClockSpeed)
{
  unsigned char setDcoRange = 0;
  unsigned char setVCore = 0;
  unsigned int  setMultiplier = 0;

  halBoardGetSystemClockSettings( systemClockSpeed, &setDcoRange,  \
                                  &setVCore, &setMultiplier);
  	
  if (setVCore > (PMMCTL0 & PMMCOREV_3))	// Only change VCore if necessary
    halBoardSetVCore( setVCore );   
    
  UCSCTL0 = 0x00;                           // Set lowest possible DCOx, MODx
  UCSCTL1 = setDcoRange;                    // Select suitable range
  
  UCSCTL2 = setMultiplier + FLLD_1;         // Set DCO Multiplier
  UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV  |  SELM__DCOCLKDIV ;
  
  // Worst-case settling time for the DCO when the DCO range bits have been 
  // changed is n x 32 x 32 x f_FLL_reference. See UCS chapter in 5xx UG 
  // for optimization.
  // 32 x 32 x / f_FLL_reference (32,768 Hz) = .03125 = t_DCO_settle
  // t_DCO_settle / (1 / 18 MHz) = 562500 = counts_DCO_settle
  
  // __delay_cycles(562500);  
  int i;
  for (i=0;i<10;i++){
    __delay_cycles(56250);  
  }
}
Exemple #3
0
/**********************************************************************//**
 * @brief  Executes the "PMM-MCLK" menu option in the User Experience
 *         example code. This menu option allows one to change the frequency
 *         of operation for the MSP430 and the VCore setting. 
 * 
 * @param  none 
 * 
 * @return none 
 *************************************************************************/
void menuPMMMCLK( void )
{
  unsigned char menuLeftPos = 2, menuRightPos = 0, menuRightMaxAllowed = 5;
  unsigned char ledOn, quit = 0;
  volatile unsigned int i;
  
  halButtonsInterruptDisable( BUTTON_ALL );
  halButtonsInterruptEnable( BUTTON_SELECT + BUTTON_S1 +   \
                             BUTTON_S2 + BUTTON_RIGHT );
  halAccelerometerShutDown();
  halLcdClearScreen();
  
  halBoardOutputSystemClock();
  halLcdPrintLineCol(&VcoreText[0], 0, 1,  OVERWRITE_TEXT );

  for (i=0;i < MCLK_MENU_MAX+1; i++)
    halLcdPrintLineCol(&MCLKText[i*6], i, 12,  OVERWRITE_TEXT );
  
  halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6],        \
                     menuLeftPos+1, 1, INVERT_TEXT | OVERWRITE_TEXT);
  halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],        \
                     menuRightPos+1, 12, INVERT_TEXT | OVERWRITE_TEXT);    
  buttonsPressed = 0;  
  
  for (i = menuRightMaxAllowed; i < MCLK_MENU_MAX; i++)
  {
    halLcdLine(96, 12*(i+1)+6, 136, 12*(i+1)+6, PIXEL_ON);        
    halLcdLine(96, 12*(i+1)+7, 136, 12*(i+1)+7, PIXEL_ON);     
  }
  ledOn = 0;
  halLcdPrintLine("      LED", 6, 0);  
  halLcdPrintLine("      OFF", 7, 0);
  halLcdImage(IMG_RIGHT_FILLED, 4, 32, 10, 75);
  
  halBoardSetVCore(menuLeftPos);
  halBoardSetSystemClock(menuRightPos);  

  while (!quit)
  {
  	// The LED can be enabled to show the relative difference between
  	// frequencies of operation. 
    while (!buttonsPressed)    
      if (ledOn)
      {
        LED_PORT_OUT ^= LED_1;
        for (i=0; i < 0xFFFF; i++)
          if (buttonsPressed)
            break;
      }      
      else
      {
      	// To emulate a real application instead of continuous jumps, use nops 
        __no_operation();
        __no_operation();
        __no_operation();
        __no_operation();                           
        __no_operation();
        __no_operation();
        __no_operation();
        __no_operation();                           
        __no_operation();
      }
    if (buttonsPressed & BUTTON_S1)
    {
      /*
       * Disabled for MSP430F5438 RTM Silicon
      halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6], menuLeftPos+1,      \
                         1,  OVERWRITE_TEXT);
      if (++ menuLeftPos >= VCORE_MENU_MAX)
      {
        menuLeftPos = 0;
        menuRightMaxAllowed = MAX_MCLK_ALLOWED[ menuLeftPos ];
        if (menuRightPos >= menuRightMaxAllowed)
        {
          halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6], menuRightPos+1, \
                             12,  OVERWRITE_TEXT);                
          menuRightPos = menuRightMaxAllowed - 1;
          halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6], menuRightPos+1, \
                             12, INVERT_TEXT | OVERWRITE_TEXT);  
        }        
        for (i = menuRightMaxAllowed; i < MCLK_MENU_MAX; i++)
        {
          halLcdLine(96, 12*(i+1)+6, 136, 12*(i+1)+6, PIXEL_ON);        
          halLcdLine(96, 12*(i+1)+7, 136, 12*(i+1)+7, PIXEL_ON);        
        }
      } 
         
      else            
      {
        for (i=menuRightMaxAllowed+1; i< MAX_MCLK_ALLOWED[menuLeftPos]+1; i ++)
          halLcdPrintLineCol(&MCLKText[i*6], i, 12,  OVERWRITE_TEXT );          
        menuRightMaxAllowed = MAX_MCLK_ALLOWED[menuLeftPos];
      }      
      halLcdPrintLineCol(&VcoreText[menuLeftPos*6 + 6], menuLeftPos+1,       \
                         1, INVERT_TEXT | OVERWRITE_TEXT);
      */
    }
    if ( buttonsPressed & BUTTON_S2 )
    {
      halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],    \
                         menuRightPos+1, 12,  OVERWRITE_TEXT);        
      
      if ( ++menuRightPos >= menuRightMaxAllowed )      
        menuRightPos = 0;
        
      halLcdPrintLineCol(&MCLKText[menuRightPos*6 + 6],    \
                         menuRightPos+1, 12, INVERT_TEXT| OVERWRITE_TEXT);              
    }
    if ( buttonsPressed & BUTTON_RIGHT )
    {
      ledOn = 1 - ledOn;
      if ( ledOn )        
        halLcdPrintLineCol("ON ", 7, 6, OVERWRITE_TEXT);
      else
      {
      	halLcdPrintLineCol("OFF", 7, 6, OVERWRITE_TEXT);
        LED_PORT_OUT &= ~LED_1;
      }         
    }    
    
    if ( buttonsPressed & (BUTTON_S1 | BUTTON_S2) )
    {
      halBoardSetVCore(menuLeftPos);
  		halBoardSetSystemClock(menuRightPos);  
  		//halBoardDisableSVS();
    }
    if ( buttonsPressed & BUTTON_SELECT )    
      quit = 1;
    buttonsPressed = 0;
  }
  
  halBoardSetSystemClock( SYSCLK_16MHZ );
  halBoardStopOutputSystemClock();
  LED_PORT_OUT &= ~LED_1;
}