View previous topic :: View next topic |
Author |
Message |
Fram_fr
Joined: 29 Oct 2008 Posts: 13
|
Pic 16F1823, timer and CCS: issue? |
Posted: Mon Feb 28, 2011 11:31 am |
|
|
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
|
|
Posted: Mon Feb 28, 2011 12:00 pm |
|
|
just try something...change my values from unsigned INT8 and unsigned INT16 into signed INT8 and signed INT16 and the 2 leds blink together.... |
|
|
Fram_fr
Joined: 29 Oct 2008 Posts: 13
|
|
Posted: Mon Feb 28, 2011 12:11 pm |
|
|
Just find what's wrong with my timer....
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
|
|
Posted: Fri Sep 16, 2011 2:10 pm |
|
|
a little old topic but still.
as far as I know is RTCC used in Timer0.
Take a look in manual for CCS.
_________________ --
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. |
|
|
|