• AVR Freaks

Hot!controller dsPIC33F family controller

Author
ashvin
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2019/11/18 03:59:01
  • Location: 0
  • Status: offline
2019/12/11 06:21:52 (permalink)
0

controller dsPIC33F family controller

hello,
i have used a controller dsPIC33FJ16GS504 for my project purpose but when i search example code in which i found adc conversion value is in range from 0 to 1023 (for 10-ADC used) but after completing that they convert data into particular format like Q15 format or Q14 format.
my question is that why used different format like Q15, Q14 and how to converter in this format.   
#1

8 Replies Related Threads

    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3510
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/19 10:37:58 (permalink)
    0
    Q1.15 is a fixed point number format that works with numbers less than 1. ie. a fraction of 1.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #2
    Bob White
    Super Member
    • Total Posts : 277
    • Reward points : 0
    • Joined: 2010/11/06 19:52:38
    • Location: Denver, Colorado
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/19 11:08:31 (permalink)
    0
    The advantage to the Q format is that if you multiply two numbers there is never any overflow.  Multiplying two 16 bit Q-numbers still gives you a 32 bit result, but the accuracy lost when when the lower 16 bits are dropped to make a new 16 bit value is minimized.
     
    You can think to conversion to Q format as a scaling or normalizing operation.  It is up to you to keep track of the scale or normalization factors.

    Here is a link the Wikipeda article on Q format numbers:

    https://en.wikipedia.org/wiki/Q_(number_format)
    #3
    NorthGuy
    Super Member
    • Total Posts : 5880
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/19 13:57:21 (permalink)
    0
    You can re-configure ADC (with ADCON1.FORM) to produce results in Q15 format directly, so there's no need to convert.
    #4
    ashvin
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2019/11/18 03:59:01
    • Location: 0
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/20 05:11:57 (permalink)
    0
    ok! as per your discussion it is a Q- fixed point format is right but my question is that i studied one example in code like that
    my ADC is 10 bit so its buffer register store value up to 1023
    example,
    an0 = ADCBUF0;    // 10-bits register so value is up to 1023
    but in given code for some application
    they write as below and said that it is a format of Q15
    an0 = ADCBUF0 << 5;
     
    now, my question is that way its called Q15 format and they also convert into Q14 format
    how to converter Q14 format
    example
    an0 is Q15 format as per above example
    now an1 is in Q14 format how its possible..... or why do that way
    an1 = ((ADCBUF1 << 5) - an0);
    #5
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3510
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/20 10:10:39 (permalink)
    0
    The proper name is Q1.15 (1bit for sign, 15 bits for the fraction)
    It represents numbers approx.
    0.11 bin to 0.75 dec
     
    post edited by Gort2015 - 2019/12/20 10:12:06

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #6
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3510
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/20 10:23:40 (permalink)
    0
    Some chips support Q1.128 to get better accuracy, it is still an approximation.
     
    if you read a value of 511 from analogue and the voltage was 5v then 0.5.
     
    To make that a Q1.15 number:
     
    (1 << 14) * ((511 + 1) / 1024)
    0.1 bin
    0.100,0000:0000,0000
     
    Probably where you saw 14.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #7
    crosland
    Super Member
    • Total Posts : 1739
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/20 11:09:22 (permalink)
    0
    Gort2015
    The proper name is Q1.15 (1bit for sign, 15 bits for the fraction)

    That depends. Qx.y can also mean x integer bits and y fractional bits
    #8
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3510
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: controller dsPIC33F family controller 2019/12/20 13:23:29 (permalink)
    0
    If using a dspic then it will be Q1.15 or Q1.31 when using the specific h/w registers and instructions.
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5