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

TIMER1 - internal LP 32.768 OSC - SOLVED

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

TIMER1 - internal LP 32.768 OSC - SOLVED
PostPosted: Fri Jul 13, 2012 6:49 pm     Reply with quote

PIC 16F886

What on earth is it supposed to be????!

I can't figure out the right value for T1CON.

I'm trying to implement an RTC using the internal T1 LP osc 32.768
Code:

void Main()
{
   SETUP_OSCILLATOR(OSC_8MHZ);                        // Set Main PIC Osc. to 8MHZ
   //SETUP_TIMER_1(T1_EXTERNAL_SYNC|T1_DIV_BY_2);
   T1CON=0x08;
   Printf("T1CON: %X \r", T1CON);
   delay_ms(3000);
   T1CON=T1CON|0x0D;
   ENABLE_INTERRUPTS(GLOBAL);                        // Enable Interrupts
   DISABLE_INTERRUPTS(INT_RDA);
   ENABLE_INTERRUPTS(INT_TIMER1);                     // disable Serial Interrupts (SPI CONFLICT)
   //ENABLE_INTERRUPTS(INT_EXT_H2L);                     // Enable INT pin Interrupt high to low trigger

//SET_TIMER1(0);
 while (1)
{
   output_toggle(PIN_B1);
   delay_ms(100);
   Printf("T1CON: %X \r", T1CON);
}

}

Aas you can see I'm trying to do it manually... since the .h file does not give me much detail.

and the datasheet is ... not helping me much.

I've gotten it to trigger the isr:
Code:
#INT_TIMER1
void Timer1Int()
{
   output_toggle(PIN_B2);
}

but I get a period of 65 ms....

Whereas by my calculations... is wrong.

Its a 32.768 k osc... timer1 is 16bit so...
my interrupt should trigger every 2 seconds.

Its not happening.

Sorry... I'm very frustrated.

G.

edit... forgot fuses:

Code:
#fuses HS,NOWDT,NOPROTECT, NOLVP,INTRC_IO

_________________
CCS PCM 5.078 & CCS PCH 5.093


Last edited by Gabriel on Sat Jul 14, 2012 6:45 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19616

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 3:53 am     Reply with quote

Start by looking at the data sheet.

Figure 4-1. Clock source block diagram.

Where does it say the LFINTOSC routes to?. Does it mention timer1?.

Then look at the timer1 block diagram. Figure 6-1.

What clock sources does it show for the timer?.

Timer1, can be clocked from the internal Fosc/4, _or_ an external low power oscillator, or the T1CKI input. Not the internal low power oscillator (unless you switch the CPU down to running off this).

I think you are getting confused with the T1 LP oscillator. This is for an _external_ 32K crystal, connected between the T1OSO, and T1OSI pins, nothing to do with the LFINTOSC.

You enable this, with:

SETUP_TIMER_1(T1_EXTERNAL|T1_DIV_BY_2|T1_CLK_OUT);

This turns on the oscillator clock _output_, so that a crystal attached will oscillate.

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 6:44 am     Reply with quote

Hi,

thanks for your answer, I misunderstood the datasheet.

I was under the impresion that:
Quote:
6.4 Timer1 Oscillator
A low-power 32.768 kHz oscillator is built-in between
pins T1OSI (input) and T1OSO (amplifier output). The
oscillator is enabled by setting the T1OSCEN control
bit of the T1CON register. The oscillator will continue to
run during Sleep.


and this
Quote:
The Timer1 oscillator is identical to the LP oscillator.
The user must provide a software time delay to ensure
proper oscillator start-up.


meant that the Oscillator was a complete module including a clock source...
that was _like_ the _main_internal_ Osc, which doesnt require a crystal.

thus i concluded that the internal Osc on T1 did not require a crystal as well.


I was not confusing LFINTOSC with the T1 oscillator i wanted...



now my next question is why if set T1CON to 0x0D on my code,
Why was it being driven by the internal clock?

from my code:
Code:
   T1CON=0x08;    // set T1OSCEN
   Printf("T1CON: %X \r", T1CON);
   delay_ms(3000); // "Suitable Delay"
   T1CON=T1CON|0x0D; // T1 ON, TMR1CS set, T1SYNC clear




anyways... thanks for your answer... i thought i didnt need a crystal.


G
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19616

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 2:22 pm     Reply with quote

On 'why was it being driven by the internal clock', reason is that you set TMR1CS to 0. This says to run Timer1, from the internal master oscillator/4.

0xD, is 0b1101

Enable LP oscillator. Do not synchronise. Internal clock. Timer1 on.

Much easier to use binary when doing this, reduces the risk of setting the wrong bit. Smile

Best Wishes
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Sat Jul 14, 2012 3:13 pm     Reply with quote

Yeah... I settled on 0x0F in the end, which is what the compiler gave me anyways:
Code:

SETUP_TIMER_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);

Its working now and I got it down to 1Hz by doing that old MSB bit trick:
Code:
#INT_TIMER1
void Timer1Int()
{
   TMR1H |= 0x80;
   output_toggle(PIN_B2);
}

I do everything in binary ... its the probably the only thing I use the windows calculator for!

By the time I posted the code last night... I was brute forcing my way through T1CON values...I was desperate.

Thanks for your help!

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
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