[A20] RTC & 32k crystal

599 views
Skip to first unread message

Ivan Kozic

unread,
Jun 19, 2015, 6:04:37 AM6/19/15
to linux...@googlegroups.com
Hi all,

I seem to have weird issues with the RTC on A20 and was wondering if someone could help. I also think that this is a good topic since up to now I haven't been able to find much info on sunxi's integrated RTC on the web. Usually people just give up and use DS1307 or similar which I would avoid honestly.

So regarding issues, this is where I'm at right now:
1. Contrary to A20 datasheet, RTC VDD should be in fact 1.3V, just like on original Allwinner EVB and Olimex Olinuxino-Micro-A20. I have tried with 3V3 also (LDO1SET tied to VINT) and this fried RTC on one of my boards :(. Luckily the board is still functional, but RTC ain't coming back.

2. On the first board boot (no power applied before, no battery), RTC driver will complain that it can't set the LOSC to external oscillator. Don't really know why. It will also complain about time being wrong, but this is normal. After one reboot however, RTC will not complain about external oscillator anymore (implying that external is now working?) and will keep the time. From this moment on, if AXP is kept alive by either battery or backup battery, RTC will keep its time.

3. Up to now I haven't been able to see anything from 32k crystal on scope - no signal whatsoever, just some DC at the input and output. This could be due:
- 32k crystal not working (either something wrong on A20 SW side, or on pcb - caps not matched or similar),
- 32k crystal working, but scope probe capacitance kills the oscillations.
However, I can verify that RTC still ticks once the probe is on one of its pins...

I have almost ruled out the HW side, since all is good on the board (triple-checked, custom A20 board, behaves much like Olinuxino A20), so I'll be focusing on SW to see if there's something in the RTC driver which is wrong. Currently it's be very helpful if someone could shed some light on the following bits of LOSC_CTRL_REG:
- EXT_LOSC_GSM, no idea what it is, but sounds like gain - so far tried "10" (default) and "11", doesn't really have any effect,
- CLK32K_AUTO_SWT_PEND and CLK32K_AUTO_SWT_EN - haven't tried these, as I have no idea what they're for. Maybe for switching between internal/external oscillator?

So if anyone's got any thoughts or ideas, please share :) If I find something out, I'll post back as well.
Cheers!

Steven Saunderson

unread,
Jun 20, 2015, 7:32:28 PM6/20/15
to linux...@googlegroups.com
I think using the A20 RTC is an excellent idea.  Unfortunately some boards (e.g. Cubieboard2) don't have the 32k crystal or even any provision for adding such.  Other boards don't have any provision for an RTC battery which seems a very short-sighted move considering that most of what is required for this very basic facility is already present.

I have noticed that if the A20 RTC oscillator stops due to loss of power then it won't start automatically when the power is restored.  Perhaps this is what you're seeing.  The CubieTruck shows this because its tiny battery has a very limited supply duration.

I've fitted a 3V non-rechargeable battery to my OrangePi and the RTC does work.  I changed the AXP209 driver so I can enable/disable the RTC battery charge feature.  This change isn't really necessary because it is possible to load the registers via the /sys/bus/i2c/devices/0-0034/axp20-reg entry.

I have found that if the RTC stops the only way I can start it is by hwclock -w.  It generally takes 3 attempts before it works.

Cheers,
Steven

Ivan Kozic

unread,
Jun 22, 2015, 5:15:13 AM6/22/15
to linux...@googlegroups.com
Hi Steven,

Funny for Cubieboard - there's no Crystal in schematic, but there is one one the board :) Just above the DDR memory, clearly marked as 32.768 kHz. But agree that Cubieboard is very short-sighted (CSI port mess).

Yeah, I also agree on the RTC behavior - once the power is cut on my board it will not resume on its own, but this is ok for me. For brief power-cuts (couple of seconds), my huge power supply caps still supply the RTC, although a backup Li battery would be much better.
I've also concluded that my 32k crystal in fact works (took out crystal caps and the RTC speeded up to 15-30sec per second :) ). However I still find very strange that I can't see the wave on the scope - unlike Banana Pi on which 32k is easily seen.

I'm still interested in the bits of the LOSC_CTRL_REG, since my RTC seems very imprecise at the moment (lost 2 hours for the weekend), although I did play with the caps too much... By the way, the settings of this register are kept with 1V3_RTC, something people should watch out for when changing them.

Either way, contrary to other forum topics claiming that RTC on A20 is not functional, it in fact is functional, only no one had the time to play with it properly. What makes it currently unusable for me is that not everything is known and in this state it's too imprecise, but I guess I'll make it work, just need some time...
Cheers!

Steven Saunderson

unread,
Jun 23, 2015, 2:38:37 AM6/23/15
to linux...@googlegroups.com
 Hi Ivan,

I have an A20 Cubieboard, is yours the same ?  I can see the crystal on the board top next to the DRAM but I'm sure this is the 24Mhz crystal for the CPU.  There is also a 25MHz crystal under the board for the emac phy.

My RTC is running at a varying natural frequency.  It gains/loses between 16 seconds and about 20 minutes per day probably depending on the temperature.  But my CB2 is working and this is why I'm reluctant to drill holes in a attempt to connect to F1 and F2 balls on the SoC for the 32kHz crystal.

I agree that the A20 RTC is fine.  My CTs and OPi are all using this and keep time while powered off.

Does the LOSC_CTRL_REG setting specify whether to use the internal oscillator or an external source ?  Just a guess.

Cheers,
Steven

Ivan Kozic

unread,
Jun 23, 2015, 4:27:47 AM6/23/15
to linux...@googlegroups.com
Hi Steven,

Pretty sure :) That would be a very awkward place for a 24MHz crystal, since the balls for 24 MHz are on the other (right/down) side beside HDMI balls. The 32k crystal balls are exactly there and most boards (Cubie, Banana, Olinuxino) have the 32k crystal there. I also did the layout/schematic for our custom board and I've put it at the same place. If you look better on the underside - under SATA, just a bit above towards A20, you'll find the 24 MHz crystal in a nice flat SMD package. This is the main crystal.

