• AVR Freaks

Hot!Cheap ($12) logic analyzer project using dsPIC33EV256GM102

Author
trossin
Super Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2006/06/02 11:31:50
  • Location: 0
  • Status: offline
2020/12/17 19:10:59 (permalink)
4.8 (5)

Cheap ($12) logic analyzer project using dsPIC33EV256GM102

For some reason, I've been making logic analyzers off and on for the last 35 years ever since I used an HP instrument in college.  There are links on my web page to some of my older machines (the oldest one is based on raw TTL and an 1976 RCA microprocessor for display).  I am very new to the dsPIC but have been using the 8-bit PIC devices since the early 2000s.  This latest design can be implemented on a solderless breadboard. 
 
I just got 16 and 8 bit mode working and below are the specs:
  • 16 channel 8178 samples with 45ns/sample to 250us/sample
  • 8 channel 16,356 samples with 45ns/sample to 250us/sample
This uses a dsPIC33EV256GM102-I/SP (28 pin skinny DIP).  The schematic and code can be found here:
 
    https://www.sites.google....n/home/electronics/pic
 
I still have more to learn and code (4,2 and 1 bit mode and get the A/D working and be able to update firmware on the fly).  I was not able to get 30ns/sample as reading a port takes two instruction cycles but 45ns is a good boost over my previous design (18F26K40) which maxed out at 125ns/sample.
#1

