Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

No Timer1 interrupt on 8051 using Keil C

Posted on 2004-05-02
4
Medium Priority
?
676 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article applies to This article will be of use if you are the owner / supporter of any computer that comes with a discrete graphics card from nVidia / ATI Radeon (Now owned by AMD) or any embedded graphics solution and need to upgrade the gr…
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…
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…
Screencast - Getting to Know the Pipeline

885 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