Example #1
0
/*
** ===================================================================
**     Method      :  FC321_GetTimeMS (bean FreeCntr32)
**
**     Description :
**         Returns the time (as a 16-bit unsigned integer) in milliseconds
**         since the last resetting after the last reset.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Time            - A pointer to the returned 16-bit value
**                           in milliseconds
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_OVERFLOW - Software counter overflow
**                           ERR_MATH - Overflow during evaluation
** ===================================================================
*/
byte FC321_GetTimeMS(word *Time)
{
  dlong RTval;                         /* Result of two 32-bit numbers multiplication */

  if (LoadTicks()) {                   /* Load actual state of counter */
    return ERR_OVERFLOW;               /* If yes then error */
  }
  PE_Timer_LngMul(LTicks, 42949673UL, &RTval); /* Multiply ticks and high speed CPU mode coefficient */
  if (PE_Timer_LngHi4(RTval[0], RTval[1], Time)) { /* Is the result greater or equal than 65536 ? */
    return ERR_MATH;                   /* If yes then error */
  } else {                             /* Is the result less than 65536 ? */
    return ERR_OK;                     /* If yes then OK */
  }
}
/*
** ===================================================================
**     Method      :  TickTimer_SetPeriodTicks32 (bean TimerInt)
**
**     Description :
**         This method sets the new period of the generated events.
**         The period is expressed in Xtal ticks as a 32-bit unsigned
**         integer number.
**         This method is available only if runtime setting type
**         'from interval' is selected in the Timing dialog box in
**         Runtime setting area.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Ticks           - Period to set [in Xtal ticks]
**                      (16000 to 320000 ticks)
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_MATH - Overflow during evaluation
**                           ERR_RANGE - Parameter out of range
** ===================================================================
*/
byte TickTimer_SetPeriodTicks32(dword Ticks)
{
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */
  word rtword;                         /* Result of 64-bit number division */

  if ((Ticks > 320000) || (Ticks < 16000)) /* Is the given value out of range? */
    return ERR_RANGE;                  /* Range error */
  PE_Timer_LngMul(Ticks,838592365,&rtval); /* Multiply given value and high speed CPU mode coefficient */
  if (PE_Timer_LngHi4(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */
    rtword = 65535;                    /* If yes then use maximal possible value */
  CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
  return ERR_OK;                       /* OK */
}
Example #3
0
/*
** ===================================================================
**     Method      :  FC81_GetTimeMS (component FreeCntr8)
**
**     Description :
**         Returns the time (as a 16-bit unsigned integer) in milliseconds
**         since the last resetting after the last reset.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Time            - A pointer to the returned 16-bit value
**                           in milliseconds
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_OVERFLOW - Software counter overflow
**                           ERR_MATH - Overflow during evaluation
** ===================================================================
*/
byte FC81_GetTimeMS(word *Time)
{
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */

  LoadTicks();                         /* Load actual state of counter */
  if (LOvf) {                          /* Testing counter overflow */
    return ERR_OVERFLOW;               /* If yes then error */
  }
  PE_Timer_LngMul((dword)LTicks,34359738UL,&rtval); /* Multiply ticks and high speed CPU mode coefficient */
  if (PE_Timer_LngHi4(rtval[0],rtval[1],Time)) { /* Is the result greater or equal than 65536 ? */
    return ERR_MATH;                   /* If yes then error */
  }
  else {                               /* Is the result less than 65536 ? */
    return ERR_OK;                     /* If yes then OK */
  }
}