Clock Gen Click set Frequency call only Integer values?

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
ACSJeff
Posts: 33
Joined: 18 Jun 2015 23:48

Clock Gen Click set Frequency call only Integer values?

#1 Post by ACSJeff » 15 Jun 2020 17:58

Hello,

I finally got the Clock Gen Click library to work in my MikroBasic Project.

This is the click board that uses the Si5351a chip.

The demo example for my PIC18F45K22, the one that comes installed on my Easy Pic 7 Pro board, works great.

I see the frequencies changing with the following code:

Code: Select all


    'Set Frequency to 5Mhz
    clockgen_set_frequency(CLOCKGEN_CLOCK_0, CLOCKGEN_PLLA, 5)
    Delay_ms(1000)

The O-scope shows close to 5mhz solid. Great.

But why was the clockgen_set_frequency written to only accept LongWord Integer values??? If I want say 3.315 Mhz, I cannot use this procedure! I do not wish to use the other functions to and have to manually calculate all the frequency values, then send writes to the Si5351a. It looks as if I am forced to do this.

I realize that the author got us most of the way there, but the math is ugly and If the author could provide an alternative example, like setting the frequency to 3.315 Mhz, I would greatly appreciate it!

thanks

Jeff

ACSJeff
Posts: 33
Joined: 18 Jun 2015 23:48

Re: Clock Gen Click set Frequency call only Integer values?

#2 Post by ACSJeff » 16 Jun 2020 16:14

Ok I'm a little closer, I've decided to use the built in functions but I'm nowhere near close to the frequency I need. Here is my attempt to create a procedure that uses Hertz instead of Mega Hertz. My Target Frequency is 10 Mhz (10000000 Hz):

Code: Select all

 	dim pllFreq as LongWord
        dim xtalFreq as LongWord
        dim l as LongWord
        dim f as float
        dim mult as byte
        dim num as LongWord
        dim denom as LongWord
        dim divider as LongWord

        'xtalFreq = XTAL_FREQ
        
        'HardCodes
        xtalFreq = 24999610
        frequency = 10000000  'TEST 10Mhz Frequency in Hertz
        
        
        divider = 900000000 / frequency   ' With 900 MHz being the maximum internal PLL-Frequency

        'Find Even divider.  If Mod returns a positive, then decrement by 1
        if (divider mod 2) > 0 then
           divider = divider -1
        end if
    
        pllFreq = divider * frequency           'Calculate the pllFrequency: the divider * desired output frequency
        mult = pllFreq / xtalFreq               'Determine the multiplier to get to the required pllFrequenc

        l = pllFreq Mod xtalFreq                    ' It has three parts:
        f = l                                         		' mult is an integer that must be in the range 15..90
        f = f * 1048575                                  ' num and denom are the fractional parts, the numerator and denominator
        f = f / xtalFreq                                 ' each is 20 bits (range 0..1048575)
        num = f                                            ' the actual multiplier is  mult + num / denom
        denom = 1048575                              ' For simplicity we set the denominator to the maximum 1048575


        'Setup PLL
        clockgen_setup_pll(SI_SYNTH_PLL_A,mult,num,denom)
        
        'Setup Multi Synth
        'Not sure what factor is in this call(last parameter) -> setting to 1
        clockgen_setup_multisyinth(CLOCKGEN_CLOCK_0,divider,num,denom,1)
If I run the above code, My O-scope says Clock 0 is running at 943.4 kHz

Can anyone identify what I am doing wrong?

User avatar
jovana.medakovic
mikroElektronika team
Posts: 986
Joined: 18 Dec 2018 10:36

Re: Clock Gen Click set Frequency call only Integer values?

#3 Post by jovana.medakovic » 17 Jun 2020 15:01

Hello,

In the attachment, you can find the source code of Clock Gen Click board, so you can try to adapt it to your needs.

Kind regards,
Jovana
Attachments
library.zip
(40.95 KiB) Downloaded 80 times

Post Reply

Return to “Library Development Discussion”