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

Problem with delay_ms

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







Problem with delay_ms
PostPosted: Fri Dec 03, 2004 3:34 am     Reply with quote

hi there

i know that i'm a greenhorn, which could cause a very simple solution for my problem. but i can't find any solution


problem:
a led should be on for exactly 1000ms (delay_ms(1000)).
but the pin is high for about 1136ms when i use the rtcc (timer0 function with interrupts are necessary for the projekt).

hardware: 16F876@16MHz

code:
#include <PIC_OKW.H>
#include <LCD_DISPLAY.C>
#include <KEYBOARD.C>

#define ints_per_zehntelsekunde 782 // (16000000/(4*256*2))=7812,5 /Sekunde

long int int_zaehler=0; // Interrupt-Zähler auf NULL setzen
long int zehntelsekunden;

#int_RTCC // Funktionsaufruf bei Timer0-Overflow
RTCC_isr()
{ if(--int_zaehler==0)
{++zehntelsekunden;
int_zaehler=ints_per_zehntelsekunde;
}
}


main()
{long int start, zehntel;
/*****************************> SERIELLES GRAFIK-DISPLAY <*****************************/
LCD_INIT_ON();printf("Timer0_OKW2.c%c",0);delay_ms(2000);CLEAR();

/*****************************> TASTATUR konfigurieren <*****************************/
KEYBOARD_INIT();CLEAR_UP();

/*****************************> T I M E R 0 aktivieren <*****************************/
int_zaehler=ints_per_zehntelsekunde;
set_timer0(0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
enable_interrupts(INT_RTCC);
enable_interrupts(global);

do
{

delay_ms(4000);
output_high(pin_C5);
delay_ms(1000);
output_low(pin_C5);

}while(true);

}

p.s.excusing my bad english
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Dec 03, 2004 5:47 am     Reply with quote

The delay_ms function doesn't account for time spent in an interrupt. So during that 1000ms your interrupt took up 136ms. You could setup a timer to count some unit of measurement (I like to use ms). Then do something like

Code:

delay_count = 1000;
while(delay_count);


and in the timer isr decrement the delay_count.
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