linear interpolation on 8bit microcontroller

Posted by JB on Stack Overflow See other posts from Stack Overflow or by JB
Published on 2010-04-18T08:19:46Z Indexed on 2010/04/18 8:23 UTC
Read the original article Hit count: 544

I need to do a linear interpolation over time between two values on an 8 bit PIC microcontroller (Specifically 16F627A but that shouldn't matter) using PIC assembly language. Although I'm looking for an algorithm here as much as actual code.

I need to take an 8 bit starting value, an 8 bit ending value and a position between the two (Currently represented as an 8 bit number 0-255 where 0 means the output should be the starting value and 255 means it should be the final value but that can change if there is a better way to represent this) and calculate the interpolated value.

Now PIC doesn't have a divide instruction so I could code up a general purpose divide routine and effectivly calculate (B-A)/(x/255)+A at each step but I feel there is probably a much better way to do this on a microcontroller than the way I'd do it on a PC in c++

Has anyone got any suggestions for implementing this efficiently on this hardware?

© Stack Overflow or respective owner

Related posts about microcontroller

Related posts about algorithm