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 support@ccsinfo.com

PIC18F67K22 TIMER1 using External Clock

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
P2



Joined: 25 Mar 2012
Posts: 5

View user's profile Send private message

PIC18F67K22 TIMER1 using External Clock
PostPosted: Sun Mar 25, 2012 1:52 pm     Reply with quote

PIC18F67K22 TIMER1 using External Clock 32KHz Oscillator (MAXIM DS32KHz) to drive pin RC1 Pin RC0 is not used.

Using PCWH 4.130

int32 n32Tick, n32OldTick;

#int_TIMER1
void TIMER1_isr(void)
{
n32Tick++;
}


in main()

n32Tick = n32OldTick = 0;

set_tris_c(0b10111010); // RC1 as i/p

setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);

enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);

while(1)
{
if ( n32Tick != n32OldTick)
{
printf("Tick=%ld\r\n", n32Tick);
n32OldTick = n32Tick; }
}
}

I set a break point in the ISR but it never gets called.
The 67K22 is a new chip for me are there any special "things" I need to do to make TIMER1 tick when driving it with an external clock ?
I know that TIMER1 can be set as a 16bit Timer but that is not the issue.
It simply does not interrupt at all.

I checked the lst file and it appears the ISR is clearing the T1IF

My next test I used the setup_timer_1(T1_FOSC|T1_DIV_BY_8); and it took off like a rocket, so clealry the ISR is working.

This led to to look at the data and errata sheets but I can't find anything special about TIMER1 and External Clock input.

I tried a Second Module and it's doing the same thing...
Code works with the old PIC18F6722 !

What am I missing ?
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 2:07 pm     Reply with quote

Well for starters, post a complete, compilable, set of code. Something anyone can toss into CCS and compile immediately without needing to change things. We don't have all of what is needed to deduce the problem...like fuses...which can be important. Also, please use the CODE tags to post it.
P2



Joined: 25 Mar 2012
Posts: 5

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 5:30 pm     Reply with quote

I think it's a configuration issue... !
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 6:25 pm     Reply with quote

Part of the configuration is in the code that you didn't post (FUSES). If you really want help, please provide it. I know, for example, that the PIC24FJ64GA004 has a fuse that toggles how the secondary oscillator pin functions. That's not your chip, but hopefully that helps you understand why it is important.
P2



Joined: 25 Mar 2012
Posts: 5

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 6:34 pm     Reply with quote

OK here are the fuses I'm using.

#fuses NOWDT, WDT128, HSM, PLLEN, NOPROTECT, CCP2E7, NOBROWNOUT, BORV27, PUT, NOCPD, STVREN, NODEBUG, NOWRT, NOCPB, NOEBTR, NOWRTD, NOWRTC, NOWRTB

Here are the fuses that are available, I don't see any that look like TIMER1 related but I could be wrong!

VREGSLEEP_SW,VREGSLEEP,INTRC_LP,INTRC_HP,SOSC_LOW,SOSC_DIG
SOSC_HIGH,NOXINST,XINST,LP,XT,HSH,HSM,ECH,ECH_IO,RC,RC_IO
INTRC_IO,INTRC,ECM,ECM_IO,ECL,ECL_IO,NOPLLEN,PLLEN,NOFCMEN
FCMEN,NOIESO,IESO,PUT,NOPUT,NOBROWNOUT,BROWNOUT_SW
BROWNOUT_NOSL,BROWNOUT,BORV30,BORV27,BORV20,BORV18,BORM_LOW
BORM_MED,BORM_HIGH,ZPBORM,NOWDT,WDT_NOSLEEP,WDT_SW,WDT,WDT1
WDT2,WDT4,WDT8,WDT16,WDT32,WDT64,WDT128,WDT256,WDT512
WDT1024,WDT2048,WDT4096,WDT8192,WDT16384,WDT32768,WDT65536
WDT131072,WDT262144,WDT524288,WDT1048576,RTCOSC_INT
RTCOSC_T1,CCP2E7,CCP2C1,MSSPMSK5,MSSPMSK7,NOMCLR,MCLR
NOSTVREN,STVREN,BBSIZ1K,BBSIZ2K,DEBUG,NODEBUG,PROTECT
NOPROTECT,CPB,NOCPB,CPD,NOCPD,WRT,NOWRT,WRTC,NOWRTC,WRTB
NOWRTB,WRTD,NOWRTD,EBTR,NOEBTR,EBTRB,NOEBTRB
P2



Joined: 25 Mar 2012
Posts: 5

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 6:47 pm     Reply with quote

OK I have a work-around but I'm not happy with this.

#byte T1CON = 0XFCD

T1CON = 0X8B; // turn on the Crystal Oscillator but still feed PIN C1 with the output of the MAXIM Oscillator.

It's works but I'll have to measure the current consumption !

I don't like this solution..

If anyone has any better suggestions I'd like to hear them... !

Thanks
jeremiah



Joined: 20 Jul 2010
Posts: 1329

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 7:31 pm     Reply with quote

None of:
SOSC_LOW
SOSC_DIG
SOSC_HIGH

Apply to your situation (page 405 of the datasheet)? I know they control how RC0 and RC1 are configured for external oscillators, which applies to timer1 in your case. Maybe I misunderstood your issue though?

EDIT: Why don't you like that solution? Bits T1CON<7..6> must be set to "10" and T1CON<3> should be "1" for you to have Timer1 interrupt off of an external source in asynchronous mode. After that is just a question of having your fuses (mentioned above) set correctly. What part is undesirable from those bits?


Last edited by jeremiah on Sun Mar 25, 2012 8:44 pm; edited 2 times in total
P2



Joined: 25 Mar 2012
Posts: 5

View user's profile Send private message

PostPosted: Sun Mar 25, 2012 7:46 pm     Reply with quote

Great... I think that sounds very much like what the problem has been ( + my head space issues of course ) Very Happy

I searched every reference to TIMER1 in the data sheet, and I can now see they never use the word TIMER1 in the description of CONFIG1L !


Thanks again much appreciated.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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