• AVR Freaks

Hot!Precision Internal Oscillator PIC18

Author
DanielSph
New Member
  • Total Posts : 8
  • Reward points : 0
  • Joined: 2021/01/08 02:47:58
  • Location: 0
  • Status: offline
2021/01/10 09:31:53 (permalink)
0

Precision Internal Oscillator PIC18

Hello,
I am using the PIC18F27K42, and need a 1 second time base for the device to be synchronized with the current time while it is asleep.
 
I was using an external 32 kHz clock and everything was working fine. But I found an anomaly, and that is when I feed the system through a boost Vout:4.2V + LDO Vout:3.3V. The device doesn't wake up and stays dead, it doesn't skip the 1 second interruption. But if I remove the boost charger and replace it with a 4.2V voltage as the LDO input, the system works perfectly.... It is possible that the output of the boost charger is interfering with the clock...
 
For this reason I have switched to using an internal clock, as with this clock the device does wake up when it is asleep. I have tried HFINTOSC , MFINTOSC and LFINTOSC but they have a ±30 seconds delay every hour, which causes the device not to be synchronized with the current time.
 
How can I get an accurate 1 second TIMER using an internal clock?
Thank you.
#1

14 Replies Related Threads

    RISC
    Super Member
    • Total Posts : 5961
    • Reward points : 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/10 16:06:20 (permalink)
    +1 (1)
    Hi,
    Please show your code (zip the project and add .txt so that you can upload it).
    I suggest you make a simple project that only uses 32kHz XTAL + TIMER1.
    The only way to have an accurate 1s is indeed to use 32khz XTAL.
    Whatever type of power supply you use for the PIC (within specs), it should wake up is the code is correct (unless there is a silicon bug documented).
    Which capacitor values did you use around the 32kHz XTAL ?
    Maybe your power supply generates too much noise...
    Regards
    post edited by RISC - 2021/01/10 16:15:13

    For support make sure to check first here : http://microchipdeveloper.com
    There are hundreds of PIC, AVR, SAM...which one do YOU use ?
    #2
    ric
    Super Member
    • Total Posts : 29869
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Precision Internal Oscillator PIC18 2021/01/10 16:13:02 (permalink)
    +2 (2)
    30 seconds in an hour is about 0.8% error, which is well within the specified 2%.
    You cannot expect better from the internal oscillator.
    You will need to fix the power supply problem so you can continue using the external crystal.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    marksullivan
    Super Member
    • Total Posts : 128
    • Reward points : 0
    • Joined: 2010/10/25 16:51:05
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/10 17:05:35 (permalink)
    0
    As others have said, the accuracy of the internal clock is pretty bad.  You could individually calibrate your devices if there is any other time reference in the system.  A crystal is probably cheaper than an explicit calibration step in production.
     
    You say "external clock" but do you mean an external oscillator or an external crystal on the internal oscillator?  If it's  a crystal, then try some different capacitor values.  Look at OSCO with a 'scope.  If it's clipping, add a resistor in series with the crystal.  
     
    Look at your power supply with a 'scope.  Make sure you have ceramic caps tightly coupled to the power supply pins of the MPU.  Follow the layout guidelines (Fig 2-3 of the data sheet) around the oscillator to minimize pick-up of stray noise.
     
    Have you thought of putting a crystal or resonator on the secondary oscillator on RC0 and RC1?  Some of the timers can use this clock even though the CPU is running on the primary, internal oscillator.
     
     
    #4
    ric
    Super Member
    • Total Posts : 29869
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Precision Internal Oscillator PIC18 2021/01/11 02:21:22 (permalink)
    +2 (2)
    The last post in this thread has vanished, so it probably contained a variation of "i-pod" and triggered the web server firewall.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    DanielSph
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2021/01/08 02:47:58
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/11 03:10:31 (permalink)
    0
    Hello,
     
    I attach the code, it's very simple.
     
    I am using PIC18F27K42, a 8MHz clock(ABM3B-8.000MHZ-10-1-U-T) connected to RA7 and RA6. And a 32kHz clock(ABS07W-32.768KHZ-D-1-T) connected to RC0 and RC1, with 3pF capacitors(C0603C309C3HACTU).
     
    This is the general scheme. And when the battery is charged, it stops working on:
     
    However, if I remove the charger everything works perfectly...
     
    Regards
    #6
    DanielSph
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2021/01/08 02:47:58
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/11 03:12:03 (permalink)
    0
    Attach 

    Attached Image(s)

    #7
    Mysil
    Super Member
    • Total Posts : 4114
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: online
    Re: Precision Internal Oscillator PIC18 2021/01/11 04:45:56 (permalink)
    +1 (1)
    Hi,
    There is competition between microcontroller manufacturers, about designing and producing devices that are able to work with low current consumption while in sleep mode, for use in battery powered products.
     
    In this connection, current used by crystal oscillator circuit for 32.768 kHz watch crystal amplifier is significant.
    These crystals may work with very low power levels, which may make the oscillator amplifier voulnerable to any kind of interference.
     
    In Datasheet for various PIC microcontrollers, there are layout suggestions for crystal and components with groundplane and grounded guard traces around the crystal and it's capacitors. What is the actual layout of the circuit board?  Are power pins correctly decoupled?
     
    Is there any way switching noise from the battery charger, can reach into PIC power lines, or get routed near crystal circuit and connections?
    Are there any harmonic frequency produced by the battery charger close to the oscillation frequency of the watch crystal?
     
    With microcontrollers designed for, and used with higher clock frequency, there is increased attention to EMC matters. Layout, grounding, decoupling, filtering and components used may matter. 
     
    In hookup suggestions for some PIC microcontrollers, there are suggestions to introduce a ferrite bead in power trace between (LDO) regulator and microcontroller. In that case, there should be stabilisation capacitor on output from LDO, and decoupling capacitor on power pin of microcontroller.
    This is to reduce spread of EMC noise between different parts of the layout.
     
        Mysil
     
    #8
    oliverb
    Super Member
    • Total Posts : 403
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/11 07:11:12 (permalink)
    0
    I would try supplying a 32kHz clock signal,just to confirm that the firmware is working as expected. There could be some kind of "red herring" at work here such as trying to count in sleep with the timer set to synchronised input?
     
    Also another wierd thing to look for is some watch crystal circuits take a crazy time to start, you may be dependant on supply noise to start the clock.
    #9
    DanielSph
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2021/01/08 02:47:58
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/12 00:33:58 (permalink)
    0
    Hi,
     
    On the 3.3V line which is the LDO output and Vdd input there is a 100uF, 100nF, 100pF, 22pF capacitor branch. I don't think that's the problem here.
     
    The firmware works correctly, the problem is in the charger BQ25505, because if I connect it the 1 second interruption stops working, and if I disconnect it it works. I don't understand.
     
    Another thing that happens is that if the battery is at 3.7V, the line of 4.2V is at 3.75V (Battery charging) the interruption works. It fails when the amplitude is 4.2V and the charger is on.
     
    Around the clock there is a GND plane, and the charger coil is "far away".
     
    Thank you.
    Regards

    Attached Image(s)

    #10
    Howard Long
    Super Member
    • Total Posts : 887
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/12 16:42:17 (permalink)
    0
    Mysil
    In this connection, current used by crystal oscillator circuit for 32.768 kHz watch crystal amplifier is significant.
    These crystals may work with very low power levels, which may make the oscillator amplifier voulnerable to any kind of interference.

     
    FWIW it varies between devices. The lowest I've managed on a PIC SOSC+TMR1 is on a PIC18F97J94, 229nA at 3.0V and 184nA at 2.0V with the regulator disabled. Mostly I measure between about 600nA and 1uA for SOSC+TMR1+sleep. These figures are for devices not using the internal voltage regulators, so PIC16LF devices and PIC18FxxJxx for example. The internal regulators, including the "low power" regulators add another dimension, often not what you'd like.
     
    ************
     
    While it will hit the BOM cost ($1.50@1ku), I've started using an RTCC from Micro Crystal, RV-3028-C7, which incorporates its own crystal, 1ppm factory calibrated, and boasts 45nA with no active output. Programmed with a 1Hz output, I achieved 50nA and that's nearly constant throughout its voltage range. Note that if you program it to output for a higher frequency, its native internal 32kHz crystal, the current rises dramatically to just under a uA on this push-pull output. There's also a programmable open drain output. There are some other nice features like Vbat/cap backup and integrated Vbat/cap charging simplifying the BOM. Although it's I2C, you can program it up once and store the config in its internal EEPROM. You can use a SOT23-10 breakout board (0.95mm pitch) for prototyping although the device is an eight pin 0.9mm pitch DFN.
     
    Attached is some code that programs the RTCC for a 1Hz output, written for a PIC16LF1518 on a Curiosity HPC and the Mikroe RTC 8 Click breakout baord for this part.
    post edited by Howard Long - 2021/01/12 16:43:21
    #11
    DanielSph
    New Member
    • Total Posts : 8
    • Reward points : 0
    • Joined: 2021/01/08 02:47:58
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/25 01:12:44 (permalink)
    0
    Finally, I will redesign the PCB. I'm going to add three decoupling capacitors near the mic input of 100nF, 10nF and 1nF.
     
    Which crystal reference do you recommend? I am currently using ABS07W-32.768KHZ-D-1-T, but it is not behaving well with the BQ25505 charger.
     
    Do you recommend me to make any more changes?
     
    Thank you.
    Best regards.
    #12
    oliverb
    Super Member
    • Total Posts : 403
    • Reward points : 0
    • Joined: 2009/02/16 13:12:38
    • Location: 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/25 01:39:13 (permalink)
    0
    I would want to find out what it is that actually stops the clock. From the way you've described it there isn't an obvious difference between working with the charger and without it apart from the clock. Can you use a CLC to route the 32kHz signal to another pin so you can monitor it directly?
     
    The boost circuit has to be a switching regulator, which could mean unexpected ground currents flow when it is operating.
     
    How this affects the 32kHz circuit though I can only speculate. Maybe the boost circuit runs near 32kHz and is somehow able to "jam" it as that sort of frequency would be high enough to not make audible whistle, but low enough to allow simple switching components.
    #13
    blue_led
    New Users
    • Total Posts : 89
    • Reward points : 0
    • Status: offline
    Re: Precision Internal Oscillator PIC18 2021/01/25 10:11:45 (permalink)
    +2 (2)
    DanielSph
     with 3pF capacitors(C0603C309C3HACTU).



    such low value ?  i will go for 15-22 pF.
    https://ww1.microchip.com...AppNotes/00001798a.pdf
     
    #14
    Jump to:
    © 2021 APG vNext Commercial Version 4.5