But I'm used to this from Cubies - I'd say that out of all of the A20 boards, cubieboards are amongst the worst. Try finding the CSI0 clock in the schematic. There isn't one - they put the data lines out, but forgot the clock... Everything on these boards is somehow half finished.

What's also funny to me is that oscillations from 32k cannot be seen on any board I've seen (Cubie, Olimex, my custom...), except for Banana Pi (?!?). And they are very clean and nice on Banana... Strange.

Ok, wandered a bit OT... I'm wondering about these 20min/day - are you still talking about CB2? If so, it is either set to internal oscillator, or the caps are somewhat off on the 32k crystal. In fact the LOSC_CTRL_REG has the bit 0 (OSC32K_SRC_SEL) to select internal/external, but this bit is clear - I was more interested in the other bits, like EXT_LOSC_GSM...

If it is set to internal 32k (bit0 of LOSC_CTRL_REG), you can do a quick test - remove the 2 small caps beside the 32k oscillator (you can return them later) - hwclock will go crazy (like 15-50 sec per second). This way you'll know that it is in fact 32k crystal and that RTC is using it (this is how I figured out anyway). If you experiment with the caps, you can even make it more precise...

Cheers!

Steven Saunderson

unread,
Jun 23, 2015, 7:41:39 AM6/23/15
to linux...@googlegroups.com


On Tuesday, June 23, 2015 at 6:27:47 PM UTC+10, Ivan Kozic wrote:
Pretty sure :) That would be a very awkward place for a 24MHz crystal, since the balls for 24 MHz are on the other (right/down) side beside HDMI balls. The 32k crystal balls are exactly there and most boards (Cubie, Banana, Olinuxino) have the 32k crystal there. I also did the layout/schematic for our custom board and I've put it at the same place. If you look better on the underside - under SATA, just a bit above towards A20, you'll find the 24 MHz crystal in a nice flat SMD package. This is the main crystal.

Thanks for this; it looks like you're right.  One side of my crystal was floating at about 1.3V and the other side had AC noise.  When I wrote 0x16aa4009 to LOSC_CTRL_REG I saw that both legs of the crystal now have AC noise.  But I'm still losing about 3 seconds / minute so it's not really a very useful clock.  LOSC_CTRL_REG seems  to default to bit 0 on after a power off.

