588,306 active members*
4,692 visitors online*
Register for free
Login Register
INDEX Forum
PIC Programing / Design > 32Khz crystal problem!
Page 1 of 2 12
Results 1 to 20 of 24
  1. #1
    Join Date
    Dec 2003
    Posts
    24220

    32Khz crystal problem!

    Anyone have problems of getting a Tim1 32khz Ext. Osc working?
    I am having a frustrating time with getting the oscillator to run, on both a 62F628 and a 16F870.
    I am using a popular Epson 32.768khz xtal.
    I have gone from 12pf to 25pf for the caps, before I look for another Xtal, is there anything in particular I may have overlooked?
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

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

  2. #2
    Join Date
    Oct 2005
    Posts
    2392
    Config settings?

    Pop in a garden variety 4MHz xtal and see if it runs. That at least will confim config and T1CON settings.

    Some of those 32kHz xtals are a little fussy as they are meant for micropower use, especially the tiny cylindrical type (watch xtals). I have had some results using a series resistor with the xtal I think about 1k but this is some years ago now.

  3. #3
    Join Date
    Dec 2003
    Posts
    24220
    Quote Originally Posted by RomanLini View Post
    Config settings?

    Pop in a garden variety 4MHz xtal and see if it runs. That at least will confim config and T1CON settings.

    Some of those 32kHz xtals are a little fussy as they are meant for micropower use, especially the tiny cylindrical type (watch xtals). I have had some results using a series resistor with the xtal I think about 1k but this is some years ago now.
    Do any of the config settings apply to the T1OSO/T1OSI ?
    I have ordered a different xtal and a range of caps, so hopefully I will have more luck.
    I am using a pre-tested code from a tutorial as a test.
    The only common thing so far is the xtal?? If all else fails I will try the 1k.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

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

  4. #4
    Join Date
    Jan 2007
    Posts
    355
    Al,

    I don't have datasheets handy for the PICs you tried, but there are probably two different config bits that need to be set for the xtal to work properly.

    In other PIC chips, the T1CON (timer 1 control register) has to have the T1OSCEN bit set (to enable the external oscillator) and the TMR1CS bit set ( to select the external clock).
    Diplomacy is the art of saying "Nice doggie" until you can find a rock. - Will Rogers

  5. #5
    Join Date
    Dec 2003
    Posts
    24220
    I have set the T1CON register in the program, it is the config or configuration word that I was questioning, in the 16F628 it is register 14-1 or the __config instruction set at programming time.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

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

  6. #6
    Join Date
    Jan 2009
    Posts
    334

    PIC16F870

    Al, the PIC16F870 can be operated in 4 different oscillator modes. Please see the data sheet here; http://melabs.picbasic.com/devicedata/30569a.pdf
    For the 32Khz xtal, you need 33pf caps. Please see pages 91 and 92.

    Also make sure that you have the proper mode set;

    • LP Low Power Crystal
    • XT Crystal/Resonator
    • HS High Speed Crystal/Resonator
    • RC Resistor/Capacitor

    Hope this helps,

    Iron-Man

  7. #7
    Join Date
    Dec 2003
    Posts
    24220
    Quote Originally Posted by Iron-Man View Post
    Al, the PIC16F870 can be operated in 4 different oscillator modes. Please see the data sheet here; http://melabs.picbasic.com/devicedata/30569a.pdf
    For the 32Khz xtal, you need 33pf caps. Please see pages 91 and 92.
    Also make sure that you have the proper mode set;

    • LP Low Power Crystal
    • XT Crystal/Resonator
    • HS High Speed Crystal/Resonator
    • RC Resistor/Capacitor

    Hope this helps,

    Iron-Man
    But this appears to refer to the FOSCI/FOSCI, main system clock?
    This is running OK as the program runs, it is the TI0SO/TIOSI, TIM1 clock, which appears to be LP type by default.
    I get no 'scope signal at the 32khz xtal pins, I am testing with the x10 scope lead as is recommended.
    As far as I have been able to tell in the documentation, the 16 bit configuration register does not apply to the TIM1 oscillator?
    I will try more tests today, including the 33pf.
    Thanks.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

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

  8. #8
    Join Date
    Jan 2009
    Posts
    334
    Al, I have searched for the, TI0SO/TIOSI, TIM1 clock and cannot find it listed any where in the data sheet for the 16F870. What data sheet are you working from. Can you post a picture of the board?

    Iron-Man

  9. #9
    Join Date
    Oct 2005
    Posts
    2392
    You didn't try the resistor like I suggested?

    Re the configs, some of the later PICs have config bits that affect pin operation for the external TMR1 osc. I didn't check the 16F870 datasheet but since it's an earlier PIC there's probably no config needed.

  10. #10
    Join Date
    Dec 2003
    Posts
    24220
    Quote Originally Posted by RomanLini View Post
    You didn't try the resistor like I suggested?
    I am going to see if I can get back to it tonight or tomorrow.
    I even have a 7404 external xtal clock to mock up if all else fails.

    Quote Originally Posted by Iron-Man View Post
    Al, I have searched for the, TI0SO/TIOSI, TIM1 clock and cannot find it listed any where in the data sheet for the 16F870.
    Page 53 of the manual link you posted, pins 11 &12 of the 28 pin version, I really need it to work for the 16F628/A, I only mocked up the 870, as I had a proven Electronic Design that was close to what I was trying to do, and I wanted to see if the results were the same, which they were.
    The F628 is practically the same set up for the 32.768khz clock xtal.
    From what I have read so far, these watch xtal's are finicky to get started.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

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

  11. #11
    Join Date
    Jul 2004
    Posts
    127
    Al_The_Man,
    Could you clarify exactly what you're trying to do? I need clarification on something. Also, I haven't used the 16 series in years, but am very familiar with the 18 series. Just took a look at the 16F628 data sheet though.
    But this appears to refer to the FOSCI/FOSCI, main system clock?
    This is running OK as the program runs, it is the TI0SO/TIOSI, TIM1 clock, which appears to be LP type by default.
    Are you trying to run the microprocessor using 2 clocks (ie. 4MHz high speed for computations and 32KHz for low speed/sleep) or just 1 low speed clock (ie. main system clock is 32KHz for everything)? If the program is running, it is getting a FOSC from somewhere.
    As far as I have been able to tell in the documentation, the 16 bit configuration register does not apply to the TIM1 oscillator?
    I would agree with this, getting the 32Khz crystal working with timer1 should just be a matter of configuring the T1CON register correctly. In order to do this, it appears you have to set the following:
    T1CON.0 -> 1 Timer1 enabled
    T1CON.1 -> 1 external clock from in RB6/T1OSO
    T1CON.2 -> 1 Do not synch external clock input. (if you are using this for sleep then you need to make sure that this is not synchronized)
    T1CON.3-> 1 Oscillator enabled
    T1CON.4-5 -> configure prescale value (1:1 -> 1:8)
    T1CON.6,7 -> unimplemented- doesnt' matter.

    Note that the datasheet suggests 15pF, but acknowledge that these values may need to be changed.

    I may be (VERY possibly) remembering this incorrectly, but on some of the older chips (16F877?) I think putting a scope probe, even on 10X directly on the oscillator (this was the main external highest speed crystal oscillator, 20MHZ) caused it to not oscillate. Don't know what the inputs/outputs are like on the 628 when it's set up for T1osc mode. It may be worth the 15 minutes to hook up an HC04 or equivalent as a buffer so you can see it on the scope, or at least confirm that you can't see it on the scope...

    Hope this helps.

    -Matt

  12. #12
    Join Date
    Dec 2003
    Posts
    24220
    Quote Originally Posted by mcarvey View Post
    Al_The_Man,
    Could you clarify exactly what you're trying to do? I need clarification on something. Also, I haven't used the 16 series in years, but am very familiar with the 18 series. Just took a look at the 16F628 data sheet though.
    Basically I picked the bones out of this article and want to use the basic functions from it, it is a very simple application so it is frustrating when it doesn't pan out, I just adapted it for my app. using the 16F628.
    I need the precise 1 second clock, basically, to measure a low freq pulse.
    System clock and Tim1 clk, the only difference is I am using the internal system clock to run the main code, the article uses an external xtal system clock also.
    http://electronicdesign.com/article/...ncies8513.aspx
    I have the code which is no longer available since E.D. moved their site.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

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

  13. #13
    Join Date
    Oct 2005
    Posts
    2392
    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.

  14. #14
    Join Date
    Dec 2003
    Posts
    24220
    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

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

  15. #15
    Join Date
    Dec 2003
    Posts
    24220

    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.(nuts)
    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

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

  16. #16
    Join Date
    Jan 2007
    Posts
    355
    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. #17
    Join Date
    Oct 2005
    Posts
    2392
    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. #18
    Join Date
    Dec 2003
    Posts
    24220
    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

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

  19. #19
    Join Date
    Jan 2009
    Posts
    334
    Al, happy to see that you got it working.
    Its usually the small things that get in the way.

    Iron-Man

  20. #20
    Join Date
    Mar 2006
    Posts
    202
    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.)

Page 1 of 2 12

Similar Threads

  1. Optical Crystal
    By adrianhdezch in forum Laser Engraving / Cutting Machine General Topics
    Replies: 5
    Last Post: 09-02-2010, 07:26 AM
  2. Replies: 5
    Last Post: 08-04-2010, 11:33 PM
  3. Supply mini 2D/3D crystal laser subsurface engraving machine
    By 3dlasermachine in forum News Announcements
    Replies: 1
    Last Post: 09-08-2009, 04:15 AM
  4. laser cutting crystal
    By Jiepu-Crystal in forum Laser Engraving / Cutting Machine General Topics
    Replies: 0
    Last Post: 08-07-2009, 06:35 AM
  5. laser crystal
    By Jiepu-Crystal in forum Laser Engraving / Cutting Machine General Topics
    Replies: 0
    Last Post: 08-07-2009, 03:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •