CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help ! 18f67k22 RTC
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 5:57 pm     Reply with quote

PCM programmer wrote:
I don't know if I can do anything more right now. Today is a holiday in
the U.S. Tomorrow morning, I could try to make it work in hardware.
I don't have your K22 series PIC, but I think I may have another PIC
that has SOSC and RTCC in it. I could try to make that work. But this
won't happen until tomorrow.


Alright!
You helped a lot!
If you can do this test to help me, I will be very grateful!
I think can find the solution.
So you can help me.
Then put your code used!
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 22, 2012 9:26 pm     Reply with quote

The code is nothing more than what I've already posted. Fuses:
Code:
#FUSES SOSC_HIGH
#FUSES RTCOSC_T1
and:
Code:
setup_rtc(RTC_ENABLE, 0);
For testing, I'd recommend:
Code:
setup_rtc(RTC_ENABLE | RTC_OUTPUT_SECONDS, 0);
Then put a 'scope on to pin 8 (G4/RTCC) and confirm there is a 1Hz square wave.

However, from looking at the photos of the PCB, there don't appear to be any load capacitors. Microchip recommends 10pF caps between each of the crystal legs and ground.

...OK, I've just read that you acknowledge you've tried capacitors and they appeared to do nothing. Let me assure you that without them it is definitely NOT going to work, and without them you're wasting everyones time. Put them on, try again, and perhaps some more photos with the caps in place?
_________________
Andrew
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 22, 2012 9:40 pm     Reply with quote

Here is a complete app that works on my board. Please review the fuses to make sure they are *all* appropriate for your project:
Code:
#include <18F67K22.h>
#device adc=12

#FUSES VREGSLEEP                //Ultra low-power regulator is disabled
#FUSES INTRC_LP                 //LF-INTOSC in Low-Power mode during Sleep
#FUSES SOSC_LOW                 //Low-power SOSC circuit is selected
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES HSM                      //High speed Osc, medium power 4MHz-16MHz
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_NOSLEEP              //Watch Dog Timer, disabled during SLEEP
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES RTCOSC_T1                //RTCC uses Secondary Oscillator as reference source
#FUSES CCP2E7                   //CCP2 input/output multiplexed with RE7
#FUSES MSSPMSK7                 //MSSP uses 7 bit Masking mode
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BBSIZ1K                  //1K words Boot Block size
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //Configuration registers not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=16M,restart_wdt)

void main(void)
{
  setup_rtc(RTC_ENABLE|RTC_OUTPUT_SOURCE,0);
}

That results in a 32.768kHz output on G4/RTCC, easily confirmed with a 'scope.

That code is working for me. As I mentioned above, I would recommend using SOSC_HIGH instead of SOSC_LOW, at least to start off with to get things going.
_________________
Andrew
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 6:57 am     Reply with quote

andrewg wrote:
Here is a complete app that works on my board. Please review the fuses to make sure they are *all* appropriate for your project:
Code:
#include <18F67K22.h>
#device adc=12

#FUSES VREGSLEEP                //Ultra low-power regulator is disabled
#FUSES INTRC_LP                 //LF-INTOSC in Low-Power mode during Sleep
#FUSES SOSC_LOW                 //Low-power SOSC circuit is selected
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES HSM                      //High speed Osc, medium power 4MHz-16MHz
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES WDT_NOSLEEP              //Watch Dog Timer, disabled during SLEEP
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES RTCOSC_T1                //RTCC uses Secondary Oscillator as reference source
#FUSES CCP2E7                   //CCP2 input/output multiplexed with RE7
#FUSES MSSPMSK7                 //MSSP uses 7 bit Masking mode
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BBSIZ1K                  //1K words Boot Block size
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //Configuration registers not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=16M,restart_wdt)

void main(void)
{
  setup_rtc(RTC_ENABLE|RTC_OUTPUT_SOURCE,0);
}

That results in a 32.768kHz output on G4/RTCC, easily confirmed with a 'scope.

That code is working for me. As I mentioned above, I would recommend using SOSC_HIGH instead of SOSC_LOW, at least to start off with to get things going.


