Solved

No Timer1 interrupt on 8051 using Keil C

Posted on 2004-05-02
4
640 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
  • 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 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

More and more people are using the enhanced small form-factor pluggable (SFP+) tranceivers, and speed is of utmost importance. Testing of speeds are critical to ensure that the devices will meet the speed requirements. There are some testing challen…
In the modern office, employees tend to move around the workplace a lot more freely. Conferences, collaborative groups, flexible seating and working from home require a new level of mobility. Technology has not only changed the behavior and the expe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now