• AVR Freaks

Hot!Interface dSPIC with external ADC

Author
gary36
New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2018/03/20 21:30:27
  • Location: 0
  • Status: offline
2019/11/22 07:24:59 (permalink)
0

Interface dSPIC with external ADC

I downloaded the latest version of dspic blocksets from github. I need to interface my custom board with external ADC. ADC I use AD7606 in parallel mode. Already I have C  code running into my target acquiring data from ADC. I want to acquire data through simulink. Can anybody explain the procedure to do so?
#1

9 Replies Related Threads

    Lubin
    Moderator
    • Total Posts : 397
    • Reward points : 5
    • Joined: 2007/03/31 07:38:15
    • Location: Bayonne, France
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/11/25 01:27:32 (permalink)
    0
    Hi Gary,
     
    The AD7606 is a SPI driven ADC. Could you try driving it with the SPI block ?
     
    To get further help with your problem, you should be more specific on the issue encountered. Maybe we can help.
    See examples provided with the blockset.
    #2
    gary36
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/03/20 21:30:27
    • Location: 0
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/11/26 01:52:45 (permalink)
    0
    Hi Lubin
    Thanks for the reply. I will try with SPI. IN the mean time I am stuck up with custom c function. I followed the examples. All I am trying to do is to toggle a port after a delay. This delay is my custom written. But some how the delay functions fail to execute. Toggle function executes properly.  Here is my code
     
    #ifndef  TOGGLE_H
    #define TOGGLE_H


    static unsigned char a;
    static unsigned int s;

    unsigned char toggle_bit(void)
    {
       a=a^0x01;
       return(a);
    }

    void delay(unsigned int val)
    {
       if(s!=val)
    {
      s++;
    }
    else
    {
     s=0;
    }
       
    }


    #endif
     
     
    #include "toggle.h"

    unsigned char check(void)  //In simulink I called custom C block with this name
    {
        delay(100);
        return(toggle_bit());
    }
    #3
    Lubin
    Moderator
    • Total Posts : 397
    • Reward points : 5
    • Joined: 2007/03/31 07:38:15
    • Location: Bayonne, France
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/11/26 02:17:12 (permalink)
    0
    Hi Gary,
     
    1. Use "while" instead of "if" ; Best to initialize s before the loop.
    2. Declare "s" as volatile variable to avoid optimisation. Best to declare s within your function scope.
    Watch out that compiler optimization that your delay function do not "get optimized" (i.e. detected as doing nothing, thus just dropped-out). Compiler provides built-in delay functions.
    #4
    gary36
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/03/20 21:30:27
    • Location: 0
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/11/26 02:38:28 (permalink)
    0
    Hi Lubin
     
    I tried with  __delay_us() function, but I get error undefined reference to __delay_us()
    #5
    Lubin
    Moderator
    • Total Posts : 397
    • Reward points : 5
    • Joined: 2007/03/31 07:38:15
    • Location: Bayonne, France
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/11/26 04:57:45 (permalink)
    4 (1)
    Gary, could you check that thread: https://www.microchip.com/forums/FindPost/783008
     
    #6
    gary36
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/03/20 21:30:27
    • Location: 0
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/11/27 01:11:40 (permalink)
    0
    Hi Lubin,
    Tried everything, but somehow I am unable to call one function in another. The code that I posted earlier does not work at all. No compilation error, program size changes, but nothing works. Hex files gets updated properly. I am using matlab 2014. Any program written within a function works. Sub functions called within a function are removed somehow by compiler. Please suggest.
    #7
    gary36
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/03/20 21:30:27
    • Location: 0
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/12/03 08:17:00 (permalink)
    0
    Hi Lubin
    With the C code working, I would like to acquire signal in external mode at 10KHz frequency and log in simulink. Would like to know the appropriate baud rate that will enable the acquisition. I have 4 int16 data to log for 2 seconds. Secondly I do not have UART-USB bridge. Alternatively can I use arduino to bridge between dspic and PC
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 18141
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: Interface dSPIC with external ADC 2019/12/03 11:03:06 (permalink)
    0
    so 4 *2 = 8 bytes
    8 * 10,000 = 80,000 bytes per second
    80,000 * (10 bits per byte) = 800,0000 bps
    so your Baud rate would need to be  800K minimum for real time.
    That sounds optimistic.  But not impossible.
     
    If you can Buffer the data then you can send it at any baud rate you want to.
     
    You can't Buy a UART-USB bridge?  
     
    #9
    gary36
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2018/03/20 21:30:27
    • Location: 0
    • Status: offline
    Re: Interface dSPIC with external ADC 2019/12/05 23:52:26 (permalink)
    0
    I managed to get UART-USB bridge. First I ensured it is working. Then hooked this module with dspic33 device TX/RX pin. Followed all directions as per https://www.microchip.com/forums/m665997.aspx. But I am unable to connect to target. Attached is the demo file I am trying to run. Let me know, where am I going wrong. Please provide a link or the document that explains in detail about PIL/external mode/HIL with examples. This would be easy without undue iterations
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5