Flowcode math

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Flowcode math

Post 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?

Chet
Posts: 61
Joined: Thu Oct 13, 2005 5:05 am
Location: USA
Has thanked: 2 times
Contact:

Post 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.

Ian
Posts: 110
Joined: Thu Sep 29, 2005 10:53 am
Location: Matrix Multimedia
Been thanked: 1 time
Contact:

Post 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.

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Post 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

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Post 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

Chet
Posts: 61
Joined: Thu Oct 13, 2005 5:05 am
Location: USA
Has thanked: 2 times
Contact:

Post 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

jimhumphries
Posts: 112
Joined: Wed Oct 12, 2005 6:29 pm
Location: USA
Been thanked: 1 time
Contact:

Post 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

Post Reply