Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[AVR] external interrupts atmega32

Status
Not open for further replies.

Abdulkerim

Junior Member level 1
Joined
Jan 31, 2022
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
GB
Activity points
91
hi dears
i have a small project that use atmega32 (MICROC FOR AVR)
i need to use 3 interrupts INT0, INT1, INT2 with TIMER1
1. INT0 to detect ZERO CROSSING
2. INT1 to detect MOTOR SPEED
3. INT2 to detect some EXTERNAL FEEDBACK
note that I have no any library or headers for INTERRUPTS
MY CODE:


Code:
void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_COMPA
{
 MS++;
}

ISR (INT0_VECT)
{
 return ZC_FLAG = 1;
/// have i reset INT0 flag here? ///
}
ISR (INT1_VECT)
{
 return TCHO_FLAG = 1;
/// have i reset INT1 flag here? ///
}
ISR (INT2_VECT)
{
 return FEEDBACK_FLAG = 1;
/// have i reset INT2 flag here? ///
}

void main (void)
{
/// TIMER1 ///
SREG.B7 = 1; // ENABLE GLOBAL INTERRUPT BIT
TCCR1A = 0x80;
TCCR1B = 0x0B;
OCR1AH = 0x30;
OCR1AL = 0xD3;
OCIE1A_bit = 1;



/// EXT_INTS ///
SREG.B7 = 0;
GICR.B6 = 1; // INT0 ENABLE
GICR.B7 = 1; // INT1 ENABLE
GICR.B5 = 1; // INT2 ENABLE
MCUCR.B0 = 0; MCUCR.B1 = 1; // INT0 FALLING EDGE
MCUCR.B2 = 0; MCUCR.B3 = 1; // INT1 FALLING EDGE
MCUCSR.B6 = 0; // INT2 FALLING EDGE
SREG.B7 = 1; // ENABLE GLOBAL INTERRUPTS

while (1)
{               


if (ZC_FLAG) {
                      // do somethings //
                      ZC_FLAG = 0;             
                     }
if (TACHO_FLAG) {
                            // do somethings //
                            TACHO_FLAG = 0;             
                            }
if (FEEDBACK_FLAG) {
                                  // do somethings //
                                 FEEDBACK_FLAG = 0;             
                                  }

}

}
/// END CODE //




thats my code
but it dosnt compiling

thank you for help
 

Here - https://www.psware.com/the-top-10-mistakes-made-by-embedded-software-engineers-in-avionics/

The case made for low latency interrupts.


Instead, minimize the use of interrupts when possible. For example, program interrupts so their only function is to signal an aperiodic process or server. Or convert handlers from periodically interrupting devices to periodic processes. If you must use interrupts, use only real-time analysis methods that account for the interrupt handling overhead. Never assume that overhead from interrupts and their handlers is negligible. Ensure mutually exclusive access to data buffers and registers in the interrupts. Do the absolute minimum amount of work possible in the handlers and exit.


Regards, Dana.
 

Hi,

my tips:

* I expect it to get compiled, but I expect it not to work.
* don´t do the triac timing in main(), do it in the ISR. But don´t use busy wait like delay_us().

The general rule "don´t use delay in an ISR" or "keep the ISR as short as possible" does not mean it just should set a flag. Otherwise you´ve nothing won.

How I´d do it:
* in the ISR: CLEAR the output (for triac gate trigger)
* use the PWM hardware to automatically SET the gate trigger output.
(this just needs a couple of microseconds in the ISR)
This is the most precise solution. It just uses the ZeroCrossISR.

Another way is to use the ZeroCrossISR and a timerISR:
* in the ZeroCrossISR: CLEAR the output (for triac gate trigger)
* set the timer timeout, then leave this ISR

* in the timerISR just SET the gate trigger output. and leave.

*****
Avoid doing precise timing in main(). Do it in the ISR. This is how it´s meant to work.

*****
I know it´s hard time to go through this the first time. We all have this behind us. (not only behind)
I know it´s a lot to read ... and it needs time to understand.
But you should know: This will go on as long as you are doing electronics/software design.
All professionals read more papers every day than you may expect. It´s unavoidable in my eys, but one get´s used to it. It´s our daily job.


Klaus
Unfortunately, I do not understand the sequence you mentioned
So please write me an example
As for the external interrupt, it must be tried
Anyway, I am waiting for the controllers, and when they arrive, I will test them and let you know the result
But I think it will work in principle because it's just like a timer1 interrupt
 

Hi,

it doesn´t work this way.
You don´t do what I recommend.
You don´t answer questions or give detailed informations.
You don´t show your own effort.
I try to explain, but no feedback.

I will help you to rectify mistakes, but I won´t do your job.
This is not how a forum is meant to work.

Again: I will support you as long as you do your job and take your part in the conversation.

Klaus
 

I am very sorry, Mr.

KlausST

I understand very well what you are saying and thank you very much for that
Of course, I don't want anyone to do my work, or I won't learn anything
The problem is that I'm trying to deal with the code at the registrar level
I've been busy reading the datasheet very carefully
Now notice in the following picture, this is timer1 interrupt in the timer calculator
TMR1 INT.png
 

Hi,

what is shown in the picutre is:

The definition of the ISR. This is nothing new. It´s already in your code since post#1.
And the same style you need to define all your other ISRs.. as already written.

The MikroE documentation as well as my example can be copy and pasted.

Feel free to tell us what you understand so far and where you need assistance.

Klaus
 
Last edited:
C:
ISR (INT0_VECT)
{
 return ZC_FLAG = 1;
/// have i reset INT0 flag here? ///
}
Where you got this syntax? I don't see it in mikroC for AVR manual.
 
Hi,

what is shown in the picutre is:

The definition of the ISR. This is nothing new. It´s already in your code since post#1.
And the same style you need to define all your other ISRs.. as already written.

The MikroE documentation as well as my example can be copy and pasted.

Feel free to tell us what you understand so far and where you need assistance.

Klaus
You are correct, Mr.

KlausST

But if you remember that when I was defining an interrupt this way

ISR (INT0_VECT)
{
// do something
}

ISR (INT1_VECT)
{
// do something
}

ISR (INT2_VECT)
{
// do something
}

It was giving me an error message so it won't build



But when I define the interrupt in this form

void EXT_INT0_ISR ()
{
// do something
}

void EXT_INT1_ISR ()
{
// do something
}

void EXT_INT2_ISR ()
{
// do something
}


The build was completed successfully and without errors
But as we said before, it must be tested in practice
--- Updated ---

C:
ISR (INT0_VECT)
{
 return ZC_FLAG = 1;
/// have i reset INT0 flag here? ///
}
Where you got this syntax? I don't see it in mikroC for AVR manual.


yes mr

FvM

you are right
What is the correct definition of external interrupt?
 

Hi,

I wonder why you insist on doing the wrong things ... and avoid doing it correct.

****

In your post#27 neither the red nor the green are showing ISR definitions. Both are wrong.

While the green ones try to define three times a function with the same name "ISR" but with different prameters.
But still just naming a function "ISR" does not mean it is an ISR.
The error message says that you must not have three function with the same name. The error message is not related to a true ISR at all.

The red one define three different functions. Thus there is no compiler error. But neither one is defined as an ISR.
Still it´s not correct definition of an ISR.

****

We have given now a lot of informations, examples how to do it right. If you can´t or don´t want to "copy and past" our effort is useless.

I wonder: are you fooling us?

Klaus
--- Updated ---

What is the correct definition of external interrupt?
I´m speechless. How often do you want us to write it? or the MikroC example?
--- Updated ---

Sorry, I´m not patient enough to go on
 
Last edited:
You clearly didn't get the point, either in understanding the numerous technical tips provided over and over again, or in understanding that some conclusions/experiments must be inferred by yourself, as long as being trivial. Since you don't seem to be interacting in a clear way, this thread will be closed for now, in the hope that you will follow the recommendations of get introduced with the fundamentals at tutorials and examples starting from the basic, found here and elsewhere; BTW, it is not the function of the forum to teach you what can be found on compiler's documentation, here you get help about specific questions, one per thread.
 
Just to demonstrate the point add these lines to your code and see the error it produces:
Code:
void MyFunction(alpha)
{
}
void MyFunction(beta)
{
}
void MyFunction(delta)
{
}
Hopefully the error message will give you a hint at why there is a problem.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top