12f629 freq divider?


Closed Thread
Results 1 to 20 of 20
  1. #1

    Default 12f629 freq divider?

    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.

  2. #2


    Did you find this post helpful? Yes | No

    Default

    the pic doing the pwm will be of the 16f variety. 628A or 88 etc.

  3. #3
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    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.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    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. ?

  5. #5
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    Using the method I suggested, you could easily change the frequency by changing the number that you subtract from the timer.

  6. #6


    Did you find this post helpful? Yes | No

    Talking

    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!

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    the easy way out ...

    Slow speed Software PWM
    http://www.pbpgroup.com/modules/wfse...hp?articleid=6

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

  8. #8


    Did you find this post helpful? Yes | No

    Talking Silver platter even!

    Thanks! now to go read and understand it. Really appreciate the replies.

  9. #9
    talat's Avatar
    talat Guest


    Did you find this post helpful? Yes | No

    Question urgent help

    Quote Originally Posted by Darrel Taylor View Post
    the easy way out ...
    Slow speed Software PWM
    http://www.pbpgroup.com/modules/wfse...hp?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?

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by talat View Post
    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.

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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>
    DT

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    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.
    Last edited by skimask; - 22nd October 2008 at 05:35. Reason: Took out those extra sentences in the beginning...WTH was that?

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    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>
    DT

  14. #14
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    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...

  15. #15
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    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.

  16. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by nomad View Post
    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:
    Code:
    '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.
    Last edited by skimask; - 23rd October 2008 at 00:20. Reason: Pulled out the REAL code...

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


    Did you find this post helpful? Yes | No

    Default Re: 12f629 freq divider?

    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

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


    Did you find this post helpful? Yes | No

    Default Re: 12f629 freq divider?

    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.

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


    Did you find this post helpful? Yes | No

    Default Re: 12f629 freq divider?

    Quote Originally Posted by F1CHF View Post
    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
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Re: 12f629 freq divider?

    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

Similar Threads

  1. Input problems with 12F629?
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 24th April 2018, 07:25
  2. 12F629 LDR - Light Dependant Resistor
    By Dennis in forum Schematics
    Replies: 15
    Last Post: - 18th February 2010, 23:33
  3. Basic help for 12F629
    By Gene Choin in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd September 2009, 05:06
  4. Servo control with 12F629
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th June 2005, 00:34
  5. HPWM on a 628 is not changing freq.
    By dtit in forum General
    Replies: 2
    Last Post: - 25th February 2005, 10:34

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