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

Pic 16F1823, timer and CCS: issue?

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



Joined: 29 Oct 2008
Posts: 13

View user's profile Send private message

Pic 16F1823, timer and CCS: issue?
PostPosted: Mon Feb 28, 2011 11:31 am     Reply with quote

Hi all,

i'm in progress to work on a small new design (real pcb) using a Pic 16F1823 with CCS 4.114.

Have an issue with delay_ms (does not work), so try to use timer1 to blink a pair of led.

1st issue: timer1 overflow is out of timing...
timer1 overflow every 500µs instead of 1ms, here are some parts of my code:
Code:

#fuses INTRC_IO,NOWDT,NOPUT,NOBROWNOUT,NOLVP

Code:

#define TIMER_1_PRELOAD (65536 - 2000) 

#int_timer1  // interrupt rate of 1 ms
void timer1_isr()
{
set_timer1(TIMER_1_PRELOAD);
// Decrement any timers that are running.

if(tempo_green_led>0)
   tempo_green_led--;
   
if(tempo_red_led>0)
   tempo_red_led--;
}


Code:

//****************************************************************************//
// Initialize timer1
//****************************************************************************//
    /* Setup timer 1
    * On a 16 Mhz clock, this will trigger a timer1 interrupt every 1.0 ms
    * to work properly, Timer1 must overflow every millisecond
    * OverflowTime = 4 * (1/OscFrequency) * Prescale * Period
    * Prescale = 2   
    * Period = TIMER_1_PRELOAD = 2000
    * For 16 Mhz: .001 seconds  = 4 * (1/16000000 seconds) * 2 * 2000
    */
//****************************************************************************//
   
   setup_timer_1(T1_INTERNAL | RTCC_DIV_2);
   set_timer1(TIMER_1_PRELOAD);

   setup_oscillator(OSC_16MHZ);


2nd issue: my leds are not blinking in the same time, but use the same timer1, use similare functions, the same schematic....i'm a bit lost...

Thank you for your help
Fram_fr



Joined: 29 Oct 2008
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 12:00 pm     Reply with quote

just try something...change my values from unsigned INT8 and unsigned INT16 into signed INT8 and signed INT16 and the 2 leds blink together.... Shocked
Fram_fr



Joined: 29 Oct 2008
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 12:11 pm     Reply with quote

Just find what's wrong with my timer.... Laughing
have to change
Code:
setup_timer_1(T1_INTERNAL | RTCC_DIV_2);

with
Code:

setup_timer_1(T1_INTERNAL | T1_DIV_BY_2);
tejca



Joined: 16 Sep 2011
Posts: 2
Location: SLOVENIJA

View user's profile Send private message

PostPosted: Fri Sep 16, 2011 2:10 pm     Reply with quote

a little old topic but still.
as far as I know is RTCC used in Timer0.
Take a look in manual for CCS.
Smile
_________________
--
Not Found (aka 404)

You're looking for something that does not, has not, will not, might not or
must not exist ...
... but you're always welcome to search for it.
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