Je gère plusieurs interruptions :
-Timer Z pour faire un compteur de période variable Tx
-Timer X utilisant l'interruption INT1 pour effectuer la mesure de largeur d'impulsion. Le résultat de cette mesure va déterminer la période variable Tx utilisé dans le timer Z. Je vous joins le programme :
/***********************************************************************************
FILE NAME main.c
DESCRIPTION Main program demonstrating RSKR8C1B peripherals.
This is the main tutorial code. This code will call three functions to
demonstrate Port pin control (FlashLEDs), Interrupt usage (TimerADC) and
C variable initialisation (Statics_Test).
Code to drive an optional LCD module is also included.
Please refer to the tutorial manual for more information on the program flow.
Copyright : 2006 Renesas Technology Europe Ltd.
Copyright : 2006 Renesas Technology Corporation.
All Rights Reserved
***********************************************************************************/
/***********************************************************************************
Revision History
DD.MM.YYYY OSO-UID Description
07.04.2006 RTE-VNA First Release
***********************************************************************************/
/**********************************************************************************
User Includes
***********************************************************************************/
/* Following header file provides a structure to access on-chip I/O registers. */
#include "sfr_r81b.h"
/* Following header file provides common defines for widely used items. */
#include "rskR8C1Bdef.h"
/* Following header file provides prototypes for the functions defined in this
file. */
#include "main.h"
/**********************************************************************************
Global variables
***********************************************************************************/
union{
short word;
struct{
char low;
char high;
}byte;
}usWidth;
unsigned short Counter=0;
static unsigned short usCounter = 0x00;
static unsigned short h = 0x00;
/**********************************************************************************
Function Name : main
Description : Main function
Parameters : none
Return value : none
***********************************************************************************/
void main(void)
{
/* Définition des priorités */
tzic = 3;
txic = 2;
int1ic = 1;
while(1);
}
// Interruptions du programme
#pragma INTERRUPT INT_TimerZ
void INT_TimerZ(void)
{
tm0 = 1200-h*4.7;
//tm0 = 266;
tzpr = 200-h;
switch (usCounter) { /* rotor position signal input */
case 0x00: /* case SENSER_DEG0: */
p1 = 0x0a;
p3 = 0x08;
usCounter = 0x01;
break;
case 0x01: /* case SENSER_DEG60: */
p1 = 0x06;
p3 = 0x08;
usCounter = 0x02;
break;
case 0x02: /* case SENSER_DEG120: */
p1 = 0x06;
p3 = 0x10;
usCounter = 0x03;
break;
case 0x03: /* case SENSER_DEG180: */
p1 = 0x0c;
p3 = 0x10;
usCounter = 0x04;
break;
case 0x04: /* case SENSER_DEG240: */
p1 = 0x0c;
p3 = 0x20;
usCounter = 0x05;
break;
case 0x05: /* case SENSER_DEG240: */
p1 = 0x0a;
p3 = 0x20;
usCounter = 0x00;
break;
default:
break;
}
}
#pragma INTERRUPT int1_int
void int1_int(void)
{
usWidth.byte.high = tx;
usWidth.byte.low = prex;
h=prex;
Counter = 0xffff - usWidth.word;
tx=0xff;
prex=0xff;
}
Le problème est à mon avis au niveau de l'ordre des interruptions car quelques fois le programme "bug". Qui a déjà eu ce problème et peut m'aider à le résoudre?
