Pumpkin, Inc.

Pumpkin User Forums

OSTimer();

If you're interested in purchasing Salvo but have some questions you want answered first, post them here.

OSTimer();

Postby schmitta » Mon Aug 18, 2008 3:39 am

Hi -- I don't want to make a pest of myself but I think there is wrong code in isr.c in C:salvo ut u1isr.c for the 8051.
Problem 1) The code specific to 8051 is:
****************************************
#elif defined(SYSI)

/* Reload values for Timer0 - 5msec interrupts for Oscillator at 11.0592 MHz */
/* This code courtesy Michael Stepanov. */
#define TIMER_H 238 /* TH0 reload value */
#define TIMER_L 0 /* TL0 reload value */


void timer0 (void) interrupt 1 using 2
{
/* stop, reload and start timer. */
TR0 = 0;
TH0 = TIMER_H;
TL0 = TIMER_L;
TR0 = 1;

OSTimer();
}
****************************************
and I believe they are using timer 0 in mode 2 which autoreloads the TL0 from TH0 upon interrupt. Thus for the code above the TH0, TL0 code should be in an initialize routine called by MAIN and the isr should be:
***************************************
void timer0 (void) interrupt 1 using 2
{
OSTimer();
}
***************************************

Problem 2) the delay is suppose to be for 0.005 seconds. For an 8051 running at 11.0592MHz we get 12 crystal cycles per PCLK or instruction cycle. This is then:
PCLK = 921600 Hz. The number of seconds per PCLK is = 1.0851us. To get 0.005 seconds you would need (0.005)/(1.0851*10^-6) or 4608 counts. Since this is bigger than 256 (one byte) it would take 4608/256 or 18 time periods (18 Timer0 isr cycles) to accumulate a time span of 0.005 seconds. Thus a counter would have to be incorporated into the Timer0 isr that would count down from 18 to 0 (fails on zero) and then call OSTimer(); Housekeeping would be to reset the user's counter to 18 (TL0 would be loaded with TH0 automatically by mode 2 of the counter) TH0 would have to be 0 to get a full 256 count at 1.0851 us per count (0.27778 ms accumulated time). So the isr would be:
****************************************

void isr (void) interrupt 1 using 2
{
counter -= 1;
if (counter == 0) {
counter = 18;
OSTimer();
}
}

****************************************

If I have not made a stupid error I think the above is correct. Let me know what you think. Alvin....

APSTRON
P. O. Box 10336
Blacksburg VA 24062-0336
schmitta
 
Posts: 7
Joined: Tue Jul 15, 2008 11:00 pm
Location: Blacksburg VA USA

Re: OSTimer();

Postby aek » Mon Aug 18, 2008 7:31 am

It's entirely possible that for your 8051 the sample code doesn't work. The [b]concept[/b is always the same -- call OSTimer() at a regular rate, typically 100Hz. How you do that is up to you ...

------------------

-------
aek
aek
 
Posts: 1888
Joined: Sat Aug 26, 2000 11:00 pm


Return to Pre-Sales Inquiries

Who is online

Users browsing this forum: No registered users and 0 guests

cron