PDA

View Full Version : 12f629 freq divider?



nomad
- 30th September 2007, 05:56
i need to output a frequency from 40hz to about 640hz. I figure i can get around the hpwm limits by multiplying by 50. and output between 2000-32000hz. so now i need a divide by 50 circuit on the output. does using a 12f629 to count pulses and toggle an output after every 25th pulse sound like the way to go? chip is cheaper than a loadable counter, associated passives, and way less board space and traces etc. seems too easy so im thinking i'm overlooking something.

nomad
- 30th September 2007, 06:01
the pic doing the pwm will be of the 16f variety. 628A or 88 etc.

Kamikaze47
- 30th September 2007, 07:58
You could always set up a timer interrupt to output the frequency.

i.e. for 40Hz, set a timer to the correct value so it will overflow in 12.5mS. When it overflows, that triggers the interrupt, and get the interrupt to toggle a digital output and then subtract 12.5mS from the timer value. This will ensure a pretty accurate 40Hz.

nomad
- 30th September 2007, 19:29
My output frequency will be constantly changing. but that's a good idea to remember, certainly gets around pwm limit. my whole circuit is reading time of an input pulse, displaying the frequency, adding or subtracting a variable amount (from button inputs to a counter) and outputting the new frequency. had it all done up with logic, counters, a pll, display drivers etc. just moving to a cleaner(simpler) solution with a pic. as an after thought was thinking the divide by 50 could also use internal DAC 25 steps up then down and get a dirty little sine wave out. ?

Kamikaze47
- 30th September 2007, 19:41
Using the method I suggested, you could easily change the frequency by changing the number that you subtract from the timer.

nomad
- 30th September 2007, 20:11
ok, guess i was looking for the easy way out. am a newbie and haven't dealt with the timers yet. just assumed it would be difficult to change on the fly. having it all done in the one pic would be best. i'll read up and let you know how it turns out. thanks!

Darrel Taylor
- 30th September 2007, 21:15
the easy way out ...

Slow speed Software PWM
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=6

Set the dutycycle to 50%
Then change the frequency at will.
<br>

nomad
- 1st October 2007, 05:42
Thanks! now to go read and understand it. Really appreciate the replies.

talat
- 21st October 2008, 22:38
the easy way out ...
Slow speed Software PWM
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=6

Set the dutycycle to 50%
Then change the frequency at will.
<br>

Hi,
how I can use SSPWM (Slow Speed PWM) code with 12F675?

skimask
- 21st October 2008, 23:18
Hi,
how I can use SSPWM (Slow Speed PWM) code with 12F675?

You can't.
Not enough on chip register space for the variables required.

Darrel Taylor
- 22nd October 2008, 00:46
Where do you come up with your answers skimask?

8-Ball?
Dart board?

Of course you can run it on a 12F675.
Just comment out the wsave1 wsave2 and wsave3 variables, since the 12F675 doesn't have GP RAM in those banks.
<br>

skimask
- 22nd October 2008, 01:30
Where do you come up with your answers skimask?
8-Ball?
Dart board?
Of course you can run it on a 12F675.
Just comment out the wsave1 wsave2 and wsave3 variables, since the 12F675 doesn't have GP RAM in those banks.
<br>
Both of them...I assign points to each answer, then take the average point out of 7 tries.
Fine, it can be run on a 12F675. I thought there was only 24 bytes ram on a '675.
The average Joe isn't going to know to comment out those wsave variables until the compiler/assembler whines about it. Then the average Joe isn't going to know what 'Unable to fit variable wsave3' means after hitting F9. Then what is the average Joe going to do? Ask questions of course. A comment in the sspwm.inc file would fix that.
I haven't tried it on anything less than a 16F628A. I'll play with it this weekend on an 'F629 and see what happens.

Darrel Taylor
- 22nd October 2008, 03:02
I thought there was only 24 bytes ram on a '675.
64, but it won't matter much.
SSPWM uses ASM interrupts. So the issue of saving all the PBP system vars doesn't apply.


A comment in the sspwm.inc file would fix that.

Or maybe a note to use the current version. :)

SPWM_INT - Multiple Software PWM
http://www.darreltaylor.com/DT_INTS-14/SPWM.html
<br>

skimask
- 22nd October 2008, 04:36
64, but it won't matter much.
That's what I get when I get my 10Fxxx's and 12Fxxx's corn-fuzzed...


SPWM_INT - Multiple Software PWM
Well then that's the one I'm going to play with some more...

rmteo
- 22nd October 2008, 17:48
Ski, if you get the 24-bit stuff, here is a what a PIC24 will do in this kind of situation:

1. Hardware PWM from 30Hz to 500KHz+.
2. Up to 16-bit duty cycle resolution at lower frequencies.
3. Up to 5 independent hardware PWM's.
4. 0% processor overhead.
5. Virtually no coding - except to set up registers.

All this from a single $2, 28-pin device. :D

skimask
- 22nd October 2008, 18:46
does using a 12f629 to count pulses and toggle an output after every 25th pulse sound like the way to go?
I didn't read the post thoroughly before...
Awhile back, I needed a divider for an output from an 18F4685 running at 40Mhz (which is wayyyy too fast at it's slowest) to drive a auto tachometer (which needs much slower input freq).
I took a regular ol' 12F675, set it up to just do a 'blinky LED' with a few pauses here and there to divide it just right and drove the 12F685's OSC1 input with the output from the PIC18F4685 that I needed to divide. Does that make sense?
The code looked like this:


'73 used, 16 lines, PIC12F675 'expensive divide by' chip
@ __CONFIG _CPD_OFF & _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _EC_OSC
DEFINE NO_CLRWDT 1 'no extra clear watchdog timer instructions
DEFINE OSCCAL_1K 1 'reload osc cal value
DISABLE
CLEAR
led var gpio.4 : tachout var gpio.2
delay con 75
cmcon = 7 : ansel = 0 : trisio = $2b 'digital pins, inputs and outputs set up
mainloop:
led = 0 : tachout = 0 : pauseus delay
led = 1 : tachout = 1 : pauseus delay
goto mainloop
ENd


I ended up with a 'divide by 58' chip. The output wasn't exactly a 50% duty cycle, but it was close enough to drive the tach. You can see the tach running off the PIC on youtube. Do a search for skimask87, check video #5.

F1CHF
- 2nd February 2021, 14:15
hello I don't know if it is the right place to put my question ! because I have quite the same need
I must divide a signal (10 Mhz) to 10 Khz (OCXO asservissement with a GPS)
I have an example in language "C" and I understand quite nothing !!! it use a 12F675 (clock is the 10 mhz signal)
Hope somebody can help me, I think that I have to write in ASM language, not in Basic
ASM is not easy for me ...
so if somebody knows how to divide a 10 Mhz signal to get a 10 Khz output signal
I would appreciate
thanks
Francois F1CHF

mpgmike
- 2nd February 2021, 16:34
First recommendation is to start you own thread to ask your question (instead of reviving a 14 year old one).

Second, could you post the C code? Please use [ CODE ] and [ /CODE ] (without the spaces around the brackets). There are several of us that can decipher C. That might be quicker than starting from scratch.

Acetronics2
- 5th February 2021, 11:13
hello I don't know if it is the right place to put my question ! because I have quite the same need
I must divide a signal (10 Mhz) to 10 Khz (OCXO asservissement with a GPS)
I have an example in language "C" and I understand quite nothing !!! it use a 12F675 (clock is the 10 mhz signal)
Hope somebody can help me, I think that I have to write in ASM language, not in Basic
ASM is not easy for me ...
so if somebody knows how to divide a 10 Mhz signal to get a 10 Khz output signal
I would appreciate
thanks
Francois F1CHF

Hello François

Have an eye Here: http://www.leapsecond.com/pic/picdiv.htm

Alain

F1CHF
- 5th February 2021, 17:19
Alain
super web site link
I must find the solution
otherwise I must switch to another hobby (stamp collection or sitting in a arm chair !)
hi