Algorithms

Algorithm Description Resources
Searching
Frequently on a PIC® MCU a RAM search can be a linear search because the chip is so fast and the RAM is so small. Searching flash or external memory may require a better algorithm such as those in the references.
Sorting
Sorting can be time intensive. Finding a good algorithm is important. If you have enough memory consider using an array of indexes or pointers that is sorted instead of the actual data.
PID
The Proportional-Integral-Derivative (PID) uses three coefficients on feedback data to adjust a stimulus. For example is you control the voltage to a motor and then read back the actual speed, the PID algorithm will tell you how much to adjust the voltage to reach your target speed. Constants used in the PID algorithm must be tuned for each specific system to match response times and the desired slope of change.
Error Detection & Correction
Simple error detection uses a parity bit, checksum or CRC on important data saved in memory or transmitted over a communications interface. More complicated techniques have multiple parity bits so errors can not only be detected but corrected as well.
  • Example Checksum Code
    • EX_CHECKSUM.C
  • Example CRC Code
    • EX_CRC.C
    • CRC.C
  • Error correction theory using the reed-solomon algorithm
Encryption
Encryption can take a lot of processing power. If you don't need to comply with a specific standard (like you would for doing web encryption) then XTEA is a simple and strong enough standard to be used on most PIC® MCU processors.