Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: WoYaoChengGOng V2-WoYaoChengGOng STM32_MagneticLight tape_Led_Sample ... more
Revision 15:d69eebdee025, committed 2013-03-01
- Comitter:
- DavidEGrayson
- Date:
- Fri Mar 01 05:05:09 2013 +0000
- Parent:
- 14:672baf3cf941
- Child:
- 16:eaed541b08b0
- Commit message:
- Cleaned up calculateDelays more. The library might be done now.
Changed in this revision
| PololuLedStrip.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/PololuLedStrip.cpp Fri Mar 01 05:00:49 2013 +0000
+++ b/PololuLedStrip.cpp Fri Mar 01 05:05:09 2013 +0000
@@ -2,47 +2,37 @@
bool PololuLedStrip::interruptFriendly = false;
-// The three timed delays, in units of half-instructions.
+// The three timed delays, in units of half-cycles.
uint8_t led_strip_write_delays[3];
void PololuLedStrip::calculateDelays()
{
- // Get the clock frequency in MHz.
- int f_mhz = SystemCoreClock / 1000000;
+ int f_mhz = SystemCoreClock / 1000000; // Clock frequency in MHz.
if (f_mhz <= 48)
{
// The delays below result in 800/1590 ns pulses and a 2500 ns period on the mbed NXP LPC11U24.
led_strip_write_delays[0] = 0;
led_strip_write_delays[1] = 0;
- led_strip_write_delays[2] = 5 << 1;
+ led_strip_write_delays[2] = 5;
}
else
{
- // Try to generally compute what the delays should be for any frequency clock.
+ // Try to generally compute what the delays should be for a ide range of clock frequencies.
// The fudge factors below were experimentally chosen so that we would have
- // 700/1300 ns pulses and a ~ 2500 ns period on the mbed NXP LPC1768 (96 MHz Cortex-M3).
+ // 700/1300 ns pulses and a ~2500 ns period on the mbed NXP LPC1768 (96 MHz Cortex-M3).
// If you ever change these numbers, it is important to check the the subtractions below
- // will not overflow in the worst case, which is f_mhz = 48.
- static const uint8_t delay_fudges[] = { 23, 28, 23 };
-
- led_strip_write_delays[0] = 700*f_mhz/1000;
- led_strip_write_delays[1] = 600*f_mhz/1000;
- led_strip_write_delays[2] = 1200*f_mhz/1000;
-
- for(int i = 0; i < 3; i++)
- {
- if (led_strip_write_delays[i] < delay_fudges[i])
- {
- led_strip_write_delays[i] = 0;
- }
- else
- {
- led_strip_write_delays[i] -= delay_fudges[i];
- led_strip_write_delays[i] <<= 1;
- }
- }
+ // will not overflow in the worst case, which is f_mhz = 49.
+ led_strip_write_delays[0] = 700*f_mhz/1000 - 23;
+ led_strip_write_delays[1] = 600*f_mhz/1000 - 28;
+ led_strip_write_delays[2] = 1200*f_mhz/1000 - 23;
+ }
+
+ // Convert from units of cycles to units of half-cycles; it makes the assembly faster.
+ for(int i = 0; i < 3; i++)
+ {
+ led_strip_write_delays[i] <<= 1;
}
}
Pololu Addressable RGB LED Strip