/* Sets the signal's frequency/pulse-width to the specified number of microseconds. */
int pwmSetFrequencyInMicroseconds(uint16_t us)
/* Sets the signal's frequency/pulse-width to the specified number of microseconds. */
int pwmSetFrequencyInMicroseconds(uint16_t us)
{
  if (us < 1)
  {
    return -1;
  }
  uint32_t ticks = (((CFG_CPU_CCLK/SCB_SYSAHBCLKDIV) / 1000000) * us);
  if (ticks > 0xFFFF)
  {
    return -1;
  }
  TMR_TMR16B1MR3 = (pwmPulseWidth = ticks - 1);
  TMR_TMR16B1MR0 = (pwmPulseWidth * (100 - pwmDutyCycle)) / 100;
  return 0;  
}