different sampleus time for three ADCs


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2015
    Posts
    13

    Default different sampleus time for three ADCs

    I've seen the manual and suggest to use DEFINE ADC_SAMPLEUS X
    but when I need different values for them, in my case 10000 for ADC1 and 1000000 for ADC2 AND ADC3, How can I do it if there is only one sampleus definition?
    I suppose this don't interfere with interrupt clock operations or any retard to the program.

    Thank you in advance
    Luis

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    it's so easy to use the ADCs directly it hardly worth using the built-in ADC functions. In this case I guess in this case you have to.
    George

  3. #3
    Join Date
    Nov 2015
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    So nobody there knows how to use different sampleus times for several ADCs on 18F4550 or any other with several ADCs? I'm using picbasic pro.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    DEFINE is a compile time directive so it can not be used to change stuff at runtime. I don't know how ADCIN works under the hood, ie if it's simply adding a PAUSUS for the duration of the sampletime or if it's actually setting acqusition time select bits of the ADC (which on the 18F4550 is in the ADCON2 register.)

    If you need to change the acqusition time during runtime you're better off driving the ADC manually - which I believe you've received as an answer already.

    Read chapter 21 in the datasheet a couple of times. It explains how to calculate the minimum conversion clock cycle time (TAD) as well as the minium acquisition time (TAcq). The acquisition time is derived from the TAD so you need to choose a TAD which allows for a long enough acqusition time.

    /Henrik.

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    "So nobody there knows how to use different sampleus times for several ADCs on 18F4550 or any other with several ADCs? I'm using picbasic pro. "

    Well, For starters, there is only 1 10 bit A/D converter on board the PIC in question. Second thing is why would you want to change the sampling time? Are you changing the oscillator frequency? If the oscillator frequency is the same for all operations then, look at the data sheet and set the DEFINE ADC_SAMPLEUS to the minimum for the oscillator frequency being used. That way you get the quickest A/D settling time and quickest A/D conversion.
    Last edited by Dave; - 16th May 2016 at 22:23.
    Dave Purola,
    N8NTA
    EN82fn

  6. #6
    Join Date
    Aug 2011
    Posts
    412


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    I wonder if the OP is confusing the sample time with some sort of automatic period for reading the ADC? The times he's mentioning are way too long for just the sampling delay after changing the channel.

  7. #7
    Join Date
    Nov 2015
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    As you can see, I'm new to this.
    Since I'm using Pic Basic Pro, I use ADCIN and sampleus time
    What I want is to get ADCIN 0 each time required for the program (velocitiy), and ADCIN 1 and ADCIN 2 each two seconds alternatively, because they are temperature measurements that I don't need in a shorter frecuency, so I would preffer to have ADC in a mode that don't use procesor time. I was thinking on something like @ ADCON0.1=0 (go/done bit) to stop it when no needed, and start it again later, but then I was asking myself if the ADC simple works without interfering with the rest of the program when I don't use ADCIN. I don't know. I hope somebody knows that.

    The original though was that the sampleus time could determine this 2 second periods alternated, 4 seconds each, although I think now that sampleus can be short and the time to get the readings be determined by program as the example below.

    My concernings are two:
    1. The ADC could use a lot of procesor time or worst: that it breaks the USB connection I'll have
    2. That a big sampleus time be the one taking the procesor time

    ---------------------------------
    ' THIS TAKES TIME FROM TICS ONLY FIRST TIME
    if banderaTpoini=0 then ' bit solo la primera vez toma tiempo
    tpoini=centesimas1 ' word
    banderaTpoini=1
    endif

    ' THIS ADD THE TIME BETWEEN READINGS
    if banderaSumarRet=0 then ' bit, suma retardo para tomar temperatura
    activarADTemp = retardoTomarTemp + tpoini 'word
    endif

    ' IF OVERFLOW COUNTER
    suma= activarADTemp ' word, ComparaT
    if suma >= maxT1 then ' 4000 sobrado para tmpos máq. una v. Word
    activarADTemp= suma - maxT1 '
    endif

    '---------------------------------------------
    ' En declaraciones
    temp=0 ' bit
    dejar un define sampleus chico, tal vez 100

    ' IF TIME NOW, ALTERNATE READINGS
    if centesimas1>= activarADTemp then
    if temp=0 then
    temp=1
    ADCIN1 ' HERE READING AND MORE CODE
    else
    temp=0
    ADCIN2 ' HERE READING AND MORE CODE
    endif
    tpoini= centesimas1
    banderaSumarRet=0
    ' ¿Apaga AD Go/done? Sería con @ ADCON0.1=0 y reponerlo antes de ADCIN 'HERE SHUT DOWN ADC
    ' I WOULD PUT IT ON BEFORE READING
    endif

    THANK YOU VERY MUCH FOR YOUR COMMENTS

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    Hi,
    That's simply not what DEFINE ADC_SAMPLUS does and it's not how PBP in general works.
    The ADC does not run continuously in the background (well, it CAN on some devices but for those ADCIN doesn't work anyway).

    If you want a reading every second you need to execute the ADCIN command once per second. There are of course many different ways of getting that done depending on your particular needs. The easiest way might be to simply have a counter that keeps track of how many times you've sampled the "fast" channel. If that's 1000 times per second then count to 1000 before sampling the "slow" channels. Another approach is a timer interrupt or using a timer/CCP module and a special events trigger. Since you're still new to this I recommend the simple approach to begin with.

    DEFINE ADC_SAMPLEUS tells the compiler how long a delay it needs to insert between selecting the channel to sample and actually starting the conversion. During this time nothing else gets done. If you set it to 1 second the program will stop for a second while the the S/H capacitor charges - it's not what you want.

    /Henrik.

  9. #9
    Join Date
    Nov 2015
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    Well, thank you very much, I think I understood what is needed. I'll set at about 50 us the sampleus time and set with the program the time it has to read the ADCINs.

    I can't mantain this more simple because I'm solving a complex machine with this. I'm controlling temperatures, velocity with a variator, interface with a tablet, etc. The program has growed more than 800 lines and is not finished. I had to deal with scaling and convertions, with real time programming techniques, about 60 parameters, (5 months already) and other details, but it is funny to go completing the puzzle and more the day I put it to work. And this is a machine for my sister, so I'm a volunteer. There are days I think it is too complex so I make some other things, but there are days I advance very well, or nights. I had to implement Bates ejercices for my eyes, one of the more demanded parts in this project, but although it has taken much more time than I thought, it is going well thanks to the help I obtain like this.

    In fact, the next project like this I would evaluate to use a C based compiler because I won't have to scale anything (it uses float vars) and it seem to have more documentation.

  10. #10
    Join Date
    Nov 2015
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    That of C based compiler was a joke for which I expected some reaction, but nobody told anything!

  11. #11
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: different sampleus time for three ADCs

    [reaction]
    That’s a great idea, I’d recommend Microchip C-30 for exactly that reason among others.
    PBP is very well documented, however you’ll notice all examples of command use are also examples of exactly how not to write a cyclic program.
    ie. a program that gives the illusion of simultaneity.
    [/reaction]
    If it’s a cyclic program that will be broken if delayed, have you considered an external ADC chip? Not that I’ve used one.
    Last edited by Art; - 22nd May 2016 at 12:47.

Similar Threads

  1. PIC 18F1330 - first time, hard time - blink that LED
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st March 2015, 22:33
  2. How best to time a pin state for extended periods of time
    By Hylan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 10th March 2011, 11:20
  3. DS1904 RTC - How to Convert Binary Time into Real Time/Date?
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd December 2010, 10:45
  4. ADCIN Sampleus time question
    By LinkMTech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th February 2009, 18:28
  5. Linx RF -> HSERIN time delay / time critical app...
    By batee in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th October 2004, 15:04

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts