RawAverageByte

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

Moderator: Benj

Post Reply
Roy Johnston
Flowcode V4 User
Posts: 220
Joined: Mon Aug 24, 2009 8:38 am
Has thanked: 2 times
Been thanked: 34 times
Contact:

RawAverageByte

Post by Roy Johnston »

Am I correct in assuming that this function will continuous to run in background , irrespective of any other routines running.
in other words samples are taken all the time and averaged out, waiting for me to read them.
Thanks in advance.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RawAverageByte

Post by Benj »

Hello,

No there is no automatic sampling, the best way to do this would be to use a timer interrupt and accumulate the results yourself. Every time you take a reading you add it to the accumulated value and you increment a count variable so you know how many to divide the accumulated value by when you get around to needing the average.

The RawAverageByte basically takes the number of readings specified one after another in an optimised manner and then returns the average once complete.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: RawAverageByte

Post by mikn »

Benj, what's the problem with GetAverageByte?
When I use this function the whole chip is freezing.
Simple project is below.
Attachments
adctest.fcfx
(4.39 KiB) Downloaded 239 times
FC 6.1.3.2 (18.02.2016)

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RawAverageByte

Post by Benj »

Hello,

The idea is this we enable the ADC and allow it to charge to the external voltage. We then start the ADC conversion and collect the result, as a further optimisation we immediately start the next conversion before delaying so that we can pick up the result immediately after the delay and if needed start the conversion going again.

This also plugs into the RAW functionality which allows you to charge the ADC for a specific channel and then leave it enabled so you can capture readings at high speed without the precharge delay as with the standard ADC sample function.

Now the problem is that on some devices there seems to be a bug when reactivating the ADC conversion which means that the conversion never completes and effectively hangs the device. It might be that we have to change the ADC CAL for the 16-bit PIC family to completely get around the issue. I will have a play here and see if I can get the problem resolved without effecting the functionality too much for other families which do work as intended.

User avatar
mikn
Posts: 209
Joined: Mon Mar 03, 2014 10:11 pm
Has thanked: 54 times
Been thanked: 41 times
Contact:

Re: RawAverageByte

Post by mikn »

Understand, thanks. So for now I better use GetByte and get average value manually accumulating several values, right?
Can you advice me some method when I can get sound signal from analog input at 22-44khz frequency? When I use GetByte or RawSampleByte I can't get them so fast with interrupt set to that frequencies. The chip freezes, however it's written that this pic24 can get upto 200-300khz frequency samples. Should I go different way? The target is to get sound at 44khz and write to FAT.
FC 6.1.3.2 (18.02.2016)

Post Reply