gojkosisa
Junior Member level 3
- Joined
- Sep 27, 2012
- Messages
- 31
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,536
Hello,
I'm working on project where I'm using 100us timer-interrupt for controlling AC motor. This application have 16x2 display and buttons for changing parameters of system. This is large project 10k+ lines of code so I write simple example to show my issue.
Please check it.
In this example I set 1us timer interrupt time because it is very simple and with 100us works fine. So, here is my issue: if I comment PORTD.F1=1; program works fine but when I uncomment this line of code program don't works at all-display freezes at beginning and don't show message "Simple test".
In my main project, situation is a little diferente. Program is working and display shows text, but timer interrupt time of 100us slow down application.
How to solve this kind of issue? I need to change state of PORTD in interrupt routine because I use phase angle control for controlling speed of AC motor.
MCU: PIC18F4620
mikroC compailer
Regards.
I'm working on project where I'm using 100us timer-interrupt for controlling AC motor. This application have 16x2 display and buttons for changing parameters of system. This is large project 10k+ lines of code so I write simple example to show my issue.
Please check it.
Code:
//LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
//Variables
unsigned char input=0;
const unsigned char UP=100;
const unsigned char DOWN=101;
unsigned char buttonUP=0;
unsigned char buttonDOWN=0;
unsigned char cnt=0;
unsigned short testVariable;
char txt[4];
///Function
unsigned char getInput();
//////////////
/////MAIN
/////////////
void main()
{
ADCON1 = 0x0F;//Digital I/O
TRISB=0xF7; //Inputs for buttons
TRISD=0x00; //Output
//////TIMER1 - 1us
T1CON = 0x01;
TMR1IF_bit = 0;
TMR1H = 0xFF;
TMR1L = 0xFE;
TMR1IE_bit = 1;
INTCON = 0xC0;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,"Simple test");
while(1)
{
input=getInput();
if(input==UP)
testVariable++;
if(input==DOWN)
testVariable--;
ByteToStr(testVariable, txt);
Lcd_Out(2,5, txt);
}
}
//////////////
/////getInput-read inputs (increment, decrement variable)
/////////////
unsigned char getInput()
{
///////TIPKA UP
if (!PORTB.F5)
{
buttonUP=1;
}
if (buttonUP && PORTB.F5) //Check button UP
{
buttonUP=0;
return UP;
}
//////TIPKA DOWN
if (!PORTB.F4) //Check button DOWN
{
buttonDOWN=1;
}
if (buttonDOWN && PORTB.F4)
{
buttonDOWN=0;
return DOWN;
}
return 1;
}
//////////////
/////Interrupt (fires every 1us)
/////////////
void Interrupt()
{
if (TMR1IF_bit)
{
TMR1IF_bit = 0;
TMR1H = 0xFF;
TMR1L = 0xFE;
//Enter your code here
cnt++;
PORTD.F1=1; // Set output - IF I COMMENT THIS PROGRAM WORKS FINE
}
}
In this example I set 1us timer interrupt time because it is very simple and with 100us works fine. So, here is my issue: if I comment PORTD.F1=1; program works fine but when I uncomment this line of code program don't works at all-display freezes at beginning and don't show message "Simple test".
In my main project, situation is a little diferente. Program is working and display shows text, but timer interrupt time of 100us slow down application.
How to solve this kind of issue? I need to change state of PORTD in interrupt routine because I use phase angle control for controlling speed of AC motor.
MCU: PIC18F4620
mikroC compailer
Regards.
Last edited: