Using interrupts on MIAC for CAN

For MIAC users to discuss projects, applications, and any other issues related to the MIAC unit.

Moderators: Benj, Mods

Post Reply
Markro
Posts: 20
Joined: Sun Sep 23, 2007 12:41 am
Contact:

Using interrupts on MIAC for CAN

Post by Markro »

Hi,

I am trying to find examples of using interupts for CAN, but cannot find any.

Obviously anything using MIAC is better based on HW configuration on the MIAC.

I noticed in the MIAC programming guide that only INT is used and is wired to RA4. I cannot however find anything using the interrupt component which allows use of RA4.

If I read the processor manual section, HW interupts seem to be tagged to port B rather than port A, Am I misunderstanding this.

The interput settings in the CAN general module settings talks about using PIN 0 for the interrupt, but not sure if this still applies to MIAC and should be left set to 0 ?

I am not sure if I would need to take car with other interrupts too as I am not 100% sure but is TMR0 using the same pin also...... ?

Is the MIAC designed to use this input, or is this only expected that this would be used by experienced users that are capable or writing their own ISRs ?

Also it looks like INT is the general purpose input and so is triggered for many reasons, so I assume it being triggered would require a check to see that the Rxbuffer had received a new message rather than take this as a new message interrupt ( I think these use 2 other specific interrupt pins, but not sure if these are used at all by MIAC ?

Any assistance / Guidance is much appreciated.

[Of course, I can just poll the Rxbuffer. It just seemed that interrupts designed into the hardware of CAN and PIC for more efficient processor usage. Then again, I am not really that experienced a programmer so I could be talking out of my hat.]

Cheers,

Mark

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Using interrupts on MIAC for CAN

Post by Sean »

Hello Mark,

There is a CAN example program in the MIAC example folder on our website (CAN connected alarm system).

The Flowcode CAN component manages the interface with the CAN controller chip and uses software polling to test for any interrupt signals when the appropriate macros are run. For this reason the INT signal is not connected to a standard interrupt input. The INT and CS pins are automatically selected when MIAC is the target device and do not need to be manually set in the component.

If you want to write your own code based on hardware interrupts (advanced programming), there is a possible configuration:
The RA4 pin of the PIC18F4455, connected to the CAN interrupt signal, can be used to generate an interrupt via Timer0. The RA4 pin is also the optional external clock input for Timer0. If Timer0 is configured for external clock input on the falling edge of RA4, and the count register is pre-loaded with the value 255, a Timer0 Overflow interrupt will be generated when RA4 is pulled low by the CAN interrupt. Timer0 would be unavailable for normal timing duties.

Markro
Posts: 20
Joined: Sun Sep 23, 2007 12:41 am
Contact:

Re: Using interrupts on MIAC for CAN

Post by Markro »

Thanks Sean,

Currently I do not really want to write my own interrupt handlers. Lets just say my abilities are not there yet....

Now, back to the CAN component approach...

Is the 'pseudo interrupt' used ? i.e. If I go into the ext properties (under Matrix CAN board specific settings) for the CAN component, I can see there is an Interrupt and I think it is set to 0. I am not quite sure what this means, or if there is an interrupt generated at all... If I insert and interrupt component, I cannot appear to reference any interrupts which look like they are specific to the CAN component.. ?

Anyway.... Does what you have written above, mean that any flowcode project involving MIAC CAN would need to be designed around periodic polling ( say off timer0 interrupt ), where a check for a received message is made each the timer0 overflows ? And so there is no possibility with CAN module (in MIAC) to have an interrupt trigger which would allow the receviced message to be services immediately.

Finally, should I only use the older CAN module for MIAC or does it not matter if CAN or CAN2 is used to contifure and interface with the CAN interface within MIAC.

Thanks,

Mark

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Using interrupts on MIAC for CAN

Post by Sean »

Hello Mark,

The CAN component does rely on regular polling to detect incomming messages. It checks one of the registers in the controller chip to see if a receive buffer is full. Most of the programs we have written around the CAN component seem to naturally loop at a rate appropriate for software polling.

The value used for the Interrupt in the CAN component identifies the port pin being used. This is mainly for e-blocks where the pin can be user allocated. The component does not use the interrupt, but ensures that the pin allocated is configured as an input.

Flowcode V3 requires the values INT = 4 and CS = 7 for MIAC. Flowcode V4 overrides these two values when MIAC is selected so these component settings can be ignored.

If the interrupt signal is connected to an interrupt capable pin, the associated interrupt could be triggered and used to read the message.

There are no CAN specific interrupts because it is an external device. All the specific interrupts refer to peripheral devices within the target microcontroller.

The CAN interrupt signal could be used to generate one of the INT interrupts (with e-blocks), or in the case of the MIAC a TMR0 interrupt (using the trick described previously).

MIAC CAN receive interrupt via TMR0:
Enable the TMR0 interrupt

Properties
Clock source = Transition on TOCKI pin
Source Edge = high-to-low transition
Prescaler = 1:1

Put the CAN_init() macro near the start of the main program.

Use a C code block with the following code during initialisation, and within the TMR0 interrupt handler macro, to force a timer overflow on the next falling edge (generating the interrupt).

tmr0l = 0xff;
tmr0h = 0xff;

Put your CAN receive code in the TMR0 interrupt handler macro (CheckRx, GetRxDataCount, GetRxData, etc.).

Keep the interrupt handler macro as small and simple as possible.


Alternatively, TMR0 could be used in its normal timer mode to generate regular interrupts and guarantee polling of the CAN chip from within the handler macro.

Post Reply