Messages - viviantern [ switch to compact view ]

Pages: [1]
1
I have few questions on software timers and interrupts on a microcontroller. Just for information, I use a PIC32 microcontroller(datasheet:http://www.kynix.com/uploadfiles/pdf8798/PIC32MX110F016B-I2fML_11369.pdf).

The final goal is to implement a serial communication protocol: RS485 with Modbus. I managed to transmit and receive a message, and now I have to do a message processing part.

Since I need a bunch of timers for all sorts of different tasks (e.g., 3.5 character delay needed for serial communication, some delay needed for buttons debouncing etc.), I plan to implement timers in a software using a single hardware timer. For example, hardware timer period is set to 100 us, and an interrupt is generated on every "overflow", i.e., every 100 us. In the ISR I just update global counters, which are basically software timers with a resolution of 100 us, whereas the hardware timer ISR has the highest priority. Is this a good way to do this, or is there some better way?

Each counter (i.e., a software timer) has defined its own period, and once the counter reaches its "period value", I want to call some function. Now it is not a very good idea to call this function from inside the hardware timer ISR, because that function will be processed with the highest priority since the calling routine is the hardware timer ISR. What I want is to define some function, let's say:

void Modbus_Protocol(void);
and to be able to define it as an interrupt, which will not be of the highest priority. Only the main hardware timer has the highest priority in this concept. In that way, once the counter in the hardware timer ISR reaches its period value, it wouldn't call its function, but it would rather just set a flag to trigger an interrupt (e.g., void Modbus_Protocol(void)), which will be triggered after the main ISR returns, depending on its priority. Can something like this be done, i.e., can I define software interrupts?

I know there is a possibility to use hardware interrupts which are not used, and to just set an interrupt flag from within the software. But I don't think this is an elegant way to implement interrupts if user defined software interrupts are possible.

Pages: [1]
Go to full version