Skip to content

Instantly share code, notes, and snippets.

@SaheblalBagwan
Last active April 16, 2016 08:41
Show Gist options
  • Save SaheblalBagwan/53d0477123d605ea6819 to your computer and use it in GitHub Desktop.
Save SaheblalBagwan/53d0477123d605ea6819 to your computer and use it in GitHub Desktop.
unsigned int getPrescalarForUs(uint8_t timerPclkBit)
{
unsigned int pclk,prescalarForUs;
pclk = (LPC_SC->PCLKSEL0 >> timerPclkBit) & 0x03; /* get the pclk info for required timer */
switch ( pclk ) /* Decode the bits to determine the pclk*/
{
case 0x00:
pclk = SystemCoreClock/4;
break;
case 0x01:
pclk = SystemCoreClock;
break;
case 0x02:
pclk = SystemCoreClock/2;
break;
case 0x03:
pclk = SystemCoreClock/8;
break;
}
prescalarForUs =pclk/1000000 - 1; /* Prescalar for 1us (1000000Counts/sec) */
return prescalarForUs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment