Question about SuperCap on MCF5221X

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Question about SuperCap on MCF5221X

3,632 Views
junkers13
Contributor I
Hi I'm pretty new to programing the coldfire processor and was wondering how to enable the SuperCap such that the processor could continue to keep track of real time.  I have configured the RTC correctly but of course everytime I power down the board the time resets to its default.  Is there anyway to use the supercap on the board to keep the time? 

I'm using the MCF52210DEMO board.

Thank you.
Labels (1)
0 Kudos
8 Replies

1,323 Views
junkers13
Contributor I
After letting it charge for a while I unplugged the power (it is running off of the USB power) to the board and the voltage output of the cap was 3.1V.  I turned the board on and checked the real time then turned the board off and then turned it on again to find that the real time is still reseting.  Is there some sort of register I have to configure in order to get the board to use the battery?


Message Edited by joey c on 2008-06-04 04:23 PM
0 Kudos

1,323 Views
junkers13
Contributor I
The above post doesnt sound right.  I charged the cap and it measured a 3.1V output.  To see if it was working properly I powered the board with the USB, and checked the real time.  I then unplugged the usb power and then pluggged it back in and then checked the real time.  I thought the supercap would enable the processor to retain the real time, but the time had reset.  I'm not sure why.
0 Kudos

1,323 Views
mjbcswitzerland
Specialist V
Hi Joey

Are you sure that you have configured the RTC to operate from the external crystal (rather than from the system clock)?

Presently I don't have experience with this, although I have prepared code to test it. Possibly I can give more information shortly once my own tests have been carried out.

Regards

Mark

0 Kudos

1,323 Views
mjbcswitzerland
Specialist V
Hi Joey

I am hoping that we can help each other since I haven't any problems configuring the external 32k oscillator and maintaining data during power down period. When the board is powered down, the 32k crystal continues oscillating and after the next reset the RTC content has been maintained (no data reset).

However the problem that I do have is the same as in the following thread:
http://forums.freescale.com/freescale/board/message?board.id=CWCFCOMM&message.id=1871&jump=true#M187...

I have experimented for several hours but haven't managed to write the divide register (it refuses to read back anything else than 0x0000) and the RTC counters never increment. I can however write values to the RTC and these are correctly maintained.

If I understand correctly, you have your RTC operating (counting) but you can't keep values across power down. Mine won't count but does keep values. If we can bring out code together maybe it will result in a solution(???).

Note that I have used the RTC with the M5223X and M5222X (its control is a bit different and doesn't have 32k crystal support) without any difficulties. I have also checked the latest errata and see no problems with the RTC in the M5221X. Therefore I assume that it is a configuration issue which is difficult to identify. For example, I have found that bits 5 and 6 in the MCF_CLOCK_RTCCR register have undocumented functions and bit 6 MUST be set in order for the 32k crystal to oscillate.

Regards

Mark

0 Kudos

1,323 Views
junkers13
Contributor I
Sorry I didnt respond quicker but I totally forgot about the forum.  Ok I got it to work using the following code:
 
 
 //REAL TIME CLOCK CONFIG
  MCF_CLOCK_RTCCR=0b01010110; //RTCCC
  MCF_RTCGOCL = 0x00002000; //32KHz
  MCF_CLOCK_RTCCR=0b01010111; //RTCCC\
  
 
  MCF_RTC_HOURMIN = ((1 << 8) | 54);
  MCF_RTC_SECONDS = MCF_RTC_SECONDS_SECONDS(((hcc_u32)1 % 60));
 
Above is initializing the RTC.  This config shows the clock being set to 1:54.  Then to read from the clock I use:
 
   static unsigned int minutes;
   static unsigned int seconds;
   static unsigned int hours;
 
     
  hours = (hcc_u8)((MCF_RTC_HOURMIN  & 0x00001F00)>>8);   
  
  minutes = MCF_RTC_HOURMIN &0x3F<<0;

  seconds = MCF_RTC_SECONDS;
 
 
The Key thing that I didnt do in order to get the clock to continuosly run after power was off is that I kept initializing the RTC every time I flashed.  All you have to do is initialize it once and then comment that code out so you dont keep writing the same numbers to the register.  I thought I had debugged it before but then when I commented the init code out it worked fine, even after power was disconnected.
 
 
The next problem Im enduring is trying to figure out the RTC_DAYS register.  Is it my understanding that the only thing this register can do is increment when 24hrs has been reached?  So I have to take this number and convert it to accually represent a real date such as:  June 8th 2008?
 
0 Kudos

1,323 Views
mjbcswitzerland
Specialist V
Joey

Thanks, I think that I have managed to get it running now. The reason is the fact that writes to the RTCGOCL must be long word writes. 16 bit writes have no effect and it is not possible to write from the register view in the debugger since this (presumably) attempts 16 bit writes. Also the value written is not displayed in the CW7.0 register view (always displays 0x0000 even though the RTC is correctly counting seconds). Finally, the RTC registers do not show in the memory viewer (can't explain why).

I couldn't find the MCF_RTCGOCL definition in MCF52210.h so I assume you added it as unsigned long. The other guy added it as unsigned short (as I originally did too), which doesn't allow it to work.

The other misleading point is that the users' manual shows a table where 0x8000 is written for 32kHz but it seems as though 0x2000 really is the correct value...presumably the input is divided by 4 somewhere(?).

So that the RTC and oscillator are only configured once you can check the state of the RTCCR and jump the configuration if it is already configured (rather than downloading different code).

To use the day counter for data you will need to calculate the number of days after a specific reference date (eg. 1.1.2008). This is not that complicated since leap years occur every 4 years from, and including, 2008 - so any year dividable by 4 up to 2099 (then there is the next exeption to the rule).
Knowing the number of days in a year and days in each month, the exact data can be interpreted.

Regards

Mark

www.uTasker.com



Message Edited by mjbcswitzerland on 2008-06-09 10:07 PM
0 Kudos

1,323 Views
mjbcswitzerland
Specialist V
Hi

I now have a follow-up question.
Has anyone used the RTC in this device together with the internal system clock?

My first attempts at doing this were not successful - again, the RTC counter doesn't increment. In this case the RTCCR is set to 0x00 (also various other values tried) so that it uses the system clock.

Any ideas?

Regards

Mark

0 Kudos

1,323 Views
mjbcswitzerland
Specialist V
Hi Joey

Ensure that J4 is set to 1-2 so that the capacitor charges when 5V is applied.
The charging takes quite a long time, so it is best to monitor this with a voltmeter - it may take about 2 hours of charging before it reaches a voltage which will keep the internal RAM and RTC values.

Regards

Mark

www.uTasker.com

0 Kudos