Page 1 of 1

Interrupt Handling ?!

Posted: Mon Oct 15, 2007 9:43 am
by kk
Hi all,

I've written a small program using the PWM and the UART macro's.

Running on M8, i can't seem to get the interrupt system up and running,
//NOTE: failed to add interrupt [RXComplete] (IntHandlerCode is blank)
Is the interrupt system not operational yet? Remember that the interrupt system on a AVR is quitte different from the way PIC handles interrupts.

KK

Posted: Mon Oct 15, 2007 9:45 am
by Steve
Hello Koen,

Please email your program to me and I'll have a look.

Interrupt handling

Posted: Mon Oct 15, 2007 5:37 pm
by Huib Koppers
Hello Steve,

I read about Coen's interrupt handling in his program.
I have done some experiments wih my own program which interrupt is working (if INT0, INT1 and INT2 are right configurated) except with some delay.
This delay i'm almost sure lays about the timing or delay routines used by flowcode.
If this can be fixed then a lot of programs can work much better

Posted: Tue Oct 16, 2007 8:40 am
by Steve
Koen's program failed because he was using a "custom interrupt" and I have not implemented this for the AVR target yet. I will try to do this sometime this week. I also want to provide a facility to import existing "Flowcode for PICmicros" programs.

I have discovered a few other errors with the simulation of interrupts that also exist in Flowcode for PICmicros:

1) The "PORTB" interrupt works for the high nibble of Port B only (i.e. B4-7). AVRs and some PICmicros allow different pins (and sometimes ports) to be selected.

2) If an interrupt is triggered during the execution of another interrupt, the newly-triggered interrupt is discarded. What happens in reality is that the interrupt is serviced once the current interrupt has finished (this is what happens on the PICmicro, and it seems to be true of the AVR as well - if I'm wrong, can someone please let me know).

The first of these issues should be relatively easy to sort out and I will try to do it this week. The second one is a much bigger problem that will have to wait.

Posted: Tue Oct 16, 2007 2:19 pm
by Sean
I have carried out some interrupt timing tests using Flowcode and an ATMEGA168 running at 4MHz and 20MHz.

Using a simple program to allow the value on PORT B to be incremented by an interrupt on INT0, the following response times were measured:

4MHz xtal - 12us
20MHz xtal - 2us

The program continuously wrote a variable value to PORT B from a While loop in the main program, and incremented the variable in the interrupt service macro.

The program contained no other delay sources.

Posted: Sun Oct 21, 2007 2:24 pm
by kk
Hi all,

I was testing again with the custom interrupts;

I cant seem to get the receive interrupt working.

I geuss the custom specific interrupt name should be the "GCC name" eg.

Code: Select all

USART_RX_vect 
the specific enable code should be

Code: Select all

UCSRB |= _BV(RXCIE);  
.

Is this correct, probably not... What is the correct approach?

Regards,
Koen.[/img]

Posted: Mon Nov 12, 2007 2:09 pm
by Sean
Here are some examples of the code required for custom interrupts.

These simple examples are written for the ATMEGA8, as illustrations of the type of information required for each section of the custom interrupt component. When using alternative devices please refer to the individual device data sheets or C compiler header files for the correct bit, register and vector names.

In the handler code "FCM_%n();" results in a call to the Flowcode macro selected in the interrupt component.

The interrupt name has no affect on the program, but appears in a comment line above the interrupt code.


USART receive

The Flowcode RS232 component can be used to set the Baud rate and configure the mode of operation, and the ReceiveRS232Char function can be used in the handler macro to read the data (clearing the interrupt).

Enable code:
UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts

Disable code:
UCSRB &= ~((1 << RXCIE); // disable USART receive interrupts

Handler code:
ISR(USART_RXC_vect) // USART receive vector
{
FCM_%n(); // call selected macro
}


Analogue comparator

Enable code:
SFIOR &= ~(1 << ACME); // disable multiplexer input
ACSR |= (1 << ACIE); // enable comparator interrupts - interrupt when comparator output toggles

Disable code:
ACSR &= ~(1 << ACIE); // disable comparator interrupts

Handler code:
ISR(ANA_COMP_vect) // analogue comparator interrupt vector
{
FCM_%n(); // call selected macro
}

The state of the comparator input can be read into a Flowcode variable 'compstate' with the following C code line:

FCV_COMPSTATE = ACSR & (1 << ACO);


Timer1 input capture

Enable code:
TCCR1B = 0x45; // positive edge trigger with no noise canceler, prescaler = /1024
TIMSK |= (1 << TICIE1); // enable input capture interrupts

Disable code:
TIMSK &= ~(1 << TICIE1); // disable input capture interrupts

Handler code:
ISR(TIMER1_CAPT_vect) // input capture vector
{
FCM_%n(); // call selected macro
}

The captured 16-bit count value can be read into a Flowcode variable 'captval' with the following C code line:

FCV_CAPTVAL = ICR1

** captval must be declared as an integer variable **


Please respond with any further comments or questions regarding custom interrupts.

Posted: Thu Nov 15, 2007 5:31 pm
by ALAN_26
Hello Sean

I am trying to impellent the custom interrupt for rs232 , but I cant get it to work I don’t know much about C so I think I’m doing something wrong .

Firs I enable the interrupt by copy paste this in a C box UCSRB |= ((1 << RXCIE) | (1 << RXEN));
Than let’s say a want to call a macro named RX232 , in another C box I type

ISR(USART_RXC_vect)
{
FCM_ RX232%n(); // call selected macro
}

AM I DOING SOMETHING WRONG ?

Posted: Thu Nov 15, 2007 6:17 pm
by Sean
Hello Alan

The code you are using should be copied to a custom interrupt component.

If you copy an interrupt component into your program, and double-click on it to open the configuration window, you can select 'Custom' in the 'Interrupt on' box.

Put a meaningful name in the 'Display name' box, and make sure the 'Enable Interrupt' option is selected.

Select the appropriate macro in the 'Will call macro' box ('RX232' in this case).

When you click on the 'Properties' button, you will see 3 text boxes, with the middle one (Disable code) greyed out.

Copy
  • UCSRB |= ((1 << RXCIE) | (1 << RXEN));
into the top box (Enable code).

Copy
  • ISR(USART_RXC_vect)
    {
    FCM_%n();
    }
into the bottom box. The macro name you selected will be substituted for %n in the final C code.

We can ignore the 'Disable code' box for now.

That should be the interrupt configuration completed.

The macro called by the interrupt must read the data from the USART to clear the interrupt. Luckily the Flowcode RS232::ReceiveRS232Char() component function does this, and returns the data in a Flowcode variable.

The interrupt occurs on completion of the reception of each character.

Posted: Fri Nov 16, 2007 7:18 pm
by ALAN_26
HELLO SEAN

The rs232 custom interrupt interrupt worked 100% thanks very much for your help !


Regards ALAN CILIA .

Re: Interrupt Handling ?!

Posted: Sun Jun 08, 2008 3:29 pm
by ALAN_26
HELLO SEAN

Will the RS232 costom interrapt work on Atmega32 ?

Re: Interrupt Handling ?!

Posted: Mon Jun 09, 2008 8:56 am
by Sean
Hello Alan,

The RS232 Custom interrupt code from a previous posting will work for the ATmega32. Most of the ATmega devices containing single USARTs provide identical interfaces. There may be some differences with older devices and the dual USART chips (ATmega128, ATmega644P etc).