My schematic is for a CB1 (A10) and maybe my CB2 is slightly different.  I've seen mention that the internal oscilattor to be 32kHz +/- 20% which sounds pretty sloppy to me.  So I've set the bit to use the external oscillator (does this mean just the crystal or is some kind of fully-fledged oscillator required ?) and I'm still losing 2 or 3 seconds / minute.  This is the same as when I select the internal oscillator.

So the timing is pretty lousy.  Strange because the RTC works well on the CTs.  The other thing I've noticed is that the RTC battery (2025) has gone flat in about 2 months.  Maybe I need a reghargeable battery and to modify the AXP209 settings to charge this battery.

Cheers,
Steven

Ivan Kozic

unread,
Jun 23, 2015, 8:23:54 AM6/23/15
to linux...@googlegroups.com
Hi Steven,


Thanks for this; it looks like you're right.  One side of my crystal was floating at about 1.3V and the other side had AC noise.  When I wrote 0x16aa4009 to LOSC_CTRL_REG I saw that both legs of the crystal now have AC noise.  But I'm still losing about 3 seconds / minute so it's not really a very useful clock.  LOSC_CTRL_REG seems  to default to bit 0 on after a power off.

LOSC_CTRL_REG along with some other Timer regs is kept with 1V3 RTC; once this is gone (power failure) it will restart to internal... Seems like a default behavior. Regarding 3 seconds... either the caps are badly matched, or the crystal is crap - you can get a similar Citizen or ECS (they're called tuning fork crystal) from Digikey or Farnell and replace that one on the board and also replace and rematch the caps. Then it should be quite good. Something like:

http://www.digikey.com/product-detail/en/ECS-.327-12.5-13FLX-C/XC1911TR-ND/2781916


My schematic is for a CB1 (A10) and maybe my CB2 is slightly different.  I've seen mention that the internal oscilattor to be 32kHz +/- 20% which sounds pretty sloppy to me.  So I've set the bit to use the external oscillator (does this mean just the crystal or is some kind of fully-fledged oscillator required ?) and I'm still losing 2 or 3 seconds / minute.  This is the same as when I select the internal oscillator.

I think both CB1 and CB2 are covered with the same crappy schematic. Pretty sure that Crystal is needed for RTC, not full oscillator (you have both IN & OUT ports on the CPU, so it's made for crystal). Regarding crappy timing, as I said - try either to rematch caps (but that will be hard, as we don't know what is load capacitance of this 32k crystal that CB2 has) or just replace all together (probably for a price of 1,- EUR).

So the timing is pretty lousy.  Strange because the RTC works well on the CTs.  The other thing I've noticed is that the RTC battery (2025) has gone flat in about 2 months.  Maybe I need a reghargeable battery and to modify the AXP209 settings to charge this battery.

Well that's not good news... I also need to think about the battery, but I thought that maybe supercap would do a better job, although I'm not sure anymore...

By the way - how do you measure the RTC error? I haven't found a nice way to do it properly - usually I just set the same time like on Windows/Linux and wait for couple of hours and then check again... But there has to be a better/nicer way to do this :) I've also tried to compare hwclock to system time, but this is also not really elegant, especially because I'm not sure which one is right...

Cheers,

Ivan

Steven Saunderson

unread,
Jun 24, 2015, 11:23:27 PM6/24/15
to linux...@googlegroups.com
Hi Ivan,

I've just replaced the 32kHz crystal on my CB2 but it's still losing about 2 secs / minute.  Could be a problem with the trim caps but my eyesight isn't quite up to playing with them at the moment.

My CR2032 battery (installed new about a week ago) has dropped to 2.8V already so it looks like there is an excessive drain into the AXP209.  This could be a problem with my soldering a lead to pin 30 of the AXP.

I'll persevere with this for  a bit but the idea of fitting a DS1307 module sure is looking attractive.

You are right about the 32kHz crystal which doesn't show up on the schematic.  I expect that the replacement crystals I bought should be a lot more accurate than appears here.  Changing bit 0 of the osc_ctrl_reg (internal/external oscillator) doesn't appears to make any difference.

Cheers,
Steven

Ivan Kozic

unread,
Jun 29, 2015, 4:05:25 AM6/29/15
to linux...@googlegroups.com
Hi Steven,

Regarding the 2sec/minute - it's probably crystal caps...

This with the consumption also looks weird - I'll measure mine today, although I do not have backup battery so I'll measure from ACIN.

I'll post back the results.

Cheers!

Ivan Kozic

unread,
Jun 29, 2015, 6:44:36 AM6/29/15
to linux...@googlegroups.com
Hi Steven,

I've just measured the power consumption fro 5V (ACIN). I've powered the board on, setup the clock then did a poweroff. I've powered on again just to be sure that the clock is actually ticking (it is), then powered down again. Consumption is around 280-290uA when the board is powered off, and I can confirm that this is only AXP running LDO1, although I do have some 0.5V at the output of 5V boost (not sure if this is my error or there's some leakage, have to check). So 5V*300uA = 1.5mW. 1.5mW/3V = 500uA from backup battery.

