Page 1 of 1
Flowcode math
Posted: Thu Oct 20, 2005 5:53 pm
by jimhumphries
Flowcode is a fantastic tool and I've been able to develop and modify large chunks of prototype code very rapidly.
I continue to have, however, a need to do math that would seem to go beyond 8 bit integers. For example, I have a need to compute the "running" average of sixteen 8 bit values. Anybody out there have any tricks for doing this (and similar math) in Flowcode?
Posted: Tue Oct 25, 2005 5:13 am
by Chet
I've got a similar problem. I need to put all 10 bits of the ADC to work
In other words I need 1024 bits of resolution for my project. Any Ideas.
Posted: Tue Oct 25, 2005 9:27 am
by Ian
The ADC example, Tutorial 26, uses the full 10 bits so you can see the maths involved in displaying the full number.
Unfortunately maths on the PIC itself is 8bit so you need to work with multiple variables to implement 10 or 16 bit maths etc.
This is especially frustrating given the 10bit ADC found on many PICs.
Posted: Mon Nov 21, 2005 9:36 pm
by jimhumphries
Ian:
Please consider adding some basic 16 bit math support in you next upgrade to Flowcode.
The examples that are shown on the PICList for 16 bit (and higher) math seem straightforward and could be dropped in after compiling Flowcode to .ASM but it would be awfully convenient if these routines (+, -, * and /) were native to Flowcode.
Jim
Posted: Mon Nov 21, 2005 10:17 pm
by jimhumphries
Chet wrote:I've got a similar problem. I need to put all 10 bits of the ADC to work
In other words I need 1024 bits of resolution for my project. Any Ideas.
Chet:
I don't know if this is helpful to you but - I had to implement a peak detector using all 10 bits of the A/D. I originally only used the high byte but it was too coarse. My routine took two sequential samples of the same signal (SIG1 and SIG2) repeatedly in a tight loop until the second sample (SIG2) was <= SIG1. I modified the routine for 10 bits in the following way:
I added 2 new variables, SIG1 low byte - SIG1L and SIG2 low byte - SIG2L so I have both high and low bytes for both samples.
First I test to see if SIG2 < SIG1 (test the high bytes) - if yes, I'm done (actually, I've missed the peak but its too late to do anything else). If no then I test to see if SIG2 = SIG1. If no, I loop and take two new sequential samples. If yes then I test the low bytes - SIG2L <= SIG1L. If no, I loop. If yes, I'm done (and this time I'm at the peak).
This approach gives a good result and is surprisingly fast.
Jim
Posted: Tue Nov 22, 2005 6:14 am
by Chet
Thanks for the idea jim, my college instructor also had an idea, that I could use the low bits as a counter, but when I run the TUT26.fcf sample
the low bits behaivor throws me. I'm not sure that it can display all 1024
bits.
I'm really just trying to control a stepper motor, with as fine a resolution as possible, I've also thought of using an encoder and forget the a/d but that would be the easy way out. If I understand your method your doing a compare test over and over.
I really wish flowcode supported the highend pics or even better the future
P24 series.
Chet
Posted: Thu Nov 24, 2005 8:15 pm
by jimhumphries
Chet:
Yes - I'm doing the compare over and over until I find the peak then I do something else.
Sounds like you're using an analog position sensor in conjunction with your stepper to get absolute position or angle and/or to servo on position or angle. If that's the case, I think you can use an approach similar to the peak detector to use all 10 bits of the A/D.
Jim