Long Variables can be negative?


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Hi,
    Yes, LONGs can only be used on 18-series parts. Do you need to do any math etc on that 32bit variable or are you just trying to store it? If you only need to store it then simply use an array of 4 bytes. If you need math you could always take a look at Darrels N-Bit math routines which will allow you to declare variables of "any" size and do math with them.

    /Henrik.

  2. #2
    Join Date
    Jan 2005
    Location
    France
    Posts
    97


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Thanks Henrik for this quick answer
    But it is "too much" for my old brain !
    Darrel has done a great job , as usual !
    yes I have just one calculation (I got the Arduino code)
    something like that
    unsigned long tuning_word = (frequency * pow(2, 32)) / DDS_REF
    frequency will go from 1 to 39 millions
    DDS_REF is 125 millions
    and I must decode what is the POW(2,32) !
    For this need I think that I will order an Arduino board !

    Happy new year for everybody
    and all my congratulations for this very nice help forum, it is great
    Francois F1CHF (radio amateur) 65 years old now ....

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Hi,
    Ah, it's that AD9850 DDS chip again, I've got a couple of those on their way to play with as well.
    pow(2,32) simply means 2 raised to the power of 32, sometimes written as 2^32 (not in PBP though) or, spelled out, 4 294 967 296. So in reallity your formula looks like unsigned long tuning_word = (frequency * 4294697296) / 125000000

    Knowing that you could shorten it to Tuning_Word = frequency * 34.3597 (where 34.3597 simply is 2^32/125M). Obviosuly non integer numbers like that 34.3597 won't fly with PBP but we could do Tuning_word = frequency */ 8796 which would be like saying tuning_word = frequency * 8796 / 256.

    Now, lets see if this works out, first with the original formula for a frequency of 500Hz
    Tuning_Word = (500 * 4294697296) / 125M = 17179
    And then for our PBP way of doing it
    Tuning_Word = 500 * 8796 / 256 = 17179

    Now, this would still only allow frequencies up to around 1900Hz after which a WORD variable will overflow. There might be a way around this but before I spend more time on it would be nice if
    A) You could verifu that the above actually works in frequencies <1900Hz and
    B) Let me know it you don't concider switching to an 18F device would be easier.

    /Henrik.

  4. #4
    Join Date
    Jan 2005
    Location
    France
    Posts
    97


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Hi Henrick
    Mister "maestro's number" ... hi !
    Yes I have ordered a AD9850 kit from ebay item 140776695890
    I got the software from here http://f5mna.free.fr/dds.htm
    I got PCB + LCD from here http://f6kbf.free.fr/pdf/Synfoxny.zip
    my objective is to generate frequency between 25 and 28 Mhz
    to play with a LNBPLL ebay item 320886789074
    I satrt to remove the 27 mhz quartz and with a generator (ADRET) I am abble
    to synchronize the pll to have different Local oscillator frequency, and the most
    important is that the oscillator accep to go on 10.368 Ghz .... it is super to have a beacon for peanut !
    so you know the complete story
    You are right, if I can find a 18Fxxxx instead of the 16Fxxxx this is the solution with PBPL compiler
    I can start the process with your example to check at least the basic (< 1900 hz) function
    hold the line ...
    my email is F1CHF at free.fr (in the case of direct messages )
    best regards
    Francois F1CHF

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,621


    Did you find this post helpful? Yes | No

    Default Re: Long Variables can be negative?

    Hi Francois,
    Actually I'm not that great at math so don't take everything I write for granted....that's why I asked you verify it.

    What type of accuracy do you need - realistically? I've been playing with it this afternoon and just now tried 25, 26.5 and 28MHz and the calculated tuning values are all at 99.99894% of the optimal one. This means that when you ask for 28MHz you'll get 27.9997MHz, or ~300Hz off your nominal center frequency. Is that too far off? (I'm not sure I could do better with using LONGs though).

    It uses Darrels N-Bit routines so it should work fine on a 16F device. However you still won't be able to simply enter a frequency value directly in Hz since there are no variable size big enough to hold that value directly. Instead the frequency value is "built" by two word size variables. However, if the desired frequency could be entered in units of kHz instead, like 26500 for 26.5MHz then I could probably add that pretty easily.

    I'm no radio guru so I don't understand all of what you're saying, especially the part with the peanut and 10.368Ghz...are you building a microwave for zapping peanuts? :-)

    /Henrik.

Members who have read this thread : 1

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

Posting Permissions

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