18 Replies Related Threads

    RISC
    Super Member
    • Total Posts : 5960
    • Reward points : 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2020/12/22 06:39:38 (permalink)
    4.5 (2)
    Hi,
    You've done amazing projects Smile: Smile
    If you like Logic analyzers, you could probably take advantage of the multiple 12 bits ADCs which exist in the latest dsPIC33CH.../CK...With this family you can achieve more than 10Msps
    regards
    post edited by RISC - 2020/12/22 06:41:09

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #2
    NorthGuy
    Super Member
    • Total Posts : 6518
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2020/12/22 07:59:31 (permalink)
    0
    trossin
    I was not able to get 30ns/sample as reading a port takes two instruction cycles but 45ns is a good boost over my previous design (18F26K40) which maxed out at 125ns/sample.



    The dsPIC33E and dsPIC33C CPUs take 2 cycles to read port because they're designed to run fast. You can use older dsPIC33F which you can run ut to 40 MHz. dsPIC33F will read the port in one cycle (25 ns/sample if run at Fcy = 40 MHz). The GS series of dsPIC33F can run at 50 MHz at normal temperature, which gives you 20 ns/sample.
     
    dsPIC33C devices can run at 100 MHz, but since they take two cycles to read PORTx, you can only reach 20 ns/sample, same as dsPIC33FxxGS.
     
    Also, make sure you use the non-overhead "repeat" instruction to sample. This will let you sample at every clock.
     
    $15 Spartan-7 will take you below 500 ps/sample.
    #3
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2020/12/22 21:31:48 (permalink)
    4.5 (2)
    Thanks for the info. I do use the zero overhead loops. Just reading the port is half the problem. I also have to store the sample in RAM. So, it takes 3 instruction cycles per sample.

    It is hard to put an FPGA on a solderless breadboard 😀. I have seen some development boards for $30 but I have not seen recent FPGAs that have 5V tolerant I/Os.

    I did build an analyzer using CPLDs and fast RAMs but it is not cheap or easy to build

    https://www.sites.google....ilinx#h.p_l1G8E54LKF7X
    post edited by trossin - 2020/12/22 21:38:19
    #4
    blue_led
    New Users
    • Total Posts : 87
    • Reward points : 0
    • Status: online
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/08 19:27:10 (permalink)
    0
    I was thinking of making a logic analyzer using spi memories, data feeding SI input,  with some gates ( 2:1 multiplexor ) in front, for memories control words. Any low MCU can drive this setup.
    #5
    David
    Pic User
    • Total Posts : 1368
    • Reward points : 0
    • Joined: 2007/12/17 23:19:53
    • Location: uk sussex
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/08 20:05:08 (permalink)
    0
    trossin
    For some reason, I've been making logic analyzers off and on for the last 35 years ever since I used an HP instrument in college.  There are links on my web page to some of my older machines (the oldest one is based on raw TTL and an 1976 RCA microprocessor for display).
      https://www.sites.google....n/home/electronics/pic



     
    I enjoyed looking around your site :) I hope the ducks are well :)

    David
    I support http://picforum.ric323.com because this forum is often too broken to use!
    #6
    NorthGuy
    Super Member
    • Total Posts : 6518
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/08 22:21:07 (permalink)
    4 (1)
    trossin
    Thanks for the info. I do use the zero overhead loops. Just reading the port is half the problem. I also have to store the sample in RAM. So, it takes 3 instruction cycles per sample.



    You can do both in one instruction, for example:
     

    mov.b [w0],[w1++]

     
    where w0 points to PORTA (or whatever) and w1 points to the buffer. So, it's 2 instruction cycles per data point in E/C, or 1 instruction cycle per data point in F.
    #7
    MBedder
    Circuit breaker
    • Total Posts : 6969
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/09 04:00:53 (permalink)
    2 (2)
    This is neither cheap nor good. You will never ever be able to beat the price and quality of Chinese mass prodicts like this ($3.80 @24 MHz)
    #8
    RISC
    Super Member
    • Total Posts : 5960
    • Reward points : 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/09 14:41:25 (permalink)
    0
    Hi,
    MBedderThis is neither cheap nor good. You will never ever be able to beat the price and quality of Chinese mass prodicts like this ($3.80 @24 MHz)

    Incredible....for this price you don't even get a USB cable wink: wink
    Regards
     

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #9
    ric
    Super Member
    • Total Posts : 29861
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/09 14:52:09 (permalink)
    4.5 (2)
    RISC
    Hi,
    MBedderThis is neither cheap nor good. You will never ever be able to beat the price and quality of Chinese mass prodicts like this ($3.80 @24 MHz)

    Incredible....for this price you don't even get a USB cable wink: wink
    Regards

    Actually, you don't.
    I bought one of these clones, and the supplied USB cable was faulty.
    Dropped that in the pin and used another cable, and it's worked fine since.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/09 21:59:15 (permalink)
    5 (2)
    Thanks for the mov [w0],[w1++] trick. I’ll give it a try tomorrow . I tried the simulator and it claimed that it took one cycle. It should at least be two due to the port read wait state. Hopefully, there is not a write after read penalty. If all goes well, this will take it from 45ns (22 M samp/s) down to 30ns (33Msamp/s). That would be super.

    I just converted to use the dsPIC33EP512MC202 and now get 24K samples in 16 bit mode and 49K in 8 bit mode.

    I’m sorry that this does not live up to your definition of good MBedder. My goal is not to sell this but to share for educational or hobby use a project that can be home built.
    #11
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/09 21:59:15 (permalink)
    0
    Thanks NorthGuy!  I verified that your code only takes two cycles.  Below are the max sample rate code for 16 and 8 bit mode.  I have verified with a  250KHz and 10 MHz source that these two are producing a sample rate of 30ns/sample (33.33 Mega samples/second) when clocking the dsPIC at 66.666 MInstructions/sec. 
     
    Sample16Max: 
    mov #PORTB,w1
    repeat #NUM_SAMPLES-1 ; Thanks to Microchip forum member NorthGuy for this secret
    mov [w1],[w7++]
    bra SampleComplete

    Sample8Max:
    mov #PORTB,w1
    repeat #32000-1 ; Thanks to Microchip forum member NorthGuy for this secret
    mov.b [w1],[w7++]
    repeat #(2*NUM_SAMPLES-32000)-1
    mov.b [w1],[w7++]
    bra SampleComplete
     
    I need to do some math and coding to get 50ns/sample back, some C++ Visual Studio 2019 fun and then testing before I'll update the code on the web.  It is nice that I got the live firmware update working so that I don't need to involve the PICkit3. 
     
    The new dsPIC I'm using gives 16 channel mode 24,562 samples and 8 channel mode 49,124 samples.  I plan on coding up the smaller channel counts soon: 4 channel(98,248 samples), 2 channel(196,496 samplse) and 1 channel mode (392,992 samples).  At the slowest sampling rate (250us/sample), 8 channel mode is able to store 12.28 seconds of samples.  At 2us/sample (fast enough for 400KHz I2C), you can sample 98ms of time.  When I get 1 channel released, you can sample a little over 3/4 second of time at 2us/second.  I don't trust streaming over USB but I may add that one day for slower sampling rates to get near infinite storage.   The screen update rates get crazy slow at long sampling rates so I'll implement some features that I put on my CPLD based machine:
    • Window mode where I only upload the current displayed window.  If you zoom out, it will upload missing samples to fill the display.
    • Simulated status LEDs to show when the trigger has been found and while it is acquiring samples
    • Sample memory limits to allow retriggering quicker.  Sometimes just getting 500 to 1000 samples after the trigger is all you need.
     
    post edited by trossin - 2021/01/10 10:25:35
    #12
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/10 11:09:04 (permalink)
    0
    Crap. As soon as I think I’m set l realize 8 bit mode is crap due to a time slip caused by the 2nd repeat instruction. I’ll have to implement the 2nd repeat with 2*NUM_SAMPLES-32000 mov instructions. Luckily this device has a crap load of code space. I just need to learn the as16 directives to generate code like I used with MPASM for the 8 bit PICs
    #13
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/10 11:09:05 (permalink)
    4 (1)
    Double post due due no feedback on reply button
    #14
    NorthGuy
    Super Member
    • Total Posts : 6518
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/10 12:20:55 (permalink)
    0
    trossin
    Crap. As soon as I think I’m set l realize 8 bit mode is crap due to a time slip caused by the 2nd repeat instruction. I’ll have to implement the 2nd repeat with 2*NUM_SAMPLES-32000 mov instructions. Luckily this device has a crap load of code space. I just need to learn the as16 directives to generate code like I used with MPASM for the 8 bit PICs



    There's a form of "repeat" which takes a register (as opposed to literal). When you use it, you should be able to pass full 16-bit counter (on E devices).
    #15
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/10 18:30:59 (permalink)
    0
    Thanks again for pointing me in the right direction. I got it working with the assembler rept pseudo opt but will recode using a working register to make firmware updates quicker.

    I did get the PC code updated as well as the PIC code and the new versions are on my web page. I have 30ns, 50ns, 150ns, and other setting up to 250us tested out in 8 and 16 channel mode. Also, lots of firmware update testing as I was coding.

    I’ll switch to a working reg from a constant and start on some of the other features.

    Thanks again NorthGuy.
    #16
    GlennP
    Super Member
    • Total Posts : 852
    • Reward points : 0
    • Joined: 2009/03/29 15:04:55
    • Location: El Paso County, CO, USA
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/11 01:55:44 (permalink)
    3.5 (2)
    Just FYI (I know it's moot for this as your next post covers a silicon test): Simulator cycle counts are not always accurate.  See this thread: https://www.microchip.com/forums/FindPost/1152516.
     
    If you look at George Pauley's reply, MCHP has basically given up on getting the counts correct in the simulator.
     
    GlennP
    #17
    Howard Long
    Super Member
    • Total Posts : 887
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/11 13:30:24 (permalink)
    0
    OP: great website, very inspiring!
    #18
    trossin
    Super Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2006/06/02 11:31:50
    • Location: 0
    • Status: offline
    Re: Cheap ($12) logic analyzer project using dsPIC33EV256GM102 2021/01/21 18:44:53 (permalink)
    5 (1)
    I added 2 and 1 channel mode, cleaned up the loops, added trigger detected and sample cancel code to the DsPIC code.  The cancel code is a must in 8,4,2 and 1 channel mode.  For example, in 1 channel mode, the PIC can store 392,992 samples and at 250us/sample, it takes 98 seconds to fill memory.  I did a lot of clean up in the PC application and added some virtual LEDs to display when the PIC is waiting for a trigger, acquiring samples and uploading samples from the PIC to the PC.  I also implemented a window upload mode to speed up the update rates when the display is zoomed in.
     
    The new code is on my web page (you need the PC and PIC code) along with a you-tube video showing the machine in action.  The PIC code can be updated using the PC code (firmware update). 
    #19
    Jump to:
    © 2021 APG vNext Commercial Version 4.5