• AVR Freaks

A question in using ADC in dsPIC33F

Author
ly
New Member
  • Total Posts : 10
  • Reward points : 0
  • Joined: 2010/12/21 19:47:19
  • Location: 0
  • Status: offline
2010/12/23 08:14:56 (permalink)
0

A question in using ADC in dsPIC33F

Hi Guys,

I have a project requiring real-time capture the over current pulse (3us) from any of 3 PHASE current fed into ADC channels and 3 temperature signals fed into another 3 ADC channels.

Now I plan to use dsPIC33J1MC202 due to its feature of "Simultaneous sampling of up to four analog input pins". I believe MCU can definitely capture such a 3us width pulse from any of three ADC channels however I have to decide whether it is over my error threshold after ADC conversion is done. Well, it will become a problem because the rest part of my code is large and code might spend lots of time there.  One senario could be that one pulse was sampled in ADC channel but it still could not do conversion. It has to finish the rest part of the code it is running at, then come to the sampled pulse, do the ADC, if the result is over my threshold, then trigger the error.... If it is like that, then from the error pulse detected to the error trigger may take a few hundred micro seconds.....

Is my understanding above right? If it is, then I probably can not use the dsPIC33F in this way.....

Thanks!


#1

7 Replies Related Threads

    sborden
    Super Member
    • Total Posts : 1932
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/23 14:26:48 (permalink)
    0
    Problem you have is Mr. Nyquist.

    He says that in order to capture a 3us event, you need to monitor at least in 1.5us intervals.

    Well, you might say, the dsPIC33 can (at 10bits) convert at 1.1Msps.  No Problem!

    Wrong. . .

    4 simultaneous sample and hold buffers! WOW!

    You have 3 channels. You have 4 buffers.

    You have 1 ADC.

    Means that you can "convert" the 3 channels at 1.1Msps.  But it means that you can only convert the 3 channels at 1.1/3Msps = 2.7us intervals.  To make matters worse, the PIC can only do 1, 2 or 4 samples, and not 3, which means you can effectively only convert the 3 channels at 1.1/4Msps = 3.6us intervals.

    It gets worse.

    Notice how I said "convert".  This is because the 1.1Msps does NOT include "acquisition" time.  OOPS!  Need to add another cycle because you are doing simultaneous sampling. So, now, your down to

    (sampling time + conv time) * num channels or

    (1TAD + 12TAD) * 4.  Min TAD=75ns, so 13*75ns*4=3.9us.

    In other words, you're %&&%ed.

    Even if you could calculate at that rate, you cannot get the samples in fast enough to do perform the calculations.

    Hate to be the bearer of bad news.
    #2
    aschen0866
    Super Member
    • Total Posts : 4482
    • Reward points : 0
    • Joined: 2006/01/08 22:18:32
    • Location: San Diego
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/23 14:47:05 (permalink)
    0
    ly
    I have a project requiring real-time capture the over current pulse (3us) from any of 3 PHASE current fed into ADC channels ...
     
    Are you saying that you'll get a 3us pulse when an over current condition occurs or you are actually getting the pulse all the time and it is the amplitude of this pulse that indicates an over current? I am just trying to understand why you need ADC for this 3us pulse...


    #3
    ly
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2010/12/21 19:47:19
    • Location: 0
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/23 16:56:40 (permalink)
    0
    aschen0866

    ly
    I have a project requiring real-time capture the over current pulse (3us) from any of 3 PHASE current fed into ADC channels ...
     
    Are you saying that you'll get a 3us pulse when an over current condition occurs or you are actually getting the pulse all the time and it is the amplitude of this pulse that indicates an over current? I am just trying to understand why you need ADC for this 3us pulse...


    The MCU always is measuring 3 phase currents through ADC. If there is an overcurrent in any of 3 phase current, it is usually a spike or a pulse which we should not let it last for over 3us. So, in my test, I will create such a 3us pulse to mimic over current spike. My concerns are

    1. I need to capture such overcurrent spike in any or 3 phase
    2. Once such spike was detected, ADC conversion should be done asap. Then, if such spike is a real overcurrent, an error should be triggered and shutdown signal should be sent asap..
    3. My code does not totally focus on ADC or over current detection. So, such over current detection should not affect other parts of the code....




    #4
    sborden
    Super Member
    • Total Posts : 1932
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/23 17:35:21 (permalink)
    0
    As I explained in my first post, you will not be able to detect and react to 3 events that quickly.  You can only get data at MAX 3.9us intervals.  To detect a "peak" you need 2 edges.  The only way for you to know that these two edges are from the same "event" is to sample 2 times within the time limit of the event.  This is the Nyquist Criterion, which you should have learned in school.  The problem is simple:
                                                                  
       +-----+      +-----+  +-+     +-- +
       |     |      |     |  | |     |   |                       
    ---+     +------+     +--+ +-----+   +-----
       A     B      C     D  E F     G   H
                                    
    If you want to detect the "length" of an event, you must detect the boudaries of the event. This means you must measure the time between A and B.  To do that you must detect when A low-high transition happens and also when B high-low transition happens. 

    If you cannot acquire data that fast, then you can completely miss an event or (if slow enough) even count between A and D as 1 event (known as aliasing), when in fact these are two events.  The ONLY way for you to GUARANTEE to catch a single event is to get the data at >2X of the SHORTEST interval you are trying to measure. 
    In  the case above, 1/2 the time of the E-F event.  This is the MINIMUM requirement to catch that an EVENT of 1/2 E-F duration took place because you know that regardless of where in or out of the event you collected the data, there is no way that you can miss the other boudary. 

    Simple proof: take ANY number and add 0.50000000000000000001.  You will always be between integer values either at the start or at the end, but never both. 
    But to know if the event is at least as long than E-F, you still need 2 points.

    And the fastest you can get two points is 7.8us
    #5
    ly
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2010/12/21 19:47:19
    • Location: 0
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/23 17:37:56 (permalink)
    0
    sborden

    Problem you have is Mr. Nyquist.

    He says that in order to capture a 3us event, you need to monitor at least in 1.5us intervals.

    Well, you might say, the dsPIC33 can (at 10bits) convert at 1.1Msps.  No Problem!

    Wrong. . .

    4 simultaneous sample and hold buffers! WOW!

    You have 3 channels. You have 4 buffers.

    You have 1 ADC.

    Means that you can "convert" the 3 channels at 1.1Msps.  But it means that you can only convert the 3 channels at 1.1/3Msps = 2.7us intervals.  To make matters worse, the PIC can only do 1, 2 or 4 samples, and not 3, which means you can effectively only convert the 3 channels at 1.1/4Msps = 3.6us intervals.

    It gets worse.

    Notice how I said "convert".  This is because the 1.1Msps does NOT include "acquisition" time.  OOPS!  Need to add another cycle because you are doing simultaneous sampling. So, now, your down to

    (sampling time + conv time) * num channels or

    (1TAD + 12TAD) * 4.  Min TAD=75ns, so 13*75ns*4=3.9us.

    In other words, you're %&&%ed.

    Even if you could calculate at that rate, you cannot get the samples in fast enough to do perform the calculations.

    Hate to be the bearer of bad news.


    Thanks for your analysis.

    I have another question here.  My code does not contain ADC only. When my code is running in some other portions, say LED or PWM or whatever. At this very moment, an over-current pulse is coming, well it may be sampled at an ADC channel, but it can not do ADC conversion immediately. It has to wait to do conversion until code loops back to the ADC part, then ADC can be done.  That means I have to wait for longer time to for ADC to be done...

    Is my understanding right? If it is right, then I think I have to think of using some hardware circuit for overcurrent trigger, then feed into external interrupt pin of a MCU....


    #6
    sborden
    Super Member
    • Total Posts : 1932
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/23 20:15:30 (permalink)
    0
    Don't mix CPU loading with A/D sampling.  You can process the data in probably less than 20 cpu cycles (30 with o'head), but you cannot get the data in fast enough for your purposes.  I won't even begin to get into a discussion about the A/D signal filtering required for this.  Although with a REALLY SHARP cut-off low-pass filter, you might get away with triggering, but you won't get what I call "good" measurements from the data, plus the more filtering, the more phase shift. . .

    Best advice, switch to a dsPIC33FJ16GS504 (44 pin) or dsPIC33FJ16GS502 (28 pin).  They can probably to what you want (4Msps conversions).  Worst case, with these two chips, is they have 4 built-in comparators you can use to auto-trigger on over-current.  These chips are designed for DC/DC and such stuff.
    #7
    ly
    New Member
    • Total Posts : 10
    • Reward points : 0
    • Joined: 2010/12/21 19:47:19
    • Location: 0
    • Status: offline
    Re:A question in using ADC in dsPIC33F 2010/12/24 20:28:24 (permalink)
    0
    sborden

    Problem you have is Mr. Nyquist.

    He says that in order to capture a 3us event, you need to monitor at least in 1.5us intervals.

    Well, you might say, the dsPIC33 can (at 10bits) convert at 1.1Msps.  No Problem!

    Wrong. . .

    4 simultaneous sample and hold buffers! WOW!

    You have 3 channels. You have 4 buffers.

    You have 1 ADC.

    Means that you can "convert" the 3 channels at 1.1Msps.  But it means that you can only convert the 3 channels at 1.1/3Msps = 2.7us intervals.  To make matters worse, the PIC can only do 1, 2 or 4 samples, and not 3, which means you can effectively only convert the 3 channels at 1.1/4Msps = 3.6us intervals.

    It gets worse.

    Notice how I said "convert".  This is because the 1.1Msps does NOT include "acquisition" time.  OOPS!  Need to add another cycle because you are doing simultaneous sampling. So, now, your down to

    (sampling time + conv time) * num channels or

    (1TAD + 12TAD) * 4.  Min TAD=75ns, so 13*75ns*4=3.9us.

    In other words, you're %&&%ed.

    Even if you could calculate at that rate, you cannot get the samples in fast enough to do perform the calculations.

    Hate to be the bearer of bad news.


    Hi sborden,

    I re-read your post many times. Now, I can say I have to give up using dsPIC33 even if it has so called ADC simultaneously sampling.

    Your calculation "(1TAD + 12TAD) * 4.  Min TAD=75ns, so 13*75ns*4=3.9us." manifests that I have to wait at least every 3.9us to expect another over current pulse coming. And, I might not capture anything if a short 2-3us pulse is coming when ADC is busy doing conversion.

    In addition, my case is even worse since I have another 3 termperature ADC which are doing sequential conversion
    SO, my total Waiting time = 3.9us + (1TAD+12TAD)*3 = 3.9us + 2.9us = 6.8us....Within this 6.8 waiting time, if a over current pulse is coming, I can not detect it at all....

    Okay, for sure, I will build some comparators to detect such over current and trigger an external interrupt to the MCU.

    thank you

    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5