FTDI Community

General Category => Discussion - Software => Topic started by: NW27 on June 25, 2018, 07:32:28 AM

Title: FT900 RTC Interrupt - Help needed
Post by: NW27 on June 25, 2018, 07:32:28 AM
Hi,

I have the RTC oscillator ticking over. So the RTC_start, RTC_Read, RTC_Write and RTC_Stop seem to be working.
It seems to be adding about 36 counts per second. Is this correct? This seems to be a bit of a strange value. How do you set a divisor for this?

Ultimately, what I would like to do is have a RTC interrupt that happens every second.

I am using the MikroC compiler from Mikro Electronica.
I have the RTC interrupt vector (void RTC_ISR() iv IVT_RTC_IRQ ics ICS_AUTO ) pointing to my RTC Time updating code but basically the system just locks up when I enable the interrupt
Using     RTC_IEN_bit = 1 ;
RTC_CCR looks like 0x00 00 00 05.

Do I need to do something at the end of the interrupt ie clear a flag etc?

Thanks,
Neil.

Code: [Select]
tByte rtc_start(void)
{
//    RTC->RTC_CCR |= MASK_RTC_CCR_EN;
    RTC_EN_bit = 1 ;
    return 0;
}


tByte rtc_stop(void)
{
//    RTC->RTC_CCR &= ~MASK_RTC_CCR_EN;
    RTC_EN_bit = 0 ;
    return 0;
}


tByte rtc_write(unsigned long val)
{
//    RTC->RTC_CLR = val;
    RTC_CLR = val;
    return 0;
}

tByte rtc_read(unsigned long *val)
{
//    *val = RTC->RTC_CCVR;
    *val = RTC_CCVR;
    return 0;
}


tByte rtc_init(rtc_wrap_t wrap)
{
    tByte iRet = 0;
    if (wrap > rtc_wrap_enabled)
    {
        iRet = -1;
    }

    if (iRet == 0)
    {
        rtc_write(0UL);

        switch(wrap)
        {
            case rtc_wrap_disabled: RTC_CCR |= RTC_WEN; break ;
            case rtc_wrap_enabled: RTC_CCR &= ~RTC_WEN; break ;
            default: break;
        }
    }

    RTC_IEN_bit = 1 ;
    return iRet;
}


void RTC_ISR() iv IVT_RTC_IRQ ics ICS_AUTO {
  tbyte a ;
  if (++RTClock.second==60)        //keep track of time, date, month, and year
  {
    RTClock.second=0;
    if (++RTClock.minute==60)
    {
      RTClock.minute=0;
      if (++RTClock.hour==24)
      {
        RTClock.hour=0;
        if (++RTClock.dow==7) RTClock.dow= SUN ;
        if (++RTClock.date==32)
        {

Etc etc
Title: Re: FT900 RTC Interrupt - Help needed
Post by: FTDI Community on June 25, 2018, 09:23:14 AM
Hello,

Since you are using the MikroC compiler from Mikro Electronica you will need to contact them for support.

Best Regards,
FTDI Community
Title: Re: FT900 RTC Interrupt - Help needed
Post by: NW27 on June 25, 2018, 10:35:35 AM
Hi,
It is your micro and I'm asking you for help with regard to usage of the interrupt registers in your micro.
I am not asking for help with the compiler.
Neil.
Title: Re: FT900 RTC Interrupt - Help needed
Post by: FTDI Community on June 25, 2018, 01:41:49 PM
Hello,

We provide some example code in AN_360 FT9xx Example Applications (http://brtchip.com/wp-content/uploads/Support/Documentation/Application_Notes/ICs/MCU/AN-360-FT9xx-Example-Applications.pdf).
See RTC Example 2 which demonstrates RTC interrupt every 2 seconds. This example should be useful to you.

These examples are provided with the free FT9xx Toolchain (http://www.ftdichip.com/Firmware/FT90xToolchain.htm) which is different from the MikroE tools.

Note that the RTC functionality between FT90x and FT93x is different and this is commented in the source code since the toolchain supports both MCU variants.
The RTC in FT90x is a simple counter. It provides information as a basic “system on” timer. The RTC in FT930 provides more detailed information and is powered by an external battery source.

Best Regards,
FTDI Community
Title: Re: FT900 RTC Interrupt - Help needed
Post by: NW27 on June 26, 2018, 06:59:49 AM
Hi,

When I perform a RTC_Read every 1Sec, I get a count difference of 32.

What would be the expected difference for a 32.768KHz osc?

Code: [Select]

int8_t RTC_Read(uint32_t *val)
{
    *val = RTC->RTC_CCVR;
    return 0;
}

main()
  RTC_Read(&a);
  delay_ms(1000);
  RTC_Read(&b);

  c = b-a ;
  // The value of C = 32

Title: Re: FT900 RTC Interrupt - Help needed
Post by: FTDI Community on June 28, 2018, 04:39:47 PM
Hello,

There is no benchmark data available on this however we could contact R&D to request more information on this if it's critical to your needs.

Please contact us at support1@ftdichip.com (support1@ftdichip.com).

Best Regards,
FTDI Community