Page 2 of 2 FirstFirst 12
Results 13 to 24 of 24

Thread: 32Khz crystal problem!

  1. #13
    Registered
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    2,387
    Downloads
    0
    Uploads
    0
    I see. Here's some suggestions. You don't need a second clock to do precise timing you can do it all from the main PIC xtal. It's actually better to use a higher xtal speed to measure the period more accurately.

    If you need to generate accurate 1 second timing and any timing events from the one PIC xtal there is a comprehensive web page of PIC and C code here; http://www.romanblack.com/one_sec.htm

    There is a complete tacho project for PIC with C source code here; http://www.romanblack.com/shift1/sh1_projects.htm
    (scroll down to SH1_Tacho)

    And another one here; http://www.romanblack.com/easypic6_proj1.htm
    using this procedure;
    1. The incoming frequency to be measured is connected to PORTC.F0.
    2. Every new pulse on PORTC.F0 causes TMR1 to increment.
    3. An accurate 1 second period is generated using the TMR2 interrupt.
    4. Every second, the TMR1 count is captured and displayed as Frequency (Hz).
    5. RPM is calculated from (Freq * 60) and RPM is displayed too.


    I have been doing precise pulse measurement and generation with PICs since the early 90's so I can help you with suggestions if you like, just provide more details about what you need it to do.


  2. #14
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    18,958
    Downloads
    0
    Uploads
    0
    Thanks, I will study those for sure, I used the 32.768khz watch xtal because being a power of 2 it utilizes the TIM1 register nicely to give the overflow at 1 sec.
    I actually made some headway today and have another program working so I am presently looking into why my previous efforts failed.
    Thanks Again, I will post an update later.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design (Skype Avail).

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  3. #15
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    18,958
    Downloads
    0
    Uploads
    0

    Update:

    Their were at least a couple of problems apparently, so it made it even harder to trouble shoot.
    The final straw was when I finally got a test program working that used TIM1 to flashed a LED every second using the 32khz T1OS0 and it ran on the bench for 6 hrs, no problem.
    I then hooked up the scope lead to common and the timer stopped!!
    Took it off and the timer resumed, I then noticed that just passing my hand above the board caused it to stop.
    Everything hardware wise looked good.
    I had dropped the code into the PicMicro F628A template file instead of my usual file and on closer check it had the MCLRE set ON, so the IC pin RA5 was expecting a high instead of floating, so any little electrical disturbance reset the Pic.
    Set it to OFF and now its working.
    BTW Roman, I have always used assembly since my 8085 days so I never did get in the "C".
    Al.
    CNC, Mechatronics Integration and Custom Machine Design (Skype Avail).

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  4. #16
    Registered
    Join Date
    Jan 2007
    Location
    USA
    Posts
    355
    Downloads
    0
    Uploads
    0
    Glad you found the problem, Al.

    I use a 19.6608 MHz oscillator for the main system clock. Divide it down to generate serial baud rates (2400, 9600, etc.). Can generate an accurate 1 second pulse, but there's a messy 75 factor to deal with .
    Diplomacy is the art of saying "Nice doggie" until you can find a rock. - Will Rogers


  • #17
    Registered
    Join Date
    Oct 2005
    Location
    Australia
    Posts
    2,387
    Downloads
    0
    Uploads
    0
    Nice work finding that one. I don't think you ever stop being bitten by config stuff like that, especially when you double/triple check the code and it's perfect.

    Quote Originally Posted by Al_The_Man View Post
    ...
    BTW Roman, I have always used assembly since my 8085 days so I never did get in the "C".
    Al.
    Oops I hope I didn't sound like I was implying you were new to micros etc, I often type replies with minimal care invested in social graces and the focus on quickly typing a solution etc.

    Re the assembler, I held off for years before switching from PIC asm to C. I still work in asm when needed for speed/size and I try to write all my C as C-- using the simplest constructs and each code line doing one task, and gotos when they are the best way (C purists would cringe) because it allows pretty easy conversion of my C code to asm, and vice versa, which I do fairly often.

    So what is this mystery "low freq measuring" project? You got my curiosity up.


  • #18
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    18,958
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by RomanLini View Post
    Oops I hope I didn't sound like I was implying you were new to micros etc,
    Didn't see it that way.

    Quote Originally Posted by RomanLini View Post
    So what is this mystery "low freq measuring" project? You got my curiosity up.
    A friend need an application, very low rpm wind tunnel detection with LCD readout and scaling.
    I probably could have used the system clk, but I saw this article and wanted to use a 32khz xtal, so it was a case I did not want it to get the better of me.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design (Skype Avail).

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  • #19
    Registered Iron-Man's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    181
    Downloads
    0
    Uploads
    0
    Al, happy to see that you got it working.
    Its usually the small things that get in the way.

    Iron-Man
    Last edited by Iron-Man; 09-15-2010 at 04:34 PM. Reason: Edit


  • #20
    Registered
    Join Date
    Mar 2006
    Location
    Sol 3 (YVR)
    Posts
    125
    Downloads
    0
    Uploads
    0
    I just changed a timing circuit from using a 4MHz crystal to a 4.096MHz crystal to improve 1 second timing. Now timer 0 overflows 250 times per second instead of the previous 244.xx times per second. (Prescale at 8 or 16 - can't remember.)


  • #21
    Registered
    Join Date
    Dec 2005
    Location
    UK
    Posts
    74
    Downloads
    0
    Uploads
    0
    Hello Al

    I have just looked through all my historic manuals. The generic MID-Range manual of 1997 shows an example of what you are trying to achieve. Important factors seem to be TIOSCEN to be set, and the caps are shown as 33pF for an Epson crystal. I can photograph it for you if you wish. Interestingly the section on the main crystal shows caps for 32kHz option being from 68 - 100pF! I hope this helps.

    Richard


  • #22
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    18,958
    Downloads
    0
    Uploads
    0
    Thanks I got it sorted.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design (Skype Avail).

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  • #23
    Registered
    Join Date
    Dec 2005
    Location
    UK
    Posts
    74
    Downloads
    0
    Uploads
    0
    Hello Al

    May I ask what the solution was?

    Richard


  • #24
    Community Moderator Al_The_Man's Avatar
    Join Date
    Dec 2003
    Location
    Canada
    Posts
    18,958
    Downloads
    0
    Uploads
    0
    See post #15, mostly this was the cause.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design (Skype Avail).

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.


  • Page 2 of 2 FirstFirst 12

    Similar Threads

    1. Need Help!- Optical Crystal
      By adrianhdezch in forum General Laser Engraving & Cutting Machine Discussion
      Replies: 5
      Last Post: 09-02-2010, 02:26 AM
    2. Replies: 5
      Last Post: 08-04-2010, 06:33 PM
    3. Supply mini 2D/3D crystal laser subsurface engraving machine
      By 3dlasermachine in forum Product and Manufacturer Announcements
      Replies: 1
      Last Post: 09-07-2009, 11:15 PM
    4. Build Thread- laser cutting crystal
      By Jiepu-Crystal in forum General Laser Engraving & Cutting Machine Discussion
      Replies: 0
      Last Post: 08-07-2009, 01:35 AM
    5. Build Thread- laser crystal
      By Jiepu-Crystal in forum General Laser Engraving & Cutting Machine Discussion
      Replies: 0
      Last Post: 08-06-2009, 10:50 PM

    Tags for this Thread

    Posting Permissions


     


    About CNCzone.com

      We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

    Follow us on

    Facebook Dribbble RSS Feed


    Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.