Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linear interpolation on 8bit microcontroller

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?

like image 328
jcoder Avatar asked Apr 18 '10 08:04

jcoder


1 Answers

The techniques described by Eric Bainville and Mads Elvheim will work fine; each one uses two multiplies per interpolation.

Scott Dattalo and Tony Kubek have put together a super-optimized PIC-specific interpolation technique called "twist" that is slightly faster than two multiplies per interpolation.

Is using this difficult-to-understand technique worth running a little faster?

like image 187
David Cary Avatar answered Sep 27 '22 22:09

David Cary