12f629 freq divider?


Closed Thread
Results 1 to 20 of 20

Hybrid View

  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
    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; - 22nd October 2008 at 23:20. Reason: Pulled out the REAL code...

  8. #8
    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

  9. #9
    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.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    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 " !!!
    *****************************************

  11. #11
    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, 06:25
  2. 12F629 LDR - Light Dependant Resistor
    By Dennis in forum Schematics
    Replies: 15
    Last Post: - 18th February 2010, 22:33
  3. Basic help for 12F629
    By Gene Choin in forum mel PIC BASIC
    Replies: 5
    Last Post: - 22nd September 2009, 04:06
  4. Servo control with 12F629
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd June 2005, 23:34
  5. HPWM on a 628 is not changing freq.
    By dtit in forum General
    Replies: 2
    Last Post: - 25th February 2005, 09: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