Looking at Panasonic CR2032 which has a capacity of 225mA, theoretically we should get around 450 Hours from it. Not really years, but little less than 3 weeks for sure... Still doesn't sound perfect, but I guess it's enough for me.

DS1307 solution sounds good, but it's way too expensive for me. Besides, I would want to use A20's RTC if it's already there...
Cheers,

Ivan

Ivan Kozic

unread,
Jun 29, 2015, 9:07:53 AM6/29/15
to linux...@googlegroups.com
Hi Steven,

Ok, now I've soldered backup battery directly to AXP's pin and hooked up the Multimeter to it. It's a standard 3V CR2032 Renata (225 mAh). Test setup:
- power on the system and set any time (just so that RTC is set and ticking),
- power down the system and cut all power/data cables to it (even uart),
- measure the current going out of CR2032,
- put UART and power back, power on and check the time.

Findings:
- when system is fully powered on or powered off and has mains power (VIPS is present), there's 100nA of reverse current (charging current) to the CR2032,
- when system is powered off and there's no additional power (no USB, no ACIN, no power except for CR2032), after transient, there is maybe 25-30 uA consumption from the CR2032.
- clock was normally ticking all the time, although loosing some seconds due to mismatched crystal caps.

For me this is good enough - I'd like it to be even less, but if you calculate the values, you'd get around 1 year from a standard (225mA) CR2032, which is enough for me. If I get the time, I'll leave the clock set up over night (at one point I need to do this, but don't know when I'll have time) and check it in the morning and of course post back.

Cheers,

Ivan

Steven Saunderson

unread,
Jun 29, 2015, 3:28:17 PM6/29/15
to linux...@googlegroups.com
Hi Ivan,

Thanks fo all your work here.  I'll try to remove the caps from my Cubieboard2 tonight and see if that makes any difference.

Your RTC battery consumption sounds okay.  I'll compare mine.  If excessive I could fit a more expensive rechargeable battery instead.

Are you seeing AC noise on both legs of your crystal ?  One thing that surprised me is that one leg of mine is at 1.3V which doesn't sound right.  Also, if I read the LOSC_CTRL_REG on the Cubieboard2 I always get 0x2009 whereas on other A20 boards I always get 0x0009.  The 0x2000 bit is undocumented.

I note your earlier comment that RTCVDD should be only 1.3V.  This is minetioned in the updates in my A20 manual.  The menyion here implies that the previous manual was wrong.

Cheers,
Steven

Ivan Kozic

unread,
Jul 1, 2015, 5:21:52 AM7/1/15
to linux...@googlegroups.com
Hi Steven,

See my comments below.


On Monday, June 29, 2015 at 9:28:17 PM UTC+2, Steven Saunderson wrote:
Hi Ivan,

Thanks fo all your work here.  I'll try to remove the caps from my Cubieboard2 tonight and see if that makes any difference.

Awaiting for results :)

Your RTC battery consumption sounds okay.  I'll compare mine.  If excessive I could fit a more expensive rechargeable battery instead.

Yes, sounds ok, but should probably be even less (DS1307 takes 500nA or similar). However, this is just fine for me.

Are you seeing AC noise on both legs of your crystal ?  One thing that surprised me is that one leg of mine is at 1.3V which doesn't sound right.  Also, if I read the LOSC_CTRL_REG on the Cubieboard2 I always get 0x2009 whereas on other A20 boards I always get 0x0009.  The 0x2000 bit is undocumented.

Hmm, I have to take a scope and check - will do it later today. As I said, funny thing is that I can only see real oscillations on Banana Pi, all the other boards have 0.4V on one leg and 1.3V on the other. Some small noise is visible, yes, but nothing too drastic. I'll try to make some photos and record some data today and post back.

I note your earlier comment that RTCVDD should be only 1.3V.  This is minetioned in the updates in my A20 manual.  The menyion here implies that the previous manual was wrong.

I agree, this is true 100%. VDD_RTC should be 1.3V. I've tried with 3.3V on one board and fried RTC on it :) So, LDO1SET should be pulled to the ground not Vint. What updates do you mean by the way? Is this a personal list, or is there an official document from someone?

Cheers,
Steven

Cheers,

Ivan

francesc...@gmail.com

unread,
Jul 5, 2015, 6:39:03 AM7/5/15
to linux...@googlegroups.com
Hi,

On Wednesday, July 1, 2015 at 11:21:52 AM UTC+2, Ivan Kozic wrote:
> I note your earlier comment that RTCVDD should be only 1.3V.  This is minetioned in the updates in my A20 manual.  The menyion here implies that the previous manual was wrong.
>
>
> I agree, this is true 100%. VDD_RTC should be 1.3V. I've tried with 3.3V on one board and fried RTC on it :) So, LDO1SET should be pulled to the ground not Vint. What updates do you mean by the way? Is this a personal list, or is there an official document from someone?

He probably meant the A20 datasheet, available at https://github.com/allwinner-zh/documents/blob/master/A20/A20_Datasheet_v1.5_20150510.pdf.
In the revision history there is an entry for revision 1.2 that reads "Revize VDD-RTC to 1.3V". In fact, the recommended operating conditions table at Section 5.2 reports MIN 1.2V, TYP 1.3V, MAX 1.4V for VDD-RTC.

Francesco

Steven Saunderson

unread,
Jul 27, 2015, 2:18:23 AM7/27/15
to linux-sunxi, jimm...@gmail.com


On Wednesday, July 1, 2015 at 7:21:52 PM UTC+10, Ivan Kozic wrote:
Hi Steven,

See my comments below.

On Monday, June 29, 2015 at 9:28:17 PM UTC+2, Steven Saunderson wrote:
Hi Ivan,

Thanks fo all your work here.  I'll try to remove the caps from my Cubieboard2 tonight and see if that makes any difference.

Awaiting for results :)

Hi Ivan,

This is all Cubieboard2 specific.  I removed the caps and the RTC then lost about 3 seconds per minute (was 2 seconds per minute).  I fitted some 22pf caps and it's back to losing about 2 seconds per minute.  The DC reading on each leg of the crystal is about 0.66V.  As before reading the LOSC_CTRL_REG gives me 0x2009 whereas other A20 boards return 0x0009.  The odd thing is that If I short the crystal the RTC gains about 6 seconds per minute and reading LOSC_CTRL_REG gives me 0x0009.

The RTCs in my other boards (CubieTruck, Orange Pi) work properly.  Maybe I've wrecked the RTC on the CB2.  The DS1307 modules I've fitted to my Raspberry Pis work well.  I'd say the CB2 RTC is a lost cause.

Cheers,
Steven

Maksims Matjakubovs

unread,
Nov 27, 2017, 4:56:36 AM11/27/17
to linux-sunxi
Hi all,

  Here will be my experience with RTC on Alwinner V3s (LicheePi Zero board).
  Solution - 32.768khz crystal need 10 Mohm resistor in parallel. (board did not have it soldered on)
  Without this resistor there is no frequency generation at all.
  Tried enable RTC by forcing switching ( bit(15) of config register , clock stop ticking ).
  If clock auto switch going enabled, RTC check external frequency and switch to it if exist or return back to unprecise one inside.

Best regards,
Maksims
Reply all
Reply to author
Forward
0 new messages