Flowcode A/D macro

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 A/D macro

Post by jimhumphries »

I suppose this question/topic should be directed to Ian.

In the Flowcode A/D macro there is a loop counter that defaults to D '220' with a 20 MHz clock. I think there are five or so instructions in the loop so with a 20mHz clock that results in a setup period of at least 220 microseconds (there are also many other instructions that execute outside that loop).

The A/D should be able to do conversions about every 20 microseconds so this would seem to be an excessively long setup period and an unnecessary restriction on the A/D sampling rate. In practice, I'm able to reduce the loop count to D '10' (or even D '5') and the A/D runs happily at about one sample every 30 microseconds. To make the change in the loop count I edit the assembly code for each A/D channel after every compilation.

Why does flowcode impose such a long period and is it possible to directly edit the Flowcode macro so that the C code compiles to .asm with a lower loop count? I've tried dropping the C code for the A/D into a "code box" and then inserting that into a larger program but that doesn't seem to work. Suggestions?

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

Post by Ian »

When we coded the Analogue component we needed to set a convenient sample speed that would work with any PIC or sensors. The delay D220 was chosen as a reasonable sample speed. We did not foresee a need to set sample speed, so the option was not set.

However we can see how such a feature would be useful (as would calling it an 'Analogue sensor' component instead of a 'thermometer' component).
I have popped the suggestion onto the Flowcode Wish list.

As far as the C code goes, it is possible to edit the C Code and use it in Flowcode C Code icons, but it takes a bit of work.

You would need to watch out for how Flowcode prefixes items such as variables etc.

I got the ADC SAmple code to work though.
You need to grab just the code from the macro you are interested in, and paste it in the c Code icon.
Careful though asthe stuff in there is one big comment. If you paste it in the middle of that it will be caught up in the comment.

I pasted the code from the SampleADC macro and modified it as follows:

char ta, te, cnt;
adcon1 = 0x00;
ta = trisa;
trisa = trisa | 0x2F;
te = trise;
trise = trise | 0x07;
adcon0 = 0x81 | (1 << 3);
// Note (X << 3), where X is the ADC channel needed
cnt =0;
while (cnt <50) cnt++;
// Note: Reduced count to 50 from 220
adcon0 = adcon0 | 0x04;
while (adcon0 & 0x04) ;
trisa = ta;
trise = te;
adcon1 = 0x07;

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

Post by jimhumphries »

Ian:

Well, at least for me, the A/D sampling rate is important because I'm sampling a wave and doing a software peak detection. I use two acquisitions in a tight loop and compare the first and second samples. When the value of the second sample is less than the value of the first (SIG2 < SIG1) I've found a peak. I initiate an event that is time-critical when the peak occurs and I then store and process SIG1 as the value of the signal's peak amplitude (the processing relates to my other question about Flowcode math and averaging). In this application the shorter the acquisition time (the higher the rate) the closer I come to capturing the actual peak (in both time and amplitude).

It would be great to have the option to run the A/D "flat out" and I hope you do include that in the next build.

In the mean time, I'll try dropping your modified code into a C icon.

Jim

Post Reply