HomeTOOLSEXAMPLESEXPLORE EMBEDDEDE CSERVICESECU SAMPLESRegistration
Embedded C programming Tutorial , Keil C ide , microsoftware.gr
Keil CRC and CAN BUS codes.
1. Shift led left
2.It's time for DAVE! <7/6/13>
3.Capture/Compare unit 6
4.ASC0-GPT1-MACROS
5.ASC0-FIFO-PEC
6.Analog converter
7.Memory manipulation routines
8. Recursion
9.Understanding interrupt priorities using CAPCOM2 module
10. POINTERS TO FUNCTION <4/7/13>,<4/28/13>
11.Memory models, memory types
12. The heap , part 1
13. The heap , part 2
14. The heap , part 3
15. Structure example
16. Nested structures, Array of structures.
17. Passing array of structures to function using pointers.<1/5/13>
18. Self Referential Structures
19. BITFIELDS
20. Linked list example
21. Circular linked list
22. Union example
23. Enumeration example
24. Watchdog timer example
25. Void pointer example <7/4/13>
26. The sieve of Eratosthenes
27. The stack
28. Union and bitfields as flags example. <6/23/13>
29. Look up table example. <8/11/13>
30. Seven segment display multiplexing -four digits with dot- example
31. LCD character display example - JHD162A
32. Hash table introduction example <8/27/14>
33. Array of Linked Lists example
34. Array of Linked lists-more functions included.
35. Hash table construction,searching and printing.
36. Fininte state machines- a first approach.
37. Finite state machines- two events example.
38. SPI port and an AT25128 serial eeprom hardware.
39. CRC CHECK
40. Definite Integral Calculator for Scientists, Engineers...
41 .Hamming distance of a CRC polynomial
42. Linux play starting.
43. Galois GF(2^4) Finite Field
44. Construct your own time triggered real time operating system.
45. CANBUS C CODE EXAMPLE.
9.Understanding interrupt priorities using CAPCOM2 module
This article explains interrupt priorities by examples using CAPCOM2 module.

Xc164cm ic includes a 16 channel module named CAPCOM2. Each channel works exactly with the same way as the channels of CAPCOM6 module. It includes a compare-mutch register etc (see Capcom6 example).
Capcom2 interacts with timers T7 and T8. Here we use timer T8 and channel16, channel17 and channel18.
We will make software interrupts (it is easier) and not hardware interrupts (for example using an external signal).

Terminology

Time that the interrupts are occured: It is the order that the interrupts are occured. Interrupts may be occured at different times or may be occured at the same time.
a) Interrupts are occured at different times. We set at compare-match registers of the channels: channel16=0x500, channel17=0x1000, channel18=0x1500. So, the order of occurance of interrupts is always :
1)channel16 2)channel17 3)channel18
b) Interrupts are occured at the same time. We set at compare-match registers of the 
    channels: channel16=0x500, channel17=0x500, channel18=0x500.

Priority order of Interrupts.   It is set by the programmer. It means that when an interrupt code is runing and durring this time a higher priority interrupt is appeared, then , the microcontroller stops servicing for the moment the lower priority order interrupt, gives attention to the higher priority order interrupt whose code is fully executed and ,after it, comes back to the lower order interrupt at the command that he stoped serviced it. But if the next appeared interrupt is a lower priority interrupt then, the higher priority interrupt code is fully executed and after it, the microcontroller gives attention to the lower priority interrupt code.
 

watch some examples here. Becarefull! Continue Reading the Explanation.

The C code for examples example3, example4 and example5 is here  .

You will find the interrupt code in CC2.C file.

Explanation
At the examples the interrupts seems to be visible in agreement with their priopity levels.  It is ought to time-delay routines inside the code- body of interrupts. Interrupts are serviced by the microcontroller in agreement with the order that they appeared in conjuction with the priority level that they were set,
but they are vissible to us at a different order. The explanation is here. Following the black arrows you will find the real order that interrupts are serviced and this order drives to the order that the interrupts are visible to us marked by red arrows. Interrupts are vissible to us only when the commands : P1L_0=1;    P1L_1=1;    P1L_2=1;  are executed.
To confirm the above black -arrow diagram you can set breakpoints inside the code-body of interrupts and doing precise "run and stop " using simulation only! Good luck.

The hardware.
To watch the order that the interrupts of channel16, channel17 and channel18 are visible (and not serviced) we use the three led that are connected to parallel port PIL on the board.
P1L_0 led for channel16   P1L_1 led for channel17     P1L_2 led for channel18

The initial state of these three led are ON and then they are going OFF following the order that the interrupts are visible. We included and time-delay routines in order to the state of the led  be visible.

EXAMPLE 5 for the  simulator is here. We set three breakpoints at the interrupt C code at CC2.C file. Open the parallel port P1L window and run again and again. Wait for some time and watch the order that the interrupts are vissible marked with a  'v' at the corresponding pin.
...but the breakpoints are set to wrong places. We lost some delay instructions that were executed. Set breakpoints inside the body-code.

Exercise :
Open the examples by DAVE, watch the selections of CAPCOM2 module and play changing the visible order of interrupts doing " drag and drop" .Set breakpoint inside the interrupt's code-body and watch the real order that they are serviced using simulator only !

 

Home|TOOLS|EXAMPLES|EXPLORE EMBEDDEDE C|SERVICES|ECU SAMPLES|Registration