Gamma SPb (22.02.2007 12:55, просмотров: 1) ответил M@ik на Вопрос по LP oscillator в dsPIC
ИМХО Главное правильно его включить:
<c>
/**
*
* @param osc Oscillator type
* @param freq External quartz frequency. Any value, if used internal OSC
* @param pll PLL multiplier coefficient.
* @param div Oscillator module postscaler coefficient
*
* @return BSPRETVAL
*/
BSPRETVAL osc_SetNew (OSC_TYPE osc, bUDWORD freq, OSC_PLL_MUL pll, OSC_PS div)
{
CURR_OSC *old_osc, new_osc;
bUCHAR oscconh, oscconl;
bBOOL cflag;
cflag = FALSE;
if ((freq * pll) > MAX_CPU_FREQ) /* Check parameters value */
return BSP_WPARAM;
old_osc = osc_GetCurrent(); /* Get current oscillator */
oscconh = OSCCON >> 8;
oscconl = OSCCON & 0x00FF;
cflag = TRUE;
new_osc.type = osc;
new_osc.pll = pll;
oscconh &= ~OSC_NOSC_MASK;
oscconh |= osc;
switch (osc) /* Set new system frequency */
{
case OSC_LP_OSC:
new_osc.freq = freq;
break;
case OSC_INT_FRC:
new_osc.freq = FRC_DEF_FREQ;
break;
case OSC_INT_LPRC:
new_osc.freq = LPRC_FREQ;
break;
case OSC_PRIMARY:
new_osc.freq = freq * pll;
break;
default:
return BSP_WPARAM;
}
if (old_osc->postsc != div) /* Set new postscaler coeff */
{
cflag = TRUE;
oscconl &= ~OSC_POST_MASK;
oscconl |= div;
}
new_osc.postsc = div;
switch (new_osc.postsc) /* Apply postscaler to calculate Fosc */
{
case OSC_PS_1:
break;
case OSC_PS_4:
new_osc.freq /= 4;
break;
case OSC_PS_16:
new_osc.freq /= 16;
break;
case OSC_PS_64:
new_osc.freq /= 64;
break;
}
if (cflag)
{
*old_osc = new_osc;
oscconl |= 0x01;
BSP_ENTER_CRITICAL();
__builtin_write_OSCCONH(oscconh);
__builtin_write_OSCCONL(oscconl);
#ifndef BSP_SIM_ENABLE
while (OSCCON_bit.OSWEN);
#endif
BSP_EXIT_CRITICAL();
}
return BSP_NOERR;
}
</c>