Jump to content
  • 0

BASYS 3 interrupts to functions


dvg

Question

Hi,

I'm building a simple c program for the basys mx3,

I'm trying to have the screen blink every second, but with the ability to change operate in the meantime, for example blinking screen + hitting buttons for change letters on the screen.

Because i don't want the device to 'freeze' during the waiting period (blink each second) i don't want to use "sleep(1)"

 

Can i use the interrupts in the MX3 for this cause?

can i somehow tell the device to send an interrupt every second, and create an "interrupt handler" that does XYZ operations?

I've read the programming documentation, but without any example on that matter (callback functions for interrupts, etc.)

thanks a lot for the help.

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

Hi @dvg,

I do not see a reason you that you can not have an interrupt every second, and create an "interrupt handler" that does XYZ operations? Here is course work on the resource center here that covers interrupts that should help you with this task. Here is microchip interrupt reference manual for reference as well.

cheers,

Jon

Link to comment
Share on other sites

13 hours ago, jpeyron said:

 

Hi!

I have read the Documentation, but could not understand how can i "catch" and interrupt, without a busy loop on it.

Can i attach a timer to a function? sort of 'callbacks'?

I see that some timers are connected to specific elements in the X3, but i'me looking to catch the interrupt in any global function.

 

I think that i'm missing something basic about the using of the API,

any help would be much appreciated, thanks.

Link to comment
Share on other sites

On 12/7/2017 at 7:20 PM, jpeyron said:

Jon

Hi, i have a few question regarding interrupts in the basys mx3:

 
In the following file (interrupt handler example)
 
1)
the library implements the funciton 
void __ISR(_TIMER_5_VECTOR, ipl2) Timer5ISR(void) but doesn't declare it anywhere, or uses it (not that i can find)
 
what is the __ISR macro , and who calls the function?
(and what are the _TIMER_5_VECTOR, ipl2 parameters)?
 
 
2) As i understand, if i now want to create a function that uses interrupts, to change the output on the lcd, i can use this timer5, altough it's the "rgb" timer right?
 
They use the global variable TMR_TIME to set the time frames of the interrupt, can i somehow change it to every second, without changing the rgb.h file?
 
thanks!
Link to comment
Share on other sites

Hello @dvg,

The _ISR macro is handled by the XC32 compiler; you can learn a bit more about it here. My understanding of the ISR function in the rgbled.c file is that once it is initiated it will continue to update itself as the timer completes and triggers the interrupt; no further action from the user is needed.

If you want to have the LCD change something based on an interrupt, my understanding is that if you wanted to use Timer5, you will be limited to only one update rate (currently the 300 microseconds that is being used to update the RGB LED). What I would recommend would be to set a new global variable in the "void __ISR(_TIMER_5_VECTOR, ipl2) Timer5ISR(void)" function that you can then check in the main.c file to then call another function to update the LCD screen. The thing not to do here would be to update the whole LCD screen inside of the interrupt function since you would then be blocking all other processes of the PIC32.

I'm not certain why you would need to change the rgbled.h file at all, but you may be able to adjust the TMR_TIME to 1 to change the interrupt to every second, although I don't know for certain what values that register accepts, though it won't hurt to try.

Let me know if you have any more questions.

Thank you,
JColvin

 

Link to comment
Share on other sites

Hi @dvg,

You will be using a "delay" function to emulate the sleep function. If you are in an Arduino environment, the delay function will already be defined for you, otherwise if you are in MPLAB X you will need to define the function for yourself; I'm not aware of a way to directly import the linux functions otherwise.

The Basys MX3 Library pack implements some of these functions already, such as this one. As noted in the function description for the example, if you are looking for exact times, you will need to use timers instead to calculate the delay.

Let me know if you have any questions.

Thanks,
JColvin

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...