Thanks for the help andrewg,

I will test later today when I get to work.
A news post here.

I did everything as you suggested.

I believe that I have some other configuration interfering with the operation of the clock!!

I'll check that today.
I'll put the same code that you used to verify the operation!

You used the 10pF capacitor?

Any other tips for when I test soon arrive at work?

4 hours will tests.

thank you
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Nov 23, 2012 7:57 am     Reply with quote

As I mentioned, I used 15pF capacitors, and they may be why I'm seeing a 60ppm error instead of an expected +/- 20ppm error. I'm not too worried about that as each unit will be calibrated using GPS PPS.

One idea if you're having problems fitting load capacitors is to locate the crystal further away from the micro and rely on the extra capacitance resulting from the additional track length, rather than actual capacitors. I can't say I'd recommend that in general, it's more of a last resort type of idea.
_________________
Andrew
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 9:13 am     Reply with quote

andrewg wrote:
As I mentioned, I used 15pF capacitors, and they may be why I'm seeing a 60ppm error instead of an expected +/- 20ppm error. I'm not too worried about that as each unit will be calibrated using GPS PPS.

One idea if you're having problems fitting load capacitors is to locate the crystal further away from the micro and rely on the extra capacitance resulting from the additional track length, rather than actual capacitors. I can't say I'd recommend that in general, it's more of a last resort type of idea.


Good idea.
but even without the capacitors should work, right?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 10:08 am     Reply with quote

Unrelated to the RTC problem, but just an error I spotted:
Code:
setup_spi2(SPI_SS_DISABLED);
This code was generated by an old CCS Code Wizard but is an invalid configuration with unknown results. Change to:
Code:
setup_spi2(FALSE);
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Fri Nov 23, 2012 11:00 am     Reply with quote

lucasromeiro wrote:
but even without the capacitors should work, right?
Wrong. I would expect it to not work without appropriate load capacitors.
_________________
Andrew
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 1:18 pm     Reply with quote

andrewg wrote:
lucasromeiro wrote:
but even without the capacitors should work, right?
Wrong. I would expect it to not work without appropriate load capacitors.

I tested your code here.
In the simulation in proteus, works perfectly.
but the real test does not work when recorded on the project.
strange, since I put the capacitors but nothing changed.

help
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 8:21 am     Reply with quote

I do not understand, the simulation works and does not work on the board.
Can someone help me??
Ttelmah



Joined: 11 Mar 2010
Posts: 20161

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 8:50 am     Reply with quote

This is why we hate Proteus.

Proteus knows nothing about real clocks. So if you tell it the processor or timer has a particular clock it'll merrily run, even if the real circuit cannot work, because the capacitors are too large, shorted, not connected properly, etc.. etc.....

Realistically, take a deep breath, and check everything. Are the capacitors in pF (if for instance you use 10nF, instead of 10pF, that will stop the oscillator working)?. Check with a meter that pins are not shorted anywhere. Look three times with a magnifying glass at every connection, then check it again.

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 8:59 am     Reply with quote

Quote:
I do not understand, the simulation works and does not work on the board.
Can someone help me??

You've just learned important lesson No 1.

Proteus is a waste of time, yours' and ours.

You will also have to learn how to debug.

You've been given loads of hints and useful tips.

Go through them all VERY carefully.

You're the one with the board in front of you, We can't see it, we can only work from what yo tell us. The more you tell us, and the more accurate it is, the better we can help you .

Good luck.

Mike

EDIT. I tried to follow the links to your board. All I got was adverts, so gave up.
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 9:04 am     Reply with quote

Ttelmah wrote:
This is why we hate Proteus.

Proteus knows nothing about real clocks. So if you tell it the processor or timer has a particular clock it'll merrily run, even if the real circuit cannot work, because the capacitors are too large, shorted, not connected properly, etc.. etc.....

Realistically, take a deep breath, and check everything. Are the capacitors in pF (if for instance you use 10nF, instead of 10pF, that will stop the oscillator working)?. Check with a meter that pins are not shorted anywhere. Look three times with a magnifying glass at every connection, then check it again.

Best Wishes



Stranger in proteus have worked perfectly and not on the board.

I have 2 boards alike, they have been verified and is not short.
Ja called oscillators with and without capacitor capacitor, the capacitor used right, but nothing changed.

All other functions work correctly.

I tested the code posted above and still nothing worked!

Totally weird!!

I tested several times on both boards but nothing worked.
Always check with the oscilloscope if the crystal vibrates, but does not work ever.

very strange

I need help, someone can test more on a card?

Thank you!
lucasromeiro



Joined: 27 Mar 2010
Posts: 167

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 9:12 am     Reply with quote

Mike Walne wrote:
Quote:
I do not understand, the simulation works and does not work on the board.
Can someone help me??

You've just learned important lesson No 1.

Proteus is a waste of time, yours' and ours.

You will also have to learn how to debug.

You've been given loads of hints and useful tips.

Go through them all VERY carefully.

You're the one with the board in front of you, We can't see it, we can only work from what yo tell us. The more you tell us, and the more accurate it is, the better we can help you .

Good luck.

Mike

EDIT. I tried to follow the links to your board. All I got was adverts, so gave up.


Thanks for the tips!

I'm working and following the tips, but nothing had an effect. mechi not like that at all, nuit stranger, without any response, in both plates

I sent the photos to see vcs p plate which is connected correctly,
Now I'll post the code I used:

Code:

#include <18F67K22.h>
//#device adc=12

#FUSES VREGSLEEP                //Ultra low-power regulator is disabled
#FUSES INTRC_LP                 //LF-INTOSC in Low-Power mode during Sleep
#FUSES SOSC_high                 //Low-power SOSC circuit is selected
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES HSM                      //High speed Osc, medium power 4MHz-16MHz
#FUSES NOPLLEN                  //4X HW PLL disabled, 4X PLL enabled in software
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
//#FUSES WDT_NOSLEEP              //Watch Dog Timer, disabled during SLEEP
//#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES RTCOSC_T1                //RTCC uses Secondary Oscillator as reference source
#FUSES CCP2E7                   //CCP2 input/output multiplexed with RE7
//#FUSES MSSPMSK7                 //MSSP uses 7 bit Masking mode
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES BBSIZ1K                  //1K words Boot Block size
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTC                   //Configuration registers not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

//#use delay(clock=20M,restart_wdt)
#use delay(clock=20000000)


#use rs232(baud=19200,parity=N,xmit=PIN_G1,rcv=PIN_G2,bits=8,stream=Modem,restart_wdt,errors)


#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt,errors)

#include <string.h>



void Mostra_Hora();
void set_clock(rtc_time_t &date_time);

   unsigned int8 dia=0;
   unsigned int8 mes=0;
   unsigned int8 ano=0;
   unsigned int8 hora=0;
   unsigned int8 min=0;
   unsigned int8 seg=0;



   rtc_time_t write_clock, read_clock;


void main(void)
{


 setup_rtc(RTC_ENABLE|RTC_OUTPUT_SOURCE,0);
 set_clock(write_clock);
 rtc_write(&write_clock);
 
 while(true){
rtc_read(&read_clock);        //reads clock value from RTCC


   delay_ms(1000);
  printf("\r\n\r\n%02u/%02u/20%02u \r\n%02u:%02u:%02u",read_clock.tm_mon,read_clock.tm_mday,read_clock.tm_year,read_clock.tm_hour,read_clock.tm_min,read_clock.tm_sec);
    }
}



void set_clock(rtc_time_t &date_time)
{
          date_time.tm_mday=dia;
          date_time.tm_mon=mes;
          date_time.tm_year=ano;
          date_time.tm_hour=hora;
          date_time.tm_min=min;
          date_time.tm_sec=seg;       
         
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 9:15 am     Reply with quote

Now you're confusing me

Quote:
All other functions work correctly.

I tested the code posted above and still nothing worked!


You also seem to be saying that the crystals never oscillate.

Please DO NOT KEEP REFERRING to PROTEUS. It's not helpful.

So.

On a REAL board tell us EXACTLY what works and what does not.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group