Multiplying with 11 using PIC


Closed Thread
Results 1 to 28 of 28
  1. #1
    Join Date
    Sep 2015
    Posts
    23

    Default Multiplying with 11 using PIC

    Hi
    Anyone can help about the following task.
    Have to multiply input frequency by 11.
    The input frequency range is from 1 Hz to 1 MHz.
    Output frequency has to be from 11 Hz to 11 Mhz.
    Input frequency is coming in time frames of 5 minutes to PIC input stochastically.Means for instance first freq. is 1 KHz and lasts for 5 minutes, after that come second freq. for instance 2 KHz which lasts 5 minutes, then come third freq. 950 KHz etc. etc.
    That means first PIC have to measure input frequency, recognize if it has changed to the new value, and sent to output the present frequency multiplied by 11.
    Much gratefull for any suggestion of which PIC to use for that and how to solve the problem. (16F628A with 20 MHz resonator, PIC16F1455 with 48 MHz osc., PIC18F13K22 with 64 MHz osc. ) ?
    If you can post some code for that the better.
    Have PBP3 Gold edition.
    Thanks

  2. #2
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    ...and sent to output the present frequency multiplied by 11.
    What do you mean by this?

    Do you want the pic to generate a square wave output from 11Hz to 11MHz on an output pin?

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


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    What sort of resolution are we talking about and how much jitter can you tolerate (ie how "clean" must the output signal be)?

    I would think that your best bet is to use a PIC that has a 20bit NCO-peripheral. 18F25K42 is one such device. If you don't know how DDS frequency generation works make sure to read up on that in order to determine if it'll fit your application.

    If DDS works but the NCO won't live up to requirements you might be able to use an external DDS-chip with a higher base frequency and/or higher resolution and use the PIC to control that chip.

    /Henrik.

  4. #4
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Please feel free to correct any faulty assumptions.

    First realize that to multiply a frequency by 11, you are dividing a time frame by 11.

    What does your frequency input look like? Is it a perfect square wave (50% duty cycle), an irregular square wave (!=50% DC), a sine wave?

    Assuming a square wave input, try using CCP1 in Capture Mode to measure the time frame of one Gate (low-high starts Capture, high-low stops it). Use CCP2 with the same source clock and divide that time frame and plug it into PWM at 50% DC.

    If your input is sine wave, you might need to use a Comparator to mark low-high and high-low transitions, then feed that into your CCP1.

    If you have an irregular square wave input, you need to measure low-high to low-high period.

    If your input frequency is extremely long (like 1 Hz), you may need a Signal Measurement Timer with 24 bits to measure the input period time. Keeping the clocks the same for measuring input and for your output means you just run the math (input period / 11 = output period).

    I hope this gives you ideas.

  5. #5
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Reply to mpgmike
    In private correspondence with Mr. Henrik the conclusion is that solution with NCO, and PIC working on 64MHz clock would not be the solution.
    Referring to your idea to measure time frame of the input to PIC which has to be multiplied by 11 – if we consider the 1MHz input (1 usec time frame) and 64MHz PIC oscillator clock.Then we have do divide 1 usec /11 and generate output on the base of 64MHz clock.Could you predict what the accuracy should be for 11 MHz output.
    Pic which works on 64MHz and have 2 CCP is PIC18(L)F24/25K40
    Input is square wave with not exactly 50% duty cycle.

    Reply to tumbleweeed
    Yes, PIS has to generate thesquare wave output from 11 Hz to 11 MHz on an output pin.
    Thanks

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,381


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Then we have do divide 1 usec /11 and generate output on the base of 64MHz clock.Could you predict what the accuracy should be for 11 MHz output.
    you could work it out

    @64 mHz the pic executes 1 instruction every 62.5 nano seconds
    to toggle a pin @11 mHz thats twice every 91 nano seconds , you don't have even 1 inst period to work with

    accuracy approx 0%

    i can't work it out in my head but CCP is unlikely to get there either,

    your going to need a bigger boat
    Warning I'm not a teacher

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    2,381


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    the closest i get to 11 meg in mcc for a pwm module is 8meg next step down is 5.33 meg next up 16 meg
    Name:  Untitled.jpg
Views: 1263
Size:  80.0 KB
    Name:  Untitled.png
Views: 1243
Size:  24.7 KB
    Last edited by richard; - 17th October 2021 at 12:33.
    Warning I'm not a teacher

  8. #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Off list I tried to get Mike to put some sort of number on the needed frequency resolution and allowable jitter. I got neither. I tried to explain how the NCO works and he determined it wasn't up to the task. I did some experiments with the 18F57Q43 running at 64MHz and I'll post some images showing the output of the NCO.

    Name:  SDS2104X Plus_PNG_4.png
Views: 1130
Size:  75.5 KB

    Name:  SDS2104X Plus_PNG_3.png
Views: 1156
Size:  75.0 KB

    Here we can see how the NCO generates an average frequency of 7.619MHz (as evident by the frequency counter in the top right corner). But when looking closely we can see that MOST of the time (as shown by the "warm" trace) the actual frequency is 7.936MHz and occationally (as shown by the "cold" trace) it's 6.309MHz. The NCO "dithers" between these two frequencies so that, over time, the average frequency is 7.619MHz.

    I tried to squeeze 11MHz out of it but it won't do it, runt pulses and all sorts of weird looking stuff - some of which most likely comes from the setup and probing.

    I still think something like an AD9850 with proper filtering on the output, and then turning that signal back to digital might work.

  9. #9
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi Richard , Hi Henrik
    You enormously help me in solving to approach to the task on the right way by conclusion that neither CCP or NCO should not lead to the solving of the problem.
    As one solution I shall try is to solve it with PLL – CD74HC4046A.Here the PIC should be used to detect input frequency and accordingly to switch on or off elements in VCO low pass filter to obtain the input frequency range from 1 Hz to 1 MHz.The multiplication should be realized by 11 time divider in between VCO output and Comparator Input of CD74HC4046A.
    I ordered the chips accordingly and it will take some time to get it and then I shall make the test.

  10. #10


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    what came to my mind first for that was PLL..... phase-locked-loop that does exact frequency multiplication using divide by N as the multiplier. One problem would be the 'dynamic range' of 1 million for the 11 to 11MHZ. The PIC could switch in 1 of 2 or 3 PLL's for workable operating ranges.

    Just saw previous post with PLL

  11. #11
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Do not understand exactly what do you mean by sentence : "The PIC could switch in 1 of 2 or 3 PLL's for workable operating ranges."
    My idea is that PIC should detect the frequency frame in which PPL will be locked.For instance the first frame will be 1 Hz to 20 Hz, the second from 20 Hz to 200 Hz, third from 200 Hz to 2000 Hz, etc.Means PIC will detect the input frequency coming to PIC input pin (and also to PLL) which have to be multiplied by 11, and accordingly will switch the right low pass filter into VCO input.The input frequency will change in value every 5 minutes.
    So idea is to switch elements in low pass filter in PLL, not to switch the whole PLL's.

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    The VCO of the PLL has a limited range that can work with specific R and C values. That is why you may need 3 discrete PLL's and have the PIC to decide which one will work at any time.

    Ioannis

  13. #13


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    switching the r or c values might work good..... the switch or transistor might have to work 'bidirectionally' I think though.

  14. #14
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    The capacitor switching is difficult as it is directly connected to the pins of 4046. The resistor R1 in the datasheet, is connected to gnd. So, maybe two or three mosfets like a 2N7000 can select one of each to define the frequency range.

    Also, a SN74LV4046A will be needed to be able to cover the 11MHz range. A CD4046 at 5V will not be able to work over 800KHz.

    Ioannis
    Last edited by Ioannis; - 19th October 2021 at 15:54.

  15. #15
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi Ioannis, Hi amgen
    Thank you for comments.
    For switching capacitor in VCO I shall try CD4066 - it has floating switch output with On resistance 5 ohm.PLL – CD74HC4046A runs on 5VDC, but I shall switch CD4066 control pin with 12 VDC.Suppose capacitor in PLL could be switched on that way.If not I shall try with J111.
    Mosfet like a 2N7000 has internally protection diode.As a solution I shall try also to switch with J111 instead which is without internal diode.At the moment I am waiting for ordered elements to arrive so I can make a test.
    Keep you informed but need some more time to receive elements and make a proto board.
    Best rds. Mike

  16. #16
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Still at 12volts, I am pretty sure the CD4046 will not go over 2MHz (the data sheet has all the info).

    I insist on using a faster chip.

    Also best is switching resistor with the ground lead instead of a capacitor of few pF and floating. It wont work.

    Ioannis

  17. #17
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    I would use an SI5351A chip with a PIC to load it with the frequency to generate based on the counted input frequency. (x11) The output will match your requirement perfectly, as long as you are good with a square wave.

  18. #18
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi Ioannis, Hi Charlie
    Thank you for your kind support.
    But CD4066 have to switch the new value capacitor or R1 every 5 minutes, as the input frequency to PLL will change every 5 minutes.
    Means, the new frequency come to PLL input, PIC have to detect in which frequency range is the input frequency and according to that, over CD4066 to switch ON or OFF the right elements C and R1 in PLL.
    So CD4066 will be switched every 5 minutes, remains in switched state also 5 minutes until the new frequency come on PLL input.
    Thank you, will inform you about test results.
    Mike

  19. #19
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    The Si5351 looks cool and perhaps I'm missing something but banner specs for it says that the lowest frequency is 2.5kHz while requirements are 11Hz. You would need an extra output divider of 227:1 to get down to 11Hz but then your top frequency doesn't come close to the requirement of 11MHz. And we still don't know the expected resolution of the output frequency. 0.1Hz, 100Hz, 10kHz?

  20. #20
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    In any case, 4046 will not operate at 11MHz.

    A DDS is much better idea.

    Ioannis

  21. #21
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi Ioannis
    thank you for your valuable comments.I shall make a test with CD4066, a mosfet 2N7000, J111, and miniature relay to try to switch C connected to PLL pins.
    To switch R connected to ground in PPL will be no such a problem.
    Shall inform you about results when test done.
    Mike

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    CD4066 is a CMOS Quad Bilateral Switch and not PLL. I cannot follow your thinking.

    Are still wanting a 11MHz operation or are OK with 2MHz?

    Ioannis

  23. #23
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    just try a 74 HC/HCT 4046 ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  24. #24
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi Ioannis
    I made a trial efforts with 74HC4046 for realization of 11 time multiplying of input frequency from 1 Hz to 1 MHz.The output such have to be from 11 Hz to 11 MHz.But it is very tricky especially because many frequency operating bands are needed to cover the whole frequency range.(means lot of VCO center frequencies and lot of filters have to switched ON and OFF for each band of frequency lock range.)
    Please what do you mean with your question to me in your previous reply : "are OK with 2MHz? "
    What solution do you have for 2 MHz frequency range ?
    Mike

  25. #25
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    I asked this because you preferred the CD4046 over the HC/HCT4046.

    The CD4046 will not go over 2-3MHz, that is why I asked this.

    Sure it is not easy task to have many different bands on one chip. Maybe have 2 or 3 discrete 4046 overlapping each other?

    Ioannis

  26. #26
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi, thanks a lot !
    I shall make additional efforts about this task.
    Mike

  27. #27
    Join Date
    Sep 2015
    Posts
    23


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    Hi
    Please look at the code for MPLAB.Please look if you can help about.My knowledge in MPLAB programming is very low.

    Here is a CODE for multiply.Please could you make a correction that MUX_24X24 routine will work when
    multiplier h'225C18' is over 6 digits – for instance in this example – multiplier should be h'179F508'
    Below code works fine with multiplier h'225C18'
    ;************************************************* **************************************
    SPREMI_MEM ; input data are FREQ_NO i MEM_NO and according to them
    ; location for saving to FLASH are defined
    ;data which are saved are saved in registers BIN_H,BIN_M i BIN_L and that are data
    ;for display frequencies on the address h'05', h'06', h'07'
    ;-calculating the word which have to be sent to AD9850:
    movf BIN_H,W ;move values for multiply KEYB
    movwf MULCND_H
    movf BIN_M,W
    movwf MULCND_M
    movf BIN_L,W
    movwf MULCND_L
    ;What if multiplier is h'179F508'
    ;Please make correction in code if multiplier is 7 digits long hex number
    movlw h'22' ;set multiplier h'225C18' KEYB
    movwf MULPLR_H
    movlw h'5C'
    movwf MULPLR_M
    movlw h'18'
    movwf MULPLR_L

    call MUX_24X24 ;multiply

    movf REZ_5,W ;registar 4 for AD9850 KEYB
    movwf RAM_0
    movf REZ_4,W ;registar 3 for AD9850 KEYB
    movwf RAM_1
    movf REZ_3,W ;registar 2 for AD9850
    movwf RAM_2
    movf REZ_2,W ;registar 1 for AD9850 KEYB
    movwf RAM_3
    movlw h'00'
    movwf RAM_4

    movf BIN_H,W ;value for diplay KEYB
    movwf RAM_5
    movf BIN_M,W ;value for display KEYB
    movwf RAM_6
    movf BIN_L,W ;value for display KEYB
    movwf RAM_7
    UPIS_U_FLASH
    call FLASH_WRITE
    return
    ;************************************************* *****************************
    ;************************************************* *****************************
    MUX_24X24 ; multiply tree bytes :MULPLR_H, MULPLR_M i MULPLR_L
    ;with MULCND_H, MULCND_M i MULCND_L
    ; 48 bit result saved in REZ_5 to REZ_0
    clrf REZ_5
    clrf REZ_4
    clrf REZ_3 ; MUX
    clrf REZ_2
    clrf REZ_1
    clrf REZ_0
    movlw d'24' ;count for 24 bit
    movwf BROJAČ_T3
    bcf STATUS,C ;Clear the carry bit in the status Reg.
    LOOP24
    rrcf MULPLR_H,F ; MUX
    rrcf MULPLR_M,F ;
    rrcf MULPLR_L,F ; MUX
    btfss STATUS,C
    goto ROTATE_R
    ADD_3_BYTES
    movf MULCND_L,W
    addwf REZ_3,F
    btfsc STATUS,C ;check carry bit
    incf REZ_4,F
    btfsc STATUS,C ;check carry bit MUX
    incf REZ_5,F

    movf MULCND_M,W
    addwf REZ_4,F
    btfsc STATUS,C ;check carry bit MUX
    incf REZ_5,F

    movf MULCND_H,W
    addwf REZ_5,F

    ROTATE_R
    rrcf REZ_5,F
    rrcf REZ_4,F
    rrcf REZ_3,F
    rrcf REZ_2,F
    rrcf REZ_1,F
    rrcf REZ_0,F
    decfsz BROJAČ_T3,F ; MUX
    goto LOOP24
    return
    ;************************************************* *****************************

  28. #28
    Join Date
    May 2013
    Location
    australia
    Posts
    2,381


    Did you find this post helpful? Yes | No

    Default Re: Multiplying with 11 using PIC

    a 32 bit number cannot be represented in 24 bits , you need 32bit multiplier code

    look at n-bit math
    Warning I'm not a teacher

Similar Threads

  1. pass pic basic pro pic from pic 16f877a to pic 16f887
    By joseluisatmega8 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th February 2020, 17:17
  2. High Speed Serial Comm PC - PIC and PIC - PIC
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 16th January 2007, 22:55
  3. Multiplying large numbers
    By jhonea1 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 14th April 2006, 18:41

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