Solved

No Timer1 interrupt on 8051 using Keil C

Posted on 2004-05-02
4
646 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Low profile graphics card for 3 monitors 2 65
Replacing SSD Drive 16 94
Building Secure Desktop 6 76
Video card for a Dell Optiplex 990 4 68
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 Beyond Tools A conversation I recently had with the DevOps manager of a major online retailer really made me think about DevOps monitoring tools (https://www.onpage.com/devops-incident-management-tool/). The manager and I discussed how sever…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

772 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