Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

No Timer1 interrupt on 8051 using Keil C

Posted on 2004-05-02
4
Medium Priority
?
664 Views
Last Modified: 2013-12-10
I am writing code for a P89C664 8051 variant to control a radio control car. I had the code working using timer0 and timer2, but needed to switch to using timer0 and 1 as i needed timer2 for the baud rate generator to increase my baud rate. The problem is now i dont seem to be getting the timer1 interrupt.

Any ideas please?

sbit STROUT = P2^0;
sbit MTROUT = P2^1;

int TempVal = 0, MilliCount = 0;
signed int SteeringVal = 0, MotorVal = 0;
double SteeringScale = 1.667, MotorScale = 1.667;
int SteeringCentre = 4800, MotorCentre = 4500;

/** Initialisation *******************************************************/
void InitDevices()
{
      /** Set motor & steering output pins ***/
      STROUT = 0;
      MTROUT = 0;

      /** Init timers for car control ********/
      //Initialise Timer1 to 16-bit timer with interupt
      TMOD |= 0x10;

      //Initialise Timer0 to 16-bit timer with interupt
      TMOD |= 0x01;
      TL0 = 0xFA;
      TH0 = 0xF2;
      TR0 = 1;

      /** Enable Interrupts ******************/
      EA = 1;      //Global enable
      ET1 = 1;      //Timer1 enable
      ET0 = 1;      //Timer0 enable
}

/** Timer0 Interrupt *****************************************************/
void Timer0Interrupt() interrupt 1
{
      //Stop timer
      TR0 = 0;      
 
      //Increment ms counter
      MilliCount += 10;

      //Do steering control pulse
      if(MilliCount == 10)
      {
            TempVal = 65536 - (SteeringCentre + (SteeringVal*SteeringScale));
            TL1 = 0x00FF & SteeringVal;
            TH1 = (0xFF00 & SteeringVal)/256;
            STROUT = 1;
      }

      //Do motor control pulse
      if(MilliCount == 20)
      {
            TempVal = 65536 - (MotorCentre + (MotorVal*MotorScale));
            TL1 = 0x00FF & MotorVal;
            TH1 = (0xFF00 & MotorVal)/256;
            MTROUT = 1;
            MilliCount = 0;
      }

       //Reload value
      TL0 = 0xFA;
      TH0 = 0xF2;

      //Start Timer1
      TR1 = 1;

      //Start Timer0
      TR0 = 1;

      //Clear interrupt
      TF0 = 0;
}

/** Timer0 Interrupt *****************************************************/
void Timer1Interrupt() interrupt 3
{
      //Stop Timer1
      TR1 = 0;

      //Clear pins
      STROUT = 0;
      MTROUT = 0;

      //Clear interrupt
      TF1 = 0;
}
0
Comment
Question by:sclarke81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10982423
Hi,
Are You sure that TH1,TL1 is > 0xF2FA? From the code above it can't be seen.
0
 

Author Comment

by:sclarke81
ID: 10982716
Hi,

I cant believe I was being so dumb! I needed to change the reload value for timer0 to give me 10ms interrupts...

Thanks alot mate, youre a star!

PS I dont suppose I could be cheeky and ask if you have any C code for interrupt driven serial comms? Currently I just have my main prog waiting for incoming data with a gets() command. Also would it screw up the serial comms if timer 0 and 1 had higher interrupt priorities? or would i need a buffer?
0
 
LVL 17

Accepted Solution

by:
mokule earned 1500 total points
ID: 10984477
Hi
The problem is I'm not using Keil C.
General rule is that it depends on serial comm speed, oscilator frequency and time consuming interrupt routine.
It would be better not to perform these
  TempVal = 65536 - (SteeringCentre + (SteeringVal*SteeringScale));
 TempVal = 65536 - (MotorCentre + (MotorVal*MotorScale));
in an interrupt routine.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

System overheating may become a serious problem if not taken care of at the proper time. I am writing this article because I faced a similar problem. Intro All electronic devices produce heat, but computers are a special case - the processors bo…
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question