Config settings for ADC

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

Moderator: Benj

Post Reply
Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Config settings for ADC

Post by Bobw »

I was looking at other post and in the help sections.
Can anyone point me to some reading on the configuration settings for an ADC?
ADCset.jpg
ADCset.jpg (67 KiB) Viewed 5613 times
The Vref I understand, Speed and cycles is what I want to read up on.

Bob

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: Config settings for ADC

Post by Benj »

Hello Bob,

Conversion Speed is basically the program cycle speed divided by a fixed value, e.g. on a 8-bit PIC the program cycle speed is 1/4 of the crystal speed and then say Fosc/4 is again divided by 4.

The FRC option is a oscillator independent value designed to give you a nice ADC conversion at any speed. As this is RC based it will fluctuate slightly depending on temperature and pressure.

The ADC conversion speed dictates the maximum number of samples per second as well as the accuracy of the conversion.

The Aquisition time is basically the pre-charge time where we allow the internal ADC capacitor to charge before the ADC conversion is started. If too short a delay then ADC channels will start to bleed into each other. If too long then there are no serious consequences apart from reducing the number of samples per second. If you are only sampling a single ADC channel then this can be reduced without any problems.

The PIC device datasheet details both the conversion speed and acquisition timings for various clock speeds.

Detailed component help is available from here: http://www.matrixmultimedia.com/wiki/in ... Components

Bobw
Posts: 157
Joined: Sat Jan 22, 2011 10:39 pm
Location: Michigan
Has thanked: 6 times
Been thanked: 27 times
Contact:

Re: Config settings for ADC

Post by Bobw »

Ben,
Just what I needed.
Kind of thought that is what the settings were for.
Suggestion for the next release, In the picture I showed above, Place a ? or help box that would link to the proper place in the WIKI page you gave me the link for.
Save other users from trying to dig around for the correct information.
I am liking version 6 but the SIM runs way slow.
Bob

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

Re: Config settings for ADC

Post by mikn »

If I need to capture analog signal from the microphone at 16khz which settings should be better for the adc component?
FC 6.1.3.2 (18.02.2016)

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Config settings for ADC

Post by kersing »

mikn wrote: If I need to capture analog signal from the microphone at 16khz which settings should be better for the adc component?
What chip are you using? On some 16 bit PICs you could use interrupts or even DMA to handle ADC. You will need an amplifier of some sort for a microphone. For example code on using interrupts combined with DMA to read at 20kHz you can check http://www.matrixmultimedia.com/article.php?a=688. (Uses dsPIC33FJ128GP802)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

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

Re: Config settings for ADC

Post by mikn »

It's easier for me as I have working hardware with another firmware. Chip is pic24fj.
Just wondering if I am on the right way. Now I set up the timer to 8khz and capture the data with adc.GetByte function then write it to sd card as raw data.
But the problem for me now is that when I set timer frequency to 16 khz or more it freezes. Seems like adc overloads and stop the whole process. Tried to play with conversion speed and aquisition times, something changes but not much. I can't capture more than 8khz. Are there any tricks?
FC 6.1.3.2 (18.02.2016)

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Config settings for ADC

Post by kersing »

I suspect using ADC GetByte in an interrupt will consume too many cycles. GetByte waits the acquisition time (default 40 microseconds) for every sample you take. That means at 25000 samples a second (=1/40 microseconds) the controller does nothing besides waiting the acquisition time. If there is anything else in the interrupt routine that takes significant time all cycles will be spend handling the interrupt routine. When it is done with one interrupt the next will have occurred and no other code will get any cycles.

So basically I do not think using ADC GetByte is the right way to do this. I would look into configuring the ADC to continuously sample using a timer to determine the sample rate and use the ADC interrupt to get the data byte (if available on your controller).

What is the exact chip? Do you have the source of the other firmware?

BTW, quote about acquisition time from Bens message above:
Benj wrote: If you are only sampling a single ADC channel then this can be reduced without any problems.
So you could reduce the 40 to something like 1. (Do not use 0)
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

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

Re: Config settings for ADC

Post by mikn »

What is the exact chip? Do you have the source of the other firmware?
pic24fj64ga002
No I don't have source for other firmware.

So you could reduce the 40 to something like 1. (Do not use 0)
Yes, during playing with settings I did reduce to 1 and even to 0, it worked but again I could not raise interrupt frequency more than 8khz (well, actually I've tried 2khz, 4khz, 8khz, 16khz...)
kersing wrote:I would look into configuring the ADC to continuously sample using a timer to determine the sample rate and use the ADC interrupt to get the data byte (if available on your controller).
Could you tell me more on this? Some example will be helpful, as I don't understand clearly how to do continuously sampling using FC
FC 6.1.3.2 (18.02.2016)

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Config settings for ADC

Post by kersing »

I don't think continues sampling can be done in FC without using C code icons. The general sequence would be something like:

Setup ADC1 to sample your input.
Set it to start sampling upon Timer 3 compare
Set it to generate an interrupt for every sample.

Add an custom interrupt handler to get the sample value from the ADC register
Setup timer3 for the required frequency.

Parts of the code can be borrowed from the example I referred to in my previous message.

I should have some time to create example code after next weekend, not before...
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply