PDA

View Full Version : Multiplying with 11 using PIC



eltra11
- 13th October 2021, 12:22
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

tumbleweed
- 13th October 2021, 15:31
...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?

HenrikOlsson
- 13th October 2021, 16:16
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.

mpgmike
- 13th October 2021, 17:52
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.

eltra11
- 17th October 2021, 08:46
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

richard
- 17th October 2021, 10:20
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

richard
- 17th October 2021, 11:29
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
9092
9093

HenrikOlsson
- 17th October 2021, 14:44
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.

9094

9095

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.

eltra11
- 18th October 2021, 12:57
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.

amgen
- 19th October 2021, 00:53
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

eltra11
- 19th October 2021, 06:26
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.

Ioannis
- 19th October 2021, 11:38
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

amgen
- 19th October 2021, 13:57
switching the r or c values might work good..... the switch or transistor might have to work 'bidirectionally' I think though.

Ioannis
- 19th October 2021, 14:52
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

eltra11
- 23rd October 2021, 18:38
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

Ioannis
- 23rd October 2021, 20:18
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

Charlie
- 24th October 2021, 17:18
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.

eltra11
- 24th October 2021, 17:54
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

HenrikOlsson
- 24th October 2021, 21:16
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?

Ioannis
- 25th October 2021, 12:09
In any case, 4046 will not operate at 11MHz.

A DDS is much better idea.

Ioannis

eltra11
- 26th October 2021, 19:32
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

Ioannis
- 27th October 2021, 10:35
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

Acetronics2
- 30th October 2021, 19:57
just try a 74 HC/HCT 4046 ...:wink:

Alain

eltra11
- 9th November 2021, 13:51
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

Ioannis
- 9th November 2021, 14:07
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

eltra11
- 9th November 2021, 16:17
Hi, thanks a lot !
I shall make additional efforts about this task.
Mike

eltra11
- 12th November 2021, 18:52
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
;************************************************* *****************************

richard
- 12th November 2021, 22:58
a 32 bit number cannot be represented in 24 bits , you need 32bit multiplier code

look at n-bit math (http://dt.picbasic.co.uk/CODEX/N-BitMath)