PIC Math - the need for speed
Hi,
First post here for me, I've been on the pBasic-l list for quiet some time though. Anyway, I'd love some input on the following.
Basicly, what I'm doing is a 'realtime pulse stretcher'. As soon as an input goes low I set an output high and starts TMR1. When the input goes high I stop TMR1, get the count, add 30% to it and then delay that amount of time before I turn the output off. So I tried this:
NewPulseTime = OldPulseTime / 100
NewPulseTime = NewPulseTime * 130
Delay = NewPulseTime - OldPulseTime
That works but it takes to long (Measured it to about 600uS). So I tried this instead.
NewValue = Value >> 6 'Divide by 64.
NewValue = NewValue * 83 'Multiply by 83. 83/64=1.29, close enough
Delay = NewValue - Value 'Calculate the delay.
That works too and is good enough but it seems to take almost 320uS to run.
Does anyone have any ideas how to speed this up except for runnig the PIC faster, that is.
Thanks,
/Henrik Olsson.