30.01.2015 Views

PWM CONTROL REGISTER - Pages de Michel Deloizy - Free

PWM CONTROL REGISTER - Pages de Michel Deloizy - Free

PWM CONTROL REGISTER - Pages de Michel Deloizy - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Microcontrôleurs<br />

http://michel.<strong>de</strong>loizy.free.fr


Microprocesseur conventionnel + périphériques<br />

Intégrés dans une puce<br />

M. <strong>Deloizy</strong> 2 dsPIC30F2023


Intègrent :<br />

Mémoire (RAM,ROM)<br />

Circuits d’horloge<br />

Ports parallèles, timers, compteurs, ports série<br />

Convertisseurs analogiques AD / DA<br />

Périphériques spécialisés :<br />

I²C<br />

Contrôle moteur<br />

Bus CAN …<br />

Constituent un système autonome à eux seuls<br />

M. <strong>Deloizy</strong> 3 dsPIC30F2023


Avantages :<br />

Système à faible coût<br />

Encombrement réduit<br />

Meilleure fiabilité<br />

Mise en œuvre facilitée<br />

Adaptés :<br />

Aux gran<strong>de</strong>s séries<br />

Aux systèmes embarqués<br />

M. <strong>Deloizy</strong> 4 dsPIC30F2023


Inconvénients :<br />

Performance <strong>de</strong>s périphériques réduite<br />

Inadaptés à la gestion <strong>de</strong> gros systèmes<br />

Utilisation simultanée <strong>de</strong> tous les périphériques impossible<br />

Complexité du système<br />

M. <strong>Deloizy</strong> 5 dsPIC30F2023


Domaines d’utilisation :<br />

Systèmes embarqués<br />

Petits systèmes économiques<br />

Systèmes <strong>de</strong> comman<strong>de</strong> à faible diffusion (prototypes…)<br />

Tout système ne nécessitant pas <strong>de</strong>s ressources importantes<br />

Applications plus importantes : PC industriel<br />

M. <strong>Deloizy</strong> 6 dsPIC30F2023


Choix d’un microcontrôleur :<br />

Deux critères essentiels :<br />

Puissance du processeur<br />

Format <strong>de</strong>s mots traités<br />

Fréquence d’horloge<br />

Architecture interne (optimisée )<br />

Jeu d’instructions et adressages, nombre <strong>de</strong> registres.<br />

Adaptation aux langages évolués.<br />

Périphériques intégrés<br />

Mémoire interne (RAM, ROM, EEPROM…)<br />

Nombre <strong>de</strong> lignes d’E/S<br />

Nombre <strong>de</strong> compteurs, précision, …<br />

Périphériques spécialisés<br />

Il est préférable <strong>de</strong> ne pas rajouter <strong>de</strong> périphériques autour du<br />

microcontrôleur !<br />

M. <strong>Deloizy</strong> 7 dsPIC30F2023


Autres critères <strong>de</strong> choix :<br />

Le coût du composant<br />

Le coût du système <strong>de</strong> développement<br />

Consommation<br />

Langages disponibles et efficacité<br />

Ressources disponibles (Internet)<br />

Connaissance du système<br />

Première mise en œuvre difficile (système complexe)<br />

M. <strong>Deloizy</strong> 8 dsPIC30F2023


MICROCHIP<br />

dsPIC30F2023<br />

dsPIC30F1010/202X<br />

28/44-Pin High-Performance<br />

Switch Mo<strong>de</strong> Power Supply<br />

Digital Signal Controllers<br />

M. <strong>Deloizy</strong> 9 dsPIC30F2023


I<br />

Présentation générale<br />

Présentation<br />

I.1 dsPIC30F SWITCH MODE POWER SUPPLY FAMILY<br />

(dsPIC30F1010/202X)<br />

Pins<br />

Packaging<br />

ProgramMemory<br />

(Bytes)<br />

Data SRAM<br />

(Bytes)<br />

Timers<br />

Capture<br />

Compare<br />

UART<br />

SPI<br />

I 2 C<br />

<strong>PWM</strong><br />

ADCs<br />

S & H<br />

A/D Inputs<br />

Analog<br />

Comparators<br />

Product<br />

dsPIC30F1010 28 SDIP 6K 256 2 0 1 1 1 1 2x2 1 3 6 ch 2 21<br />

dsPIC30F1010 28 SOIC 6K 256 2 0 1 1 1 1 2x2 1 3 6 ch 2 21<br />

dsPIC30F1010 28 QFN-S 6K 256 2 0 1 1 1 1 2x2 1 3 6 ch 2 21<br />

dsPIC30F2020 28 SDIP 12K 512 3 1 2 1 1 1 4x2 1 5 8 ch 4 21<br />

dsPIC30F2020 28 SOIC 12K 512 3 1 2 1 1 1 4x2 1 5 8 ch 4 21<br />

dsPIC30F2020 28 QFN-S 12K 512 3 1 2 1 1 1 4x2 1 5 8 ch 4 21<br />

dsPIC30F2023 44 QFN 12K 512 3 1 2 1 1 1 4x2 1 5 12 ch 4 35<br />

dsPIC30F2023 44 TQFP 12K 512 3 1 2 1 1 1 4x2 1 5 12 ch 4 35<br />

GPIO<br />

M. <strong>Deloizy</strong> 10 dsPIC30F2023


I.2 Boîtiers<br />

Présentation<br />

44-Lead Plastic Quad Flat, No Lead Package (ML) - 8x8 mm Body (QFN) :<br />

M. <strong>Deloizy</strong> 11 dsPIC30F2023


Présentationn<br />

44-Lead Plastic Thin Quad Flatpack (PT)<br />

10x10x1 mm Body, 1.0/0.10 mm<br />

Lead Form (TQFP) :<br />

M. <strong>Deloizy</strong><br />

12<br />

dsPIC30F2023


Présentation<br />

I.3 Caractéristiques générales<br />

I.3.a High-Performance Modified RISC CPU:<br />

• Modified Harvard architecture<br />

• C compiler optimized instruction set architecture<br />

• 83 base instructions with flexible addressing mo<strong>de</strong>s<br />

• 24-bit wi<strong>de</strong> instructions, 16-bit wi<strong>de</strong> data path<br />

• 12 Kbytes on-chip Flash program space<br />

• 512 bytes on-chip data RAM<br />

• 16 x 16-bit working register array<br />

• Up to 30 MIPS operation:<br />

- Dual Internal RC<br />

- 9.7 and 14.55 MHz (±1%) Industrial Temp<br />

- 6.4 and 9.7 MHz (±1%) Exten<strong>de</strong>d Temp<br />

- 32X PLL with 480 MHz VCO<br />

- PLL inputs ±3%<br />

- External EC clock 6.0 to 14.55 MHz<br />

- HS Crystal mo<strong>de</strong> 6.0 to 14.55 MHz<br />

• 32 interrupt sources<br />

• Three external interrupt sources<br />

• 8 user-selectable priority levels for each interrupt<br />

• 4 processor exceptions and software traps<br />

M. <strong>Deloizy</strong> 13 dsPIC30F2023


Présentation<br />

I.3.b DSP Engine Features:<br />

• Modulo and Bit-Reversed mo<strong>de</strong>s<br />

• Two 40-bit wi<strong>de</strong> accumulators with optional saturation logic<br />

• 17-bit x 17-bit single-cycle hardware fractional/integer multiplier<br />

• Single-cycle Multiply-Accumulate (MAC) operation<br />

• 40-stage Barrel Shifter<br />

• Dual data fetch<br />

M. <strong>Deloizy</strong> 14 dsPIC30F2023


Présentation<br />

I.3.c Peripheral Features:<br />

• High-current sink/source I/O pins: 25 mA/25 mA<br />

• Three 16-bit timers/counters; optionally pair up 16-bit timers into 32-<br />

bit timer modules<br />

• One 16-bit Capture input functions<br />

• Two 16-bit Compare/<strong>PWM</strong> output functions<br />

- Dual Compare mo<strong>de</strong> available<br />

• 3-wire SPI modules (supports 4 Frame mo<strong>de</strong>s)<br />

• I2CTM module supports<br />

o Multi-Master/Slave mo<strong>de</strong><br />

o 7-bit/10-bit addressing<br />

• UART Module:<br />

- Supports RS-232, RS-485 and LIN 1.2<br />

- Supports IrDA® with on-chip hardware en<strong>de</strong>c<br />

- Auto wake-up on Start bit<br />

- Auto-Baud Detect<br />

- 4-level FIFO buffer<br />

M. <strong>Deloizy</strong> 15 dsPIC30F2023


Présentation<br />

I.3.d Power Supply <strong>PWM</strong> Module Features:<br />

• Four <strong>PWM</strong> generators with 8 outputs<br />

• Each <strong>PWM</strong> generator has in<strong>de</strong>pen<strong>de</strong>nt time base and duty cycle<br />

• Duty cycle resolution of 1.1 ns at 30 MIPS<br />

• Individual <strong>de</strong>ad time for each <strong>PWM</strong> generator:<br />

- Dead-time resolution 4.2 ns at 30 MIPS<br />

- Dead time for rising and falling edges<br />

• Phase-shift resolution of 4.2 ns @ 30 MIPS<br />

• Frequency resolution of 8.4 ns @ 30 MIPS<br />

• <strong>PWM</strong> mo<strong>de</strong>s supported:<br />

- Complementary<br />

- Push-Pull<br />

- Multi-Phase<br />

- Variable Phase<br />

- Current Reset<br />

- Current-Limit<br />

• In<strong>de</strong>pen<strong>de</strong>nt Current-Limit and Fault Inputs<br />

• Output Overri<strong>de</strong> Control<br />

• Special Event Trigger<br />

• <strong>PWM</strong> generated ADC Trigger<br />

M. <strong>Deloizy</strong> 16 dsPIC30F2023


Présentation<br />

I.3.e Analog Features:<br />

ADC<br />

• 10-bit resolution<br />

• 2000 Ksps conversion rate<br />

• Up to 12 input channels<br />

• “Conversion pairing” allows simultaneous conversion of two inputs<br />

(i.e., current and voltage) with a single trigger<br />

• <strong>PWM</strong> control loop:<br />

- Up to six conversion pairs available<br />

- Each conversion pair has up to four <strong>PWM</strong> and seven other<br />

selectable trigger sources<br />

• Interrupt hardware supports up to 1M interrupts per second<br />

M. <strong>Deloizy</strong> 17 dsPIC30F2023


Présentation<br />

COMPARATOR<br />

• Four Analog Comparators:<br />

- 20 ns response time<br />

- 10-bit DAC reference generator<br />

- Programmable output polarity<br />

- Selectable input source<br />

- ADC sample and convert capable<br />

• <strong>PWM</strong> module interface<br />

- <strong>PWM</strong> Duty Cycle Control<br />

- <strong>PWM</strong> Period Control<br />

- <strong>PWM</strong> Fault Detect<br />

• Special Event Trigger<br />

• <strong>PWM</strong>-generated ADC Trigger<br />

M. <strong>Deloizy</strong> 18 dsPIC30F2023


Présentation<br />

I.3.f Special Microcontroller Features:<br />

• Enhanced Flash program memory:<br />

- 10,000 erase/write cycle (min.) for industrial temperature range,<br />

100k (typical)<br />

• Self-reprogrammable un<strong>de</strong>r software control<br />

• Power-on Reset (POR), Power-up Timer (PWRT) and Oscillator Startup<br />

Timer (OST)<br />

• Flexible Watchdog Timer (WDT) with on-chip low power RC oscillator<br />

for reliable operation<br />

• Fail-Safe clock monitor operation<br />

• Detects clock failure and switches to on-chip low power RC oscillator<br />

• Programmable co<strong>de</strong> protection<br />

• In-Circuit Serial Programming (ICSP)<br />

• Selectable Power Management mo<strong>de</strong>s<br />

- Sleep, Idle and Alternate Clock mo<strong>de</strong>s<br />

M. <strong>Deloizy</strong> 19 dsPIC30F2023


Présentation<br />

I.3.g CMOS Technology:<br />

• Low-power, high-speed Flash technology<br />

• 3.3V and 5.0V operation (±10%)<br />

• Industrial and Exten<strong>de</strong>d temperature ranges<br />

• Low power consumption<br />

M. <strong>Deloizy</strong> 20 dsPIC30F2023


I.4 Schéma fonctionnel<br />

Présentationn<br />

M. <strong>Deloizy</strong><br />

21<br />

dsPIC30F2023


I.5 Brochage<br />

Présentationn<br />

M. <strong>Deloizy</strong><br />

22<br />

dsPIC30F2023


CPU<br />

II Architecture du CPU<br />

II.1 Le noyau<br />

Instructions sur 24 bits (en adresses paires). 4M adressable.<br />

Pré-décodage <strong>de</strong>s instructions (pas <strong>de</strong> pipeline)<br />

Structures <strong>de</strong> boucles <strong>de</strong> programmes (instructions DO REPEAT)<br />

16 registres <strong>de</strong> 16 bits pour données, adresses ou offsets (W15 = SP)<br />

Espace adressage données : 64 k octets (32 k mots) divisé en 2 blocs<br />

Chaque bloc est géré par son AGU (Address Generation Unit)<br />

Accès aux données contenues dans la mémoire programme :<br />

- Pagination utilisant PSVPAG (les 32 ko du haut <strong>de</strong> l’espace <strong>de</strong><br />

données peuvent être mappés tous les 16kmots du bas <strong>de</strong> la mémoire<br />

<strong>de</strong> programme (user space)<br />

- Utilisation d’instructions <strong>de</strong> lecture/écriture <strong>de</strong> tables<br />

Moteur DSP intégré<br />

Gestion <strong>de</strong> buffers circulaires (adressage modulo)<br />

Adressage bit-reverse<br />

Instructions MAC (Multiply and Acumulate)<br />

62 vecteurs d’interruption (8 traps) avec 7 niveaux <strong>de</strong> priorité<br />

M. <strong>Deloizy</strong> 23 dsPIC30F2023


Registres :<br />

- W0 à W15 : 16<br />

registres <strong>de</strong><br />

travail<br />

- ACCA, ACCB : accumulateurs<br />

40 bits<br />

- SR : registre d’état<br />

- TBLPAG : registre <strong>de</strong><br />

page <strong>de</strong><br />

données<br />

- PSVPAG : registre <strong>de</strong><br />

visibilité<br />

<strong>de</strong> page <strong>de</strong> programme<br />

- DOSTART, DOEND, DCOUNT<br />

et<br />

RCOUNT : registres <strong>de</strong> gestion<br />

<strong>de</strong> DO<br />

REPEAT<br />

- PC : compteur <strong>de</strong> programme<br />

CPU<br />

W15<br />

est réservé pour la gestion <strong>de</strong><br />

la<br />

pile<br />

système (SP).<br />

W14<br />

est dédié à la pile utilisateur<br />

(avec les instructions LNK<br />

et ULNK).<br />

M. <strong>Deloizy</strong><br />

24<br />

dsPIC30F2023


II.1.a<br />

Instruction LNK<br />

CPU<br />

LNK #lit14<br />

lit14 [0 ... 16382]<br />

Opération:<br />

W14 → (W15)<br />

W15 + 2 → W15<br />

W15 → W14<br />

W15 + lit14 → W15<br />

LNK #0xA0<br />

Avant Après<br />

W14 2000 W14 2002<br />

W15 2000 W15 20A2<br />

Data 2000 0000 Data 2000 2000<br />

SR 0000 SR 0000<br />

II.1.b Instruction ULNK<br />

ULNK<br />

Opération:<br />

W14 → W15<br />

W15 – 2 → W15<br />

(W15) → W14<br />

ULNK<br />

Avant Après<br />

W14 2002 W14 2000<br />

W15 20A2 W15 2000<br />

Data 2000 2000 Data 2000 0000<br />

SR 0000 SR 0000<br />

M. <strong>Deloizy</strong> 25 dsPIC30F2023


II.2 Mémoire<br />

programme<br />

Caractéristiques :<br />

• Adressee sur 24 bits<br />

• Instructions sur 24 bits.<br />

CPU<br />

Instructions toutes les adresses paires (pour assurer<br />

compatibilité avec<br />

données quand<br />

lecturee <strong>de</strong> données).<br />

Programmes situéss dans l’ ’espace mémoire utilisateur<br />

avec PC sur<br />

23 bits<br />

(0x000000 à 0x7FFFFE).<br />

Bit<br />

•<br />

•<br />

•<br />

b23 permet accès à :<br />

Device ID<br />

User ID<br />

Bits <strong>de</strong> configuration<br />

Les instructions TBLRD et<br />

TBLWTT permettent l’accès<br />

aux<br />

données contenues en mémoire programme.<br />

Possibilité<br />

<strong>de</strong> "remapper"<br />

une page (16K mots) <strong>de</strong><br />

la<br />

mémoire programme dans<br />

la mémoire <strong>de</strong> données.<br />

M. <strong>Deloizy</strong><br />

26<br />

dsPIC30F2023


II.3 Mémoire<br />

<strong>de</strong> données<br />

II.3.a<br />

Caractéristiques :<br />

• Adressee sur 16 bits<br />

• Données sur 16<br />

bits.<br />

• Accès possible aux octets.<br />

• Les mots doivent être en<br />

adressee paire<br />

CPU<br />

Espace <strong>de</strong> données divisé en 2<br />

blocs (X et Y, pour<br />

certaines<br />

instructions DSP) et peut être vu<br />

comme un unique en usage<br />

CPU<br />

standard.<br />

Les blocs sont gérés par <strong>de</strong>s AGU<br />

(Address Generation Unit). Leurs<br />

adresses sont contigües.<br />

M. <strong>Deloizy</strong><br />

27<br />

dsPIC30F2023


CPU<br />

II.3.b Espace Near<br />

Espace dans le bloc X compris entre 0x0000 et 0x1FFF.<br />

Accessible par une adresse 13 bits.<br />

II.3.c Pile système<br />

Gérée par W15 (=SP)<br />

W15 pointe sur l’espace disponible situé au<br />

sommet <strong>de</strong> la pile.<br />

La pile croît vers les adresses hautes.<br />

Empilement : Donnée stockée en [W15] puis<br />

post-incrémentation <strong>de</strong> W15.<br />

Dépilement : Pré-décrémentation <strong>de</strong> W15, puis<br />

récupération <strong>de</strong> la donnée pointée par W15.<br />

SPLIM doit contenir la valeur maximale que<br />

peut atteindre la pile.<br />

Une exception est déclenchée si W15=SPLIM et qu’une donnée est empilée.<br />

De même, si W15 atteint une valeur inférieure à 0x800, une exception est<br />

déclenchée (afin <strong>de</strong> protéger l’espace SFR).<br />

M. <strong>Deloizy</strong> 28 dsPIC30F2023


II.3.d Registres du noyau<br />

Voir fascicule<br />

CPU<br />

M. <strong>Deloizy</strong> 29 dsPIC30F2023


II.4 Interruptions<br />

CPU<br />

35 sources d’interruption<br />

4 exceptions processeur (traps)<br />

Table <strong>de</strong> vecteurs (IVT) à partir <strong>de</strong> l’adresse 4.<br />

Table <strong>de</strong> vecteurs alternée (AIVT) utilisée si ALTIVT (INTCON2.15) = 1.<br />

M. <strong>Deloizy</strong> 30 dsPIC30F2023


CPU<br />

M. <strong>Deloizy</strong> 31 dsPIC30F2023


II.4.a Interruptions gérées par :<br />

• IFS0, IFS1, IFS2 : <strong>de</strong>man<strong>de</strong>s d’interruptions.<br />

o mis à 1 par les périphériques<br />

o remis à 0 par programme.<br />

• IEC0, IEC1, IEC2 : autorisations <strong>de</strong>s interruptions.<br />

• IPC0 à IPC11 : gestion <strong>de</strong>s priorités pour chaque périphérique.<br />

• IPL : niveau <strong>de</strong> priorité courant du CPU.<br />

o IPL dans CORCON (CORCON)<br />

o IPL dans SR (SR).<br />

• INTCON1, INTCON2 : registres <strong>de</strong> contrôle et d’état <strong>de</strong>s exceptions<br />

• INTTREG : numéro du vecteur d’interruption et niveau <strong>de</strong> priorité<br />

• DISI : interdiction temporaire <strong>de</strong>s interruptions <strong>de</strong> niveau ≤ 6<br />

o DISICNT : nombre <strong>de</strong> cycles restant<br />

CPU<br />

M. <strong>Deloizy</strong> 32 dsPIC30F2023


CPU<br />

II.4.b Table <strong>de</strong>s vecteurs d’interruption et priorités<br />

Voir fascicule<br />

Niveau <strong>de</strong> priorité :<br />

• 1 : moins prioritaire<br />

• 7 : priorité maximale<br />

• Niveau 0 : interruptions du périphérique non prises en compte<br />

• IPCx : fixent la priorité pour chaque source d’interruption.<br />

• Si <strong>de</strong>ux sources d’interruption on le même niveau <strong>de</strong> priorité, celle<br />

dont le niveau "naturel" est le plus élevé sera prise en compte en<br />

premier.<br />

• Tous les champs IP sont initialisés à 1 au RESET.<br />

M. <strong>Deloizy</strong> 33 dsPIC30F2023


CPU<br />

II.4.c<br />

Séquence d’interruption<br />

1)<br />

IFSx<br />

évalués entre <strong>de</strong>ux<br />

instructions.<br />

2)<br />

Si IFSx=1 et<br />

IECx = 1 :<br />

o requête d’interruption<br />

vali<strong>de</strong>.<br />

3)<br />

Le cycle d’interruption<br />

est lancé pour la requête <strong>de</strong><br />

niveau maximal (en prenant<br />

en compte IPCx<br />

et la priorité<br />

naturelle), si ce<br />

niveau<br />

est<br />

strictement supérieur<br />

au<br />

niveau courant<br />

du CPU<br />

(défini dans SR).<br />

4)<br />

Le CPU empile alors PC, SRL et IPL3<br />

5)<br />

Le niveau correspondant à l’interruption<br />

prise en<br />

compte est<br />

chargé dans SR : interdict<br />

tion <strong>de</strong> toute inter. <strong>de</strong> niveau inférieur<br />

ou égal.<br />

6)<br />

IPL3<br />

est mis<br />

à 0 pour les interruptions. Il est mis à 1 pour<br />

les traps.<br />

7)<br />

PC est chargé à partir du vecteur d’interruption<br />

M. <strong>Deloizy</strong><br />

34<br />

dsPIC30F2023


CPU<br />

8) …<br />

La routine <strong>de</strong> gestion <strong>de</strong> l’interruption s’exécute.<br />

Elle doit se terminer par RETFIE.<br />

Le flag <strong>de</strong> ISFx doit être remis à 0 (procédure d’acquittement) avant <strong>de</strong><br />

quitter l’interruption.<br />

9) RETFIE dépile PC, SR et IPL3, ce qui a pour effet <strong>de</strong> remettre pour<br />

le CPU le niveau d’interruption initial et <strong>de</strong> poursuivre l’exécution du<br />

programme interrompu.<br />

Notes :<br />

• Une interruption est interruptible si une requête <strong>de</strong> niveau supérieur<br />

survient.<br />

• On peut interdire la prise en compte d’une autre interruption pendant<br />

l’exécution d’une interruption en mettant NSTDIS (INTCON1) à 1,<br />

ceci indépendamment <strong>de</strong>s priorités.<br />

• Pour interdire toutes les interruptions, on peut mettre IPL à 7<br />

(dans SR). Ceci n’aura cependant pas d’inci<strong>de</strong>nce sur la prise en<br />

compte <strong>de</strong>s traps.<br />

M. <strong>Deloizy</strong> 35 dsPIC30F2023


CPU<br />

II.4.d Traps<br />

Interruptions non masquables<br />

→ Défaillance matérielle ou logicielle.<br />

Les priorités sont fixées et sont comprises entre 8 et 15 (IPL3=1).<br />

Déclenchement <strong>de</strong>s traps :<br />

• Erreur mathématique<br />

o Division par 0<br />

o Overflow d’un accumulateur (A ou B) sur b31 ou b39 (peut être<br />

paramétré et autorisé)<br />

o Nombre <strong>de</strong> décalages trop grand<br />

• Erreur d’adresse<br />

o Accès d’un mot à une adresse impaire<br />

o Accès d’une donnée à une adresse (programme ou donnée) non<br />

implémentée<br />

o Exécution d’une instruction dans la table <strong>de</strong>s vecteurs<br />

d’interruptions<br />

o Branchement (BRA ou GOTO) à une adresse non implémentée<br />

o Modification <strong>de</strong> PC correspondant à une adresse non implémentée.<br />

• Erreur <strong>de</strong> pile<br />

M. <strong>Deloizy</strong> 36 dsPIC30F2023


CPU<br />

o Si SP est chargé par ne valeur inférieure à 0x800<br />

o Si SP prend une valeur supérieure à SPLIM.<br />

• Erreur d’oscillateur<br />

o Si l’oscillateur externe <strong>de</strong>vient défaillant (passage sur oscillateur<br />

interne).<br />

M. <strong>Deloizy</strong> 37 dsPIC30F2023


CPU<br />

II.4.e Commutation <strong>de</strong> contexte rapi<strong>de</strong><br />

Une sauvegar<strong>de</strong> rapi<strong>de</strong> <strong>de</strong> contexte peut être réalisée en utilisant <strong>de</strong>s<br />

registres caches. Cette sauvegar<strong>de</strong> ne peut se faire que sur un niveau en<br />

utilisant les instructions PUSH.S et POP.S (il n’y a alors pas utilisation <strong>de</strong><br />

la pile)<br />

Les données enregistrées sont les flags DC, N, OV, Z et C <strong>de</strong> SR, et les<br />

registres W0 à W3.<br />

M. <strong>Deloizy</strong> 38 dsPIC30F2023


CPU<br />

II.4.f Reset<br />

Réinitialisation <strong>de</strong> tous les registres du CPU et <strong>de</strong>s périphériques à un état<br />

prédéfini.<br />

PC est mis à 0.<br />

Le déclenchement d’un RESET est obtenu par :<br />

• Patte RESET externe<br />

• Power-On RESET (croissance <strong>de</strong> VDD au-<strong>de</strong>là d’un certain seuil (1.85V<br />

nom.)<br />

• Instruction RESET<br />

• Un débor<strong>de</strong>ment du watchdog<br />

• Utilisation d’un registre W non initialisé<br />

• Co<strong>de</strong> instruction illégal<br />

• Plusieurs traps matériels déclenchés simultanément<br />

M. <strong>Deloizy</strong> 39 dsPIC30F2023


II.4.g Réveil du processeur<br />

Le processeur peut être sorti <strong>de</strong>s mo<strong>de</strong>s SLEEP et IDLE à partir d’une<br />

interruption, si elle est active et autorisée.<br />

En mo<strong>de</strong> Sleep le CPU, la source d’horloge et tous les périphériques<br />

dépendant <strong>de</strong> l’horloge système sont arrêtés. Il s’agit du mo<strong>de</strong> <strong>de</strong><br />

consommation minimale.<br />

En mo<strong>de</strong> Idle, le CPU est arrêté mais l’horloge continue <strong>de</strong> fonctionner<br />

pour les périphériques.<br />

Ces mo<strong>de</strong>s sont activés grâce aux instructions suivantes :<br />

• PWRSAV #SLEEP_MODE ; Put the <strong>de</strong>vice into SLEEP mo<strong>de</strong><br />

• PWRSAV #IDLE_MODE ; Put the <strong>de</strong>vice into IDLE mo<strong>de</strong><br />

CPU<br />

M. <strong>Deloizy</strong> 40 dsPIC30F2023


II.4.h<br />

CPU<br />

Registres associés aux interruptions<br />

♦ INTCON1: INTERRUPT <strong>CONTROL</strong> <strong>REGISTER</strong> 1<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

NSTDIS OVAERR OVBERR COVAERR COVBERR OVATE OVBTE COVTE<br />

b15 b8<br />

R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0<br />

SFTACERR DIV0ERR — MATHERR ADDRERR STKERR OSCFAIL —<br />

b7 b0<br />

bit 15 NSTDIS: Interrupt Nesting Disable bit<br />

1 = Interrupt nesting is disabled<br />

0 = Interrupt nesting is enabled<br />

bit 14 OVAERR: Accumulator A Overflow Trap Flag bit<br />

1 = Trap was caused by overflow of Accumulator A<br />

0 = Trap was not caused by overflow of Accumulator A<br />

bit 13 OVBERR: Accumulator B Overflow Trap Flag bit<br />

1 = Trap was caused by overflow of Accumulator B<br />

0 = Trap was not caused by overflow of Accumulator B<br />

bit 12 COVAERR: Accumulator A Catastrophic Overflow Trap Enable bit<br />

1 = Trap was caused by catastrophic overflow of Accumulator A<br />

0 = Trap was not caused by catastrophic overflow of Accumulator A<br />

bit 11 COVBERR: Accumulator B Catastrophic Overflow Trap Enable bit<br />

1 = Trap was caused by catastrophic overflow of Accumulator B<br />

0 = Trap was not caused by catastrophic overflow of Accumulator B<br />

bit 10 OVATE: Accumulator A Overflow Trap Enable bit<br />

1 = Trap overflow of Accumulator A<br />

0 = Trap disabled<br />

bit 9 OVBTE: Accumulator B Overflow Trap Enable bit<br />

1 = Trap overflow of Accumulator B<br />

0 = Trap disabled<br />

bit 8 COVTE: Catastrophic Overflow Trap Enable bit<br />

1 = Trap on catastrophic overflow of Accumulator A or B enabled<br />

0 = Trap disabled<br />

M. <strong>Deloizy</strong> 41 dsPIC30F2023


CPU<br />

bit 7 SFTACERR: Shift Accumulator Error Status bit<br />

1 = Math error trap was caused by an invalid accumulator shift<br />

0 = Math error trap was not caused by an invalid accumulator shift<br />

bit 6 DIV0ERR: Arithmetic Error Status bit<br />

1 = Math error trap was caused by a divi<strong>de</strong>d by zero<br />

0 = Math error trap was not caused by an invalid accumulator shift<br />

bit 5 Unimplemented: Read as ‘0’<br />

bit 4<br />

MATHERR: Arithmetic Error Status bit<br />

1 = Overflow trap has occurred<br />

0 = Overflow trap has not occurred<br />

bit 3 ADDRERR: Address Error Trap Status bit<br />

1 = Address error trap has occurred<br />

0 = Address error trap has not occurred<br />

bit 2 STKERR: Stack Error Trap Status bit<br />

1 = Stack error trap has occurred<br />

0 = Stack error trap has not occurred<br />

bit 1 OSCFAIL: Oscillator Failure Trap Status bit<br />

1 = Oscillator failure trap has occurred<br />

0 = Oscillator failure trap has not occurred<br />

bit 0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 42 dsPIC30F2023


CPU<br />

♦ INTCON2: INTERRUPT <strong>CONTROL</strong> <strong>REGISTER</strong> 2<br />

R/W-0 R-0 U-0 U-0 U-0 U-0 U-0 U-0<br />

ALTIVT DISI — — — — — —<br />

b15 b8<br />

U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0<br />

— — — — — INT2EP INT1EP INT0EP<br />

b7 b0<br />

bit 15 ALTIVT: Enable Alternate Interrupt Vector Table bit<br />

1 = Use alternate vector table<br />

0 = Use standard (<strong>de</strong>fault) vector table<br />

bit 14 DISI: DISI Instruction Status bit<br />

1 = DISI instruction is active<br />

0 = DISI instruction is not active<br />

bit 13-3 Unimplemented: Read as ‘0’<br />

bit 2<br />

bit 1<br />

bit 0<br />

INT2EP: External Interrupt 2 Edge Detect Polarity Select bit<br />

1 = Interrupt on negative edge<br />

0 = Interrupt on positive edge<br />

INT1EP: External Interrupt 1 Edge Detect Polarity Select bit<br />

1 = Interrupt on negative edge<br />

0 = Interrupt on positive edge<br />

INT0EP: External Interrupt 0 Edge Detect Polarity Select bit<br />

1 = Interrupt on negative edge<br />

0 = Interrupt on positive edge<br />

M. <strong>Deloizy</strong> 43 dsPIC30F2023


CPU<br />

♦ IFS0: INTERRUPT FLAG STATUS <strong>REGISTER</strong> 0<br />

U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— MI2CIF SI2CIF NVMIF ADIF U1TXIF U1RXIF SPI1IF<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

T3IF T2IF OC2IF — T1IF OC1IF IC1IF INT0IF<br />

b7 b0<br />

bit 15 Unimplemented: Read as ‘0’<br />

bit 14 MI2CIF: I2C Master Events Interrupt Flag Status bit<br />

bit 13 SI2CIF: I2C Slave Events Interrupt Flag Status bit<br />

bit 12 NVMIF: Nonvolatile Memory Interrupt Flag Status bit<br />

bit 11 ADIF: ADC Conversion Complete Interrupt Flag Status bit<br />

bit 10 U1TXIF: UART1 Transmitter Interrupt Flag Status bit<br />

bit 9 U1RXIF: UART1 Receiver Interrupt Flag Status bit<br />

bit 8 SPI1IF: SPI1 Event Interrupt Flag Status bit<br />

bit 7 T3IF: Timer3 Interrupt Flag Status bit<br />

bit 6 T2IF: Timer2 Interrupt Flag Status bit<br />

bit 5 OC2IF: Output Compare Channel 2 Interrupt Flag Status bit<br />

bit 4 Unimplemented: Read as ‘0’<br />

bit 3 T1IF: Timer1 Interrupt Flag Status bit<br />

bit 2 OC1IF: Output Compare Channel 1 Interrupt Flag Status bit<br />

bit 1 IC1IF: Input Capture Channel 1 Interrupt Flag Status bit<br />

bit 0 INT0IF: External Interrupt 0 Flag Status bit<br />

M. <strong>Deloizy</strong> 44 dsPIC30F2023


CPU<br />

♦ IFS1: INTERRUPT FLAG STATUS <strong>REGISTER</strong> 1<br />

R/W-0 R/W-0 R/W-0 U-0 R/W-0 U-0 U-0 U-0<br />

AC3IF AC2IF AC1IF — CNIF — — —<br />

b15 b8<br />

U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— <strong>PWM</strong>4IF <strong>PWM</strong>3IF <strong>PWM</strong>2IF <strong>PWM</strong>1IF PSEMIF INT2IF INT1IF<br />

b7 b0<br />

bit 15 AC3IF: Analog Comparator #3 Interrupt Flag Status bit<br />

bit 14 AC2IF: Analog Comparator #2 Interrupt Flag Status bit<br />

bit 13 AC1IF: Analog Comparator #1 Interrupt Flag Status bit<br />

bit 12 Unimplemented: Read as ‘0’<br />

bit 11 CNIF: Input Change Notification Interrupt Flag Status bit<br />

bit 10-7 Unimplemented: Read as ‘0’<br />

bit 6 <strong>PWM</strong>4IF: Pulse Width Modulation Generator #4 Interrupt Flag Status bit<br />

bit 5 <strong>PWM</strong>3IF: Pulse Width Modulation Generator #3 Interrupt Flag Status bit<br />

bit 4 <strong>PWM</strong>2IF: Pulse Width Modulation Generator #2 Interrupt Flag Status bit<br />

bit 3 <strong>PWM</strong>1IF: Pulse Width Modulation Generator #1 Interrupt Flag Status bit<br />

bit 2 PSEMIF: <strong>PWM</strong> Special Event Match Interrupt Flag Status bit<br />

bit 1 INT2IF: External Interrupt 2 Flag Status bit<br />

bit 0 INT1IF: External Interrupt 1 Flag Status bit<br />

M. <strong>Deloizy</strong> 45 dsPIC30F2023


CPU<br />

♦ IFS2: INTERRUPT FLAG STATUS <strong>REGISTER</strong> 2<br />

U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-00 R/W-0<br />

— — — — — ADCP5IF ADCP4IF ADCP3IF<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0 R/W-0<br />

ADCP2IF ADCP1IF ADCP0IF — — — — AC4IF<br />

b7 b0<br />

bit 15-11 Unimplemented: Read as ‘0’<br />

bit 10 ADCP5IF: ADC Pair 5 Conversion Done Interrupt Flag Status bit<br />

bit 9 ADCP4IF: ADC Pair 4 Conversion Done Interrupt Flag Status bit<br />

bit 8 ADCP3IF: ADC Pair 3 Conversion Done Interrupt Flag Status bit<br />

bit 7 ADCP2IF: ADC Pair 2 Conversion Done Interrupt Flag Status bit<br />

bit 6 ADCP1IF: ADC Pair 1 Conversion Done Interrupt Flag Status bit<br />

bit 5 ADCP0IF: ADC Pair 0 Conversion Done Interrupt Flag Status bit<br />

bit 4-1 Unimplemented: Read as ‘0’<br />

bit 0 AC4IF: Analog Comparator #4 Interrupt Flag Status bit<br />

M. <strong>Deloizy</strong> 46 dsPIC30F2023


CPU<br />

♦ IEC0: INTERRUPT ENABLE <strong>CONTROL</strong> <strong>REGISTER</strong> 0<br />

U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— MI2CIE SI2CIE NVMIE ADIE U1TXIE U1RXIE SPI1IE<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

T3IE T2IE OC2IE — T1IE OC1IE IC1IE INT0IE<br />

b7 b0<br />

♦ IEC1: INTERRUPT ENABLE <strong>CONTROL</strong> <strong>REGISTER</strong> 1<br />

R/W-0 R/W-0 R/W-0 U-0 R/W-0 U-0 U-0 U-0<br />

AC3IE AC2IE AC1IE — CNIE — — —<br />

b15 b8<br />

U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— <strong>PWM</strong>4IE <strong>PWM</strong>3IE <strong>PWM</strong>2IE <strong>PWM</strong>1IE PSEMIE INT2IE INT1IE<br />

b7 b0<br />

♦ IEC2: INTERRUPT ENABLE <strong>CONTROL</strong> <strong>REGISTER</strong> 2<br />

U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0<br />

— — — — — ADCP5IE ADCP4IE ADCP3IE<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0 R/W-0<br />

ADCP2IE ADCP1IE ADCP0IE — — — — AC4IE<br />

b7 b0<br />

M. <strong>Deloizy</strong> 47 dsPIC30F2023


CPU<br />

♦ IPC0: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 0<br />

bit 14-12<br />

bit 10-8<br />

bit 6-4<br />

bit 2-0<br />

T1IP: Timer1 Interrupt Priority bits<br />

OC1IP: Output Compare Channel 1 Interrupt Priority bits<br />

IC1IP: Input Capture Channel 1 Interrupt Priority bits<br />

INT0IP: External Interrupt 0 Priority bits<br />

♦ IPC1: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 1<br />

bit 14-12<br />

bit 10-8<br />

bit 6-4<br />

T3IP: Timer3 Interrupt Priority bits<br />

T2IP: Timer2 Interrupt Priority bits<br />

OC2IP: Output Compare Channel 2 Interrupt Priority bits<br />

♦ IPC2: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 2<br />

bit 14-12<br />

bit 10-8<br />

bit 6-4<br />

bit 2-0<br />

ADIP: ADC Conversion Complete Interrupt Priority bit<br />

U1TXIP: UART1 Transmitter Interrupt Priority bits<br />

U1RXIP: UART1 Receiver Interrupt Priority bits<br />

SPI1IP: SPI1 Event Interrupt Priority bits<br />

♦ IPC3: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 3<br />

bit 10-8<br />

bit 6-4<br />

bit 2-0<br />

MI2CIP: I2C Master Events Interrupt Priority bits<br />

SI2CIP: I2C Slave Events Interrupt Priority bits<br />

NVMIP: Nonvolatile Memory Interrupt Priority bits<br />

♦ IPC4: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 4<br />

bit 15 Unimplemented: Read as ‘0’<br />

bit 14-12 <strong>PWM</strong>1IP: <strong>PWM</strong> Generator #1 Interrupt Priority bits<br />

bit 11 Unimplemented: Read as ‘0’<br />

bit 10-8 PSEMIP: <strong>PWM</strong> Special Event Match Priority bits<br />

bit 7 Unimplemented: Read as ‘0’<br />

bit 6-4 INT2IP: External Interrupt 2 Priority bits<br />

bit 3 Unimplemented: Read as ‘0’<br />

bit 2-0 INT1IP: External Interrupt 1 Priority bits<br />

M. <strong>Deloizy</strong> 48 dsPIC30F2023


CPU<br />

♦ IPC5: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 5<br />

bit 10-8<br />

bit 6-4<br />

bit 2-0<br />

<strong>PWM</strong>4IP: <strong>PWM</strong> Generator #4 Interrupt Priority bits<br />

<strong>PWM</strong>3IP: <strong>PWM</strong> Generator #3 Interrupt Priority bits<br />

<strong>PWM</strong>2IP: <strong>PWM</strong> Generator #2 Interrupt Priority bits<br />

♦ IPC6: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 6<br />

bit 14-12 CNIP: Change Notification Interrupt Priority bits<br />

♦ IPC7: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 7<br />

bit 14-12<br />

bit 10-8<br />

bit 6-4<br />

AC3IP: Analog Comparator 3 Interrupt Priority bits<br />

AC2IP: Analog Comparator 2 Interrupt Priority bits<br />

AC1IP: Analog Comparator 1 Interrupt Priority bits<br />

♦ IPC8: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 8<br />

bit 2-0 AC4IP: Analog Comparator 4 Interrupt Priority bits<br />

♦ IPC9: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 9<br />

bit 14-12<br />

bit 10-8<br />

bit 6-4<br />

ADCP2IP: ADC Pair 2 Conversion Done Interrupt Priority bits<br />

ADCP1IP: ADC Pair 1 Conversion Done Interrupt Priority bits<br />

ADCP0IP: ADC Pair 0 Conversion Done Interrupt Priority bits<br />

♦ IPC10: INTERRUPT PRIORITY <strong>CONTROL</strong> <strong>REGISTER</strong> 10<br />

bit 10 - 8<br />

bit 6-4<br />

bit 2-0<br />

ADCP5IP: ADC Pair 5 Conversion Done Interrupt Priority bits<br />

ADCP4IP: ADC Pair 4 Conversion Done Interrupt Priority bits<br />

ADCP3IP: ADC Pair 3 Conversion Done Interrupt Priority bits<br />

M. <strong>Deloizy</strong> 49 dsPIC30F2023


CPU<br />

♦ INTTREG: INTERRUPT <strong>CONTROL</strong> AND STATUS <strong>REGISTER</strong><br />

U-0 U-0 U-0 U-0 R-0 R-0 R-0 R-0<br />

— — — — ILR<br />

b15 b8<br />

U-0 R-0 R-0 R-0 R-0 R-0 R-0 R-0<br />

— VECNUM<br />

b7 b0<br />

bit 15-12 Unimplemented: Read as ‘0’<br />

bit 11-8<br />

ILR: New CPU Interrupt Priority Level bits<br />

1111 = CPU Interrupt Priority Level is 15<br />

•<br />

•<br />

0001 = CPU Interrupt Priority Level is 1 0000 = CPU Interrupt Priority Level is 0<br />

bit 7 Unimplemented: Read as ‘0’<br />

bit 6-0<br />

VECNUM: Vector Number of Pending Interrupt bits<br />

0111111 = Interrupt Vector pending is number 135<br />

•<br />

•<br />

0000001 = Interrupt Vector pending is number 9<br />

0000000 = Interrupt Vector pending is number 8<br />

M. <strong>Deloizy</strong> 50 dsPIC30F2023


II.5 Horloge<br />

II.5.a Caractéristiques<br />

• Horloge interne ou externe<br />

• PLL intégrée<br />

• Mécanisme <strong>de</strong> commutation d’horloges<br />

• Post diviseur programmable (économie d’énergie)<br />

• Détection <strong>de</strong>s défaillances<br />

• Mo<strong>de</strong> programmé dans les bits <strong>de</strong> configuration (peut être modifié<br />

ensuite)<br />

CPU<br />

M. <strong>Deloizy</strong> 51 dsPIC30F2023


II.5.b<br />

Sources d’horloge<br />

♦ Oscillateu<br />

ur primaire<br />

Mo<strong>de</strong> HS : quartz 10 MHz-25 MHz.<br />

CPU<br />

♦ Horloge externe<br />

EC<br />

OSCILLATOR<br />

CONFIGURATION<br />

ECIO OSCILLATOR<br />

CONFIGURATION<br />

M. <strong>Deloizy</strong><br />

52<br />

dsPIC30F2023


♦ Oscillateur interne - INTERNAL FAST RC OSCILLATOR (FRC)<br />

• Rapi<strong>de</strong> (6.4/9.7/14.55 MHz)<br />

• Précis (< 2% erreur)<br />

• Réglable à ±3%<br />

CPU<br />

FRC sélectionné quand :<br />

• Oscillateurs EC ou HS non sélectionnés<br />

• Détection d’une défaillance d’horloge<br />

Sélection <strong>de</strong> gamme <strong>de</strong> fréquences :<br />

• Haute : 14.55 MHz (industrielle) / 9.7 MHz (étendue)<br />

• Basse : 9.7 MHz (industrielle) / 6.4 MHz (étendue)<br />

Mo<strong>de</strong> réduction du bruit CEM pour la <strong>PWM</strong> par variation (faible) <strong>de</strong> la<br />

fréquence d’horloge<br />

• Mo<strong>de</strong> séquence <strong>de</strong> fréquences<br />

• Mo<strong>de</strong> glissement pseudo aléatoire<br />

M. <strong>Deloizy</strong> 53 dsPIC30F2023


II.5.c<br />

Schéma fonctionnel<br />

CPU<br />

X32<br />

M. <strong>Deloizy</strong> 54 dsPIC30F2023


CPU<br />

M. <strong>Deloizy</strong><br />

55 dsPIC30F2023


II.5.d<br />

Registres <strong>de</strong> contrôle<br />

CPU<br />

♦ OSCCON: OSCILLATOR <strong>CONTROL</strong> <strong>REGISTER</strong><br />

U-0 R-y R-y R-y U-0 R/W-y R/W-y R/W-y<br />

HS,HC HS,HC HS,HC<br />

— COSC — NOSC<br />

b15 b8<br />

R/W-0 U-0 R-0<br />

HS,HC<br />

R/W-0 R/C-0<br />

HS,HC<br />

R/W-0 U-0 R/W-0<br />

HC<br />

CLKLOCK — LOCK PRCDEN CF TSEQEN — OSWEN<br />

b7 b0<br />

bit 15 Unimplemented: Read as ‘0’<br />

bit 14-12 COSC: Current Oscillator Group Selection bits (read-only)<br />

000 = Fast RC Oscillator (FRC)<br />

001 = Fast RC Oscillator (FRC) with PLL Module<br />

010 = Primary Oscillator (HS, EC)<br />

011 = Primary Oscillator (HS, EC) with PLL Module<br />

100 = Reserved<br />

101 = Reserved<br />

110 = Reserved<br />

111 = Reserved<br />

This bit is Reset upon: Set to FRC value (‘000’) on POR Loa<strong>de</strong>d with NOSC at the completion of a successful clock switch Set to<br />

FRC value (‘000’) when FSCM <strong>de</strong>tects a failure and switches clock to FRC<br />

bit 11 Unimplemented: Read as ‘0’<br />

bit 10-8 NOSC: New Oscillator Group Selection bits<br />

000 = Fast RC Oscillator (FRC)<br />

001 = Fast RC Oscillator (FRC) with PLL Module<br />

010 = Primary Oscillator (HS, EC)<br />

011 = Primary Oscillator (HS, EC) with PLL Module<br />

100 = Reserved<br />

M. <strong>Deloizy</strong> 56 dsPIC30F2023


it 7<br />

CPU<br />

101 = Reserved<br />

110 = Reserved<br />

111 = Reserved<br />

CLKLOCK: Clock Lock Enabled bit<br />

1 = If (FCKSM1 = 1), then clock and PLL configurations are locked. If (FCKSM1 = 0), then clock and PLL configurations may be<br />

modified<br />

0 = Clock and PLL selection are not locked, configurations may be modified<br />

Note: Once set, this bit can only be cleared via a Reset.<br />

bit 6 Unimplemented: Read as ‘0’<br />

bit 5<br />

LOCK: PLL Lock Status bit (read-only)<br />

1 = Indicates that PLL is in lock<br />

0 = Indicates that PLL is out of lock (or disabled)<br />

This bit is :<br />

- Reset on POR<br />

- Reset when a valid clock switching sequence is initiated by the clock switch state machine<br />

- Set when PLL lock is achieved after a PLL start<br />

- Reset when lock is lost<br />

- Read zero when PLL is not selected as a Group 1 system clock<br />

bit 4 PRCDEN: Pseudo Random Clock Dither Enable bit<br />

1 = Pseudo random clock dither is enabled<br />

0 = Pseudo random clock dither is disabled<br />

bit 3 CF: Clock Fail Detect bit (read/clearable by application)<br />

1 = FSCM has <strong>de</strong>tected clock failure<br />

0 = FSCM has NOT <strong>de</strong>tected clock failure<br />

This bit is :<br />

- Reset on POR<br />

- Reset when a valid clock switching sequence is initiated by the clock switch state machine<br />

- Set when clock fail <strong>de</strong>tected<br />

bit 2<br />

TSEQEN: FRC Tune Sequencer Enable bit<br />

1 = The TUN, TSEQ1, ... , TSEQ7 bits in the OSCTUN and the OSCTUN2 registers sequentially tune the FRC oscillator.<br />

Each field being sequentially selected via the ROLL signals from the <strong>PWM</strong> module.<br />

0 = The TUN bits in OSCTUN register tunes the FRC oscillator<br />

bit 1 Unimplemented: Read as ‘0’<br />

bit 0 OSWEN: Oscillator Switch Enable bit<br />

1 = Request oscillator switch to selection specified by NOSC bits<br />

0 = Oscillator switch is complete<br />

This bit is Reset upon:<br />

- Reset on POR<br />

- Reset after a successful clock switch<br />

- Reset after a redundant clock switch<br />

- Reset after FSCM switches the oscillator to (Group 3) FRC<br />

M. <strong>Deloizy</strong> 57 dsPIC30F2023


CPU<br />

♦ OSCTUN: OSCILLATOR TUNING <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

TSEQ3<br />

TSEQ2<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

TSEQ1<br />

TUN<br />

b7 b0<br />

bit 15-12 TSEQ3: Tune Sequence Value #3 bits<br />

When <strong>PWM</strong> ROLL = 011, this field is used to tune the FRC instead of TUN<br />

bit 11-8 TSEQ2: Tune Sequence Value #2 bits<br />

When <strong>PWM</strong> ROLL = 010, this field is used to tune the FRC instead of TUN<br />

bit 7-4 TSEQ1: Tune Sequence Value #1 bits<br />

When <strong>PWM</strong> ROLL = 001, this field is used to tune the FRC instead of TUN<br />

bit 3-0 TUN: Specifies the user tuning capability for the internal fast RC oscillator .<br />

If the TSEQEN bit in the OSCCON register is set, this field, along with bits TSEQ1-TSEQ7, will sequentially tune the FRC oscillator.<br />

0111 = Maximum frequency<br />

0110=<br />

0101=<br />

0100=<br />

0011=<br />

0010=<br />

0001=<br />

0000 = Center frequency, oscillator is running at calibrated frequency<br />

1111=<br />

1110=<br />

1101=<br />

1100=<br />

1011=<br />

1010=<br />

1001=<br />

1000 = Minimum frequency<br />

M. <strong>Deloizy</strong> 58 dsPIC30F2023


CPU<br />

♦ OSCTUN2: OSCILLATOR TUNING <strong>REGISTER</strong> 2<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

TSEQ7<br />

TSEQ6<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

TSEQ5<br />

TSEQ4<br />

b7 b0<br />

bit 15-12<br />

bit 11-8<br />

bit 7-4<br />

bit 3-0<br />

TSEQ7: Tune Sequence value #7 bits<br />

When <strong>PWM</strong> ROLL = 111, this field is used to tune the FRC instead of TUN<br />

TSEQ6: Tune Sequence value #6 bits<br />

When <strong>PWM</strong> ROLL = 110, this field is used to tune the FRC instead of TUN<br />

TSEQ5: Tune Sequence value #5 bits<br />

When <strong>PWM</strong> ROLL = 101, this field is used to tune the FRC instead of TUN<br />

TSEQ4: Tune Sequence value #4 bits<br />

When <strong>PWM</strong> ROLL = 100, this field is used to tune the FRC instead of TUN<br />

M. <strong>Deloizy</strong> 59 dsPIC30F2023


CPU<br />

♦ LFSR: LINEAR FEEDBACK SHIFT <strong>REGISTER</strong><br />

U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— LFSR<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

LFSR<br />

b7 b0<br />

bit 15 Unimplemented: Read as ‘0’<br />

When <strong>PWM</strong> ROLL = 111, this field is used to tune the FRC instead of TUN<br />

bit 14-8 LFSR : Most Significant 7 bits of the pseudo random FRC trim value bits<br />

bit 7-0 LFSR : Least Significant 8 bits of the pseudo random FRC trim value bits<br />

M. <strong>Deloizy</strong> 60 dsPIC30F2023


CPU<br />

II.6 Watchdog (Chien <strong>de</strong> gar<strong>de</strong>)<br />

Prévient les dysfonctionnements logiciels en réinitialisant (RESET) le<br />

CPU.<br />

Composé d’un timer et d’une horloge indépendants.<br />

Activé ou désactivé par FWDTEN dans FWDT (registre <strong>de</strong> configuration).<br />

Quand activé, le compteur s’incrémente. Quand un overflow apparaît,<br />

RESET est déclenché (sauf en mo<strong>de</strong> SLEEP).<br />

Pour éviter le RESET, l’instruction CLRWDT permet <strong>de</strong> remettre à 0 le<br />

compteur.<br />

Si FWDTEN=0, SWDTEN (RCON) permet d’activer le Watchdog par<br />

programme.<br />

M. <strong>Deloizy</strong> 61 dsPIC30F2023


II.7 Mots <strong>de</strong> configuration<br />

Les mots <strong>de</strong> configuration sont chargés lors <strong>de</strong> la programmation du<br />

composant.<br />

CPU<br />

M. <strong>Deloizy</strong> 62 dsPIC30F2023


♦ FOSCSEL (0xF80006): OSCILLATOR SELECTION CONFIGURATION BITS<br />

CPU<br />

U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0<br />

— — — — — — — —<br />

b23 b16<br />

U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0<br />

— — — — — — — —<br />

b15 b8<br />

U-0 U-0 U-0 U-0 U-0 U-0 R/P R/P<br />

— — — — — — FNOSC1 FNOSC0<br />

b7 b0<br />

bit 23-2 Unimplemented: Read as ‘0’<br />

bit 1-0 FNOSC: Initial Oscillator Group Selection on POR bits<br />

00 = Fast RC Oscillator (FRC)<br />

01 = Fast RC Oscillator (FRC) divi<strong>de</strong>d by N, with PLL module<br />

10 = Primary Oscillator (HS,EC)<br />

11 = Primary Oscillator (HS,EC) with PLL module<br />

M. <strong>Deloizy</strong> 63 dsPIC30F2023


CPU<br />

♦ FOSC (0xF80008) : OSCILLATOR SELECTION CONFIGURATION BITS<br />

U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0<br />

— — — — — — — —<br />

b23 b16<br />

U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0<br />

— — — — — — — —<br />

b15 b8<br />

R/P R/P R/P U-0 U-0 R/P R/P R/P<br />

FCKSM FRANGE — — OSCIOFNC POSCMD<br />

b7 b0<br />

bit 23-8 Unimplemented: Read as ‘0’<br />

bit<br />

bit 5<br />

7-6 FCKSM: Clock Switching and Monitor Selection Configuration bits<br />

1x = Clock switching is disabled, fail-safe clock monitor is disabled<br />

01 = Clock switching is enabled, fail-safe clock monitor is disabled<br />

00 = Clock switching is enabled, fail-safe clock monitor is enabled<br />

FRANGE: Frequency Range Select for FRC and PLL bit<br />

Acts like a “Gear Shift” feature that enables the dsPIC DSC <strong>de</strong>vice to operate at reduced MIPS at a reduced supply voltage (3.3V)<br />

bit 4-3 Unimplemented: Read as ‘0’<br />

bit 2 OSCIOFNC: OSC2 Pin I/O Enable bit<br />

1= CLKO output signal active on the OSCO pin<br />

0= CLKO output disabled<br />

bit 1-0 POSCMD: Primary Oscillator Mo<strong>de</strong><br />

11 = Primary Oscillator Disabled<br />

10 = HS oscillator mo<strong>de</strong> selected<br />

01 = Reserved<br />

00 = External clock mo<strong>de</strong> selected<br />

FRANGE<br />

Bit Value<br />

Temperature<br />

Rating<br />

FRC Frequency<br />

(Nominal)<br />

PLL VCO<br />

(Nominal)<br />

1= High Range Industrial 14.55 MHz 466 MHz (480 MHz max.)<br />

Exten<strong>de</strong>d 9.7 MHz 310 MHz (320 MHz max.)<br />

0= Low Range Industrial 9.7 MHz 310 MHz (320 MHz max.)<br />

Exten<strong>de</strong>d 6.4 MHz 205 MHz (211 MHz max.)<br />

M. <strong>Deloizy</strong> 64 dsPIC30F2023


♦ FBS (0xF80000): Boot Co<strong>de</strong> Segment Configuration Register<br />

CPU<br />

BWRP Boot Segment Program Flash Write Protection<br />

1 = Boot segment may be written<br />

0 = Boot segment is write-protected<br />

BSS Boot Segment Program Flash Co<strong>de</strong> Protection Size<br />

x11= No boot program Flash segment<br />

x00= No boot program Flash segment<br />

110= Standard security; small boot segment; boot program Flash segment starts at the end of the Interrupt Vector Segment and ends at<br />

0003FFH<br />

010 = High security; small boot segment; boot program Flash segment starts at the end of the Interrupt Vector Segment and ends at<br />

0003FFH<br />

101= Standard security; medium boot segment; boot program Flash segment starts at the end of the Interrupt Vector Segment and ends<br />

at 000FFFH<br />

001= High security; medium boot segment; boot program Flash segment starts at the end of the Interrupt Vector Segment and ends at<br />

000FFFH<br />

M. <strong>Deloizy</strong> 65 dsPIC30F2023


♦ FGS (0xF80004): General Co<strong>de</strong> Segment Configuration Register<br />

CPU<br />

GWRP General Segment Program Flash Write Protection<br />

1 = General segment may be written<br />

0 = General segment is write-protected<br />

GSS General Segment Program Flash Co<strong>de</strong> Protection<br />

11 = No Protection<br />

10 = Standard security; general program Flash segment starts at the end of the Boot Segment and ends at the end of program Flash<br />

0x = Reserved<br />

♦ FWDT (0xF8000A): Watchdog Timer Configuration Register<br />

FWDTEN Watchdog Timer Enable bit<br />

1 = Watchdog Timer always enabled. (LPRC oscillator cannot be dis-abled. Clearing the SWDTEN bit in the RCON register will have no<br />

effect.)<br />

0 = Watchdog Timer enabled/disabled by user software (LPRC can be disabled by clearing the SWDTEN bit in the RCON register)<br />

WWDTEN Watchdog Timer Window Enable bit<br />

1 = Watchdog Timer in Non-Window mo<strong>de</strong><br />

0 = Watchdog Timer in Window mo<strong>de</strong><br />

WDTPRE Watchdog Timer Prescaler bit<br />

1 = 1:128<br />

0 = 1:32<br />

WDTPOST<br />

Watchdog Timer Postscaler bits<br />

1111= 1:32, 768<br />

1110= 1:16, 384<br />

.<br />

.<br />

0001 = 1:2<br />

0000 = 1:1<br />

M. <strong>Deloizy</strong> 66 dsPIC30F2023


CPU<br />

♦ FPOR (0xF8000C): Power-On Reset Configuration Register<br />

FPWRT Power-on Reset Timer Value Select bits<br />

111= PWRT = 128 ms<br />

110= PWRT = 64 ms<br />

101= PWRT = 32 ms<br />

100= PWRT = 16 ms<br />

011= PWRT = 8 ms<br />

010= PWRT = 4 ms<br />

001= PWRT = 2 ms<br />

000= PWRT = Disabled<br />

M. <strong>Deloizy</strong> 67 dsPIC30F2023


Les ports d’E/S<br />

III Ports d’Entrées / Sorties<br />

III.1 Caractéristiques<br />

• 5 ports (A, B, D, E, F)<br />

• Toutes les pattes sont partagées entre E/S et périphériques (sauf<br />

alimentations, MCLR et OSC1/CLKI)<br />

• Toutes les entrées disposent d’un trigger <strong>de</strong> Schmitt<br />

M. <strong>Deloizy</strong> 68 dsPIC30F2023


• Étage <strong>de</strong> connexion :<br />

Les ports d’E/S<br />

M. <strong>Deloizy</strong><br />

69<br />

dsPIC30F2023


Les ports d’E/S<br />

III.2 Fonctionnement<br />

III.2.a Ports non multiplexés avec une entrée analogique<br />

♦ Programmation du mo<strong>de</strong> Entrée ou Sortie<br />

TRISA, TRISB, TRISD, TRISE ou TRISF :<br />

• Bit à 1 ⇒ patte en entrée.<br />

• Bit à 0 ⇒ patte en sortie.<br />

♦ Écriture en sortie<br />

Écriture dans PORTA, PORTB, PORTD, PORTE ou PORTF :<br />

• Bit à 1 ⇒ niveau logique patte =1.<br />

• Bit à 0 ⇒ niveau logique patte =0.<br />

LATA, LATB, LATD, LATE ou LATF :<br />

Mémorisent la valeur écrite dans PORTx.<br />

Les contenus <strong>de</strong> LATx et PORTx peuvent être différents :<br />

• Si une sortie a un niveau imposé par un circuit extérieur (Ex. : court-circuit)<br />

• Si un bit est mis en entrée<br />

• Si un bit est utilisé par un périphérique<br />

Les bits orientés en entrée ne sont pas affectés par une écriture dans PORTx.<br />

M. <strong>Deloizy</strong> 70 dsPIC30F2023


Les ports d’E/S<br />

♦ Lecture d’une entrée<br />

Lecture <strong>de</strong> PORTx : lecture du niveau logique présent sur les pattes.<br />

III.2.b Ports multiplexés avec une entrée analogique<br />

Le port B est multiplexé avec les entrées du convertisseur analogique<br />

numérique.<br />

Les E/S multiplexées avec une entrée analogique sont en mo<strong>de</strong> analogique<br />

par défaut.<br />

Les registres ADPCFG (voir p 99) et TRISx contrôlent le mo<strong>de</strong> <strong>de</strong><br />

fonctionnement <strong>de</strong> ces E/S.<br />

En mo<strong>de</strong> analogique, les ports doivent être mis en entrée (bits <strong>de</strong> TRISx =<br />

1)<br />

Les bits <strong>de</strong> ADPCFG doivent être à 1 pour utiliser le port en numérique.<br />

M. <strong>Deloizy</strong> 71 dsPIC30F2023


Les ports d’E/S<br />

III.3 Notification <strong>de</strong> changement<br />

(Input Change Notification)<br />

• CN0 à CN7 peuvent déclencher une interruption quand un changement<br />

d’état est détecté.<br />

• Fonctionne en mo<strong>de</strong> SLEEP.<br />

CN0 CN1 CN2 CN3 CN4 CN5 CN6 CN7<br />

RE6 RE7 RB0 RB1 RB2 RB3 RB4 RB5<br />

Les registres CNEN1 & CNPU1 contrôlent les CNx :<br />

• CNEN1 active (bit=1) ou désactive (bit=0) les entrées CNx<br />

• CNPU1 active (bit=1) ou désactive (bit=0) les pull-ups<br />

Si une patte CNx est mise en sortie, le tirage doit être désactivé.<br />

M. <strong>Deloizy</strong> 72 dsPIC30F2023


III.4 Registres associés<br />

SFR Name-Addr<br />

Reset State<br />

TRISA-02C0<br />

0000 1111 0000 0000<br />

PORTA-02C2<br />

0000 0000 0000 0000<br />

LATA-02C4<br />

0000 0000 0000 0000<br />

TRISB-02C6<br />

0000 1111 1111 1111<br />

PORTB-02C8<br />

0000 0000 0000 0000<br />

LATB-02CA<br />

0000 0000 0000 0000<br />

TRISD-02D2<br />

0000 0000 0000 0011<br />

PORTD-02D4<br />

0000 0000 0000 0000<br />

LATD-02D6<br />

0000 0000 0000 0000<br />

TRISE02D8<br />

0000 0000 1111 1111<br />

PORTE-02DA<br />

0000 0000 0000 0000<br />

LATE-02DC<br />

0000 0000 0000 0000<br />

TRISF-02DE<br />

1100 0001 1100 1100<br />

PORTF-02E0<br />

0000 0000 0000 0000<br />

LATF02E2<br />

0000 0000 0000 0000<br />

TRISG-02E4<br />

0000 0000 0000 1100<br />

PORTG-02E6<br />

0000 0000 0000 0000<br />

LATG-02E8<br />

0000 0000 0000 0000<br />

ADPCFG-0302<br />

0000 0000 0000 0000<br />

CNEN1-0060<br />

0000 0000 0000 0000<br />

CNPU1-0064<br />

0000 0000 0000 0000<br />

Les ports d’E/S<br />

Bits<br />

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0<br />

— — — — TRISA11 TRISA10 TRIS9 TRISA8 — — — — — — — —<br />

— — — — RA11 RA10 RA9 RA8 — — — — — — — —<br />

— — — — LATA11 LATA10 LATA9 LATA8 — — — — — — — —<br />

— — — — TRISB11 TRISB10 TRISB9 TRISB8 TRISB7 TRIS6 TRISB5 TRISB4 TRISB3 TRISB2 TRISB1 TRISB0<br />

— — — — RB11 RB10 RB9 RB8 RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0<br />

— — — — LATB11 LATB10 LATB9 LATB8 LATB7 LATB6 LATB5 LATB4 LATB3 LATB2 LATB1 LATB0<br />

— — — — — — — — — — — — — — TRISD1 TRISD0<br />

— — — — — — — — — — — — — — RD1 RD0<br />

— — — — — — — — — — — — — — LATD1 LATD0<br />

— — — — — — — — TRSE7 TRSE6 TRISE5 TRISE4 TRISE3 TRISE2 TRISE1 TRISE0<br />

— — — — — — — — RE7 RE6 RE5 RE4 RE3 RE2 RE1 RE0<br />

— — — — — — — — LATE7 LATE6 LATE5 LATE4 LATE3 LATE2 LATE1 LATE0<br />

TRISF15 TRISF14 — — — — — TRISF8 TRISF7 TRISF6 — — TRISF3 TRISF2 — —<br />

RF15 RF14 — — — — — RF8 RF7 RF6 — — RF3 RF2 — —<br />

LATF15 LATF14 — — — — — LATF8 LATF7 LATF6 — — LATF3 LATF2 — —<br />

— — — — — — — — — — — — TRISG3 TRISG2 — —<br />

— — — — — — — — — — — — RG3 RG2 — —<br />

— — — — — — — — — — — — LATG3 LATG2 — —<br />

— — — — PCFG11 PCFG10 PCFG9 PCFG8 PCFG7 PCFG6 PCFG5 PCFG4 PCFG3 PCFG2 PCFG1 PCFG0<br />

— — — — — — — — CN7IE CN6IE CN5IE CN4IE CN3IE CN2IE CN1IE CN0IE<br />

— — — — — — — — CN7PUE CN6PUE CN5PUE CN4PUE CN3PUE CN2PUE CN1PUE CN0PUE<br />

M. <strong>Deloizy</strong> 73 dsPIC30F2023


♦ Application 1 :<br />

Les ports d’E/S<br />

Simulateur logique<br />

A B NAND NOR XOR<br />

0 0 1 1 0<br />

0 1 1 0 1<br />

1 0 1 0 1<br />

1 1 0 0 0<br />

J K Qn+1<br />

0 0 Qn<br />

0 1 0<br />

1 0 1<br />

1 1 /Qn<br />

M. <strong>Deloizy</strong> 74 dsPIC30F2023


♦ Applicatio<br />

on 2<br />

Dans le schéma ci-contre, MODE représente un sélecteur<br />

Cavalier sur :<br />

1-2 : mo<strong>de</strong> 1<br />

2-3 : mo<strong>de</strong> 2<br />

cavalier<br />

retiré : mo<strong>de</strong> 3<br />

Les ports d’E/S<br />

à cavalier :<br />

Écrire la fonction mo<strong>de</strong> :<br />

int<br />

mo<strong>de</strong>(void) ;<br />

M. <strong>Deloizy</strong><br />

75<br />

dsPIC30F2023


♦ Application 3 :<br />

Les ports d’E/S<br />

Serrure codée<br />

Co<strong>de</strong> <strong>de</strong> 3 à 6 chiffres<br />

‘C’ : Recommencer<br />

‘V’ : Vali<strong>de</strong>r<br />

LED indique :<br />

Co<strong>de</strong> Ok (allumage 1s)<br />

Début saisie (2 clign.)<br />

Activation gâche : 1 sec<br />

On dispose <strong>de</strong> :<br />

void <strong>de</strong>lay(unsigned ms)<br />

M. <strong>Deloizy</strong> 76 dsPIC30F2023


Timers<br />

IV Timers<br />

3 timers 16 bits :<br />

• TIMER1 : Timer <strong>de</strong> type A<br />

• TIMER2 et TIMER3 constituent un Timer 32 bits, mais peuvent<br />

fonctionner séparément<br />

• TIMER2 : Timer <strong>de</strong> type B<br />

• TIMER3 : Timer <strong>de</strong> type C<br />

M. <strong>Deloizy</strong> 77 dsPIC30F2023


TIMER1<br />

Timers<br />

IV.1.a Caractéristiques :<br />

• Peut fonctionner en :<br />

o Timer<br />

o Compteur synchrone<br />

o Compteur asynchrone.<br />

• Peut être validé par une entrée (Gate)<br />

• Prédiviseur programmable<br />

• Peut fonctionner en mo<strong>de</strong> SLEEP ou IDLE<br />

• Effectue <strong>de</strong>s cycles 0…(PR1), 0…(PR1), … où PR1 est le registre <strong>de</strong><br />

pério<strong>de</strong> (Period Register 1)<br />

• Déclenche une interruption quand :<br />

o TMR1 est remis à 0 (suite au passage par PR1).<br />

o Front <strong>de</strong>scendant <strong>de</strong> Gate (en mo<strong>de</strong> Gate)<br />

M. <strong>Deloizy</strong> 78 dsPIC30F2023


IV.1. .b Schéma fonctionnel<br />

Timers<br />

M. <strong>Deloizy</strong><br />

79 dsPIC30F2023


IV.1.c<br />

Mo<strong>de</strong>s<br />

Timers<br />

♦ Mo<strong>de</strong> Timer<br />

Le timer s’incrémente au rythme <strong>de</strong> F CY (à chaque instruction).<br />

Quand le timer atteint la valeur contenue dans PR1, le timer est remis à 0<br />

et le cycle se poursuit.<br />

En mo<strong>de</strong> SLEEP, le timer s’arrête (plus d’horloge système).<br />

En mo<strong>de</strong> Idle, le timer continue <strong>de</strong> fonctionner si TSIDL (T1CON) = 0.<br />

Il s’arrête si TSIDL=1.<br />

♦ Mo<strong>de</strong> compteur synchrone<br />

Le compteur s’incrémente à chaque front montant du signal appliqué sur<br />

T1CK. Ce signal est synchronisé sur l’horloge système.<br />

Quand le compteur atteint la valeur contenue dans PR1, le compteur est<br />

remis à 0 et le cycle se poursuit.<br />

En mo<strong>de</strong> SLEEP, le compteur s’arrête (plus d’horloge système).<br />

En mo<strong>de</strong> Idle, le compteur continue <strong>de</strong> fonctionner si TSIDL (T1CON)<br />

= 0. Il s’arrête si TSIDL=1.<br />

♦ Mo<strong>de</strong> compteur asynchrone<br />

Le compteur s’incrémente à chaque front montant du signal appliqué sur<br />

T1CK.<br />

M. <strong>Deloizy</strong> 80 dsPIC30F2023


Timers<br />

Quand le compteur atteint la valeur contenue dans PR1, le compteur est<br />

remis à 0 et le cycle se poursuit.<br />

En mo<strong>de</strong> SLEEP, le compteur continue <strong>de</strong> fonctionner, car il fonctionne<br />

indépendamment <strong>de</strong> l’horloge système.<br />

En mo<strong>de</strong> Idle, le compteur continue <strong>de</strong> fonctionner si TSIDL<br />

(T1CON) = 0. Il s’arrête si TSIDL=1.<br />

♦ Mo<strong>de</strong> Gate<br />

Dans ce mo<strong>de</strong>, l’entrée T1CK fonctionne en Gate et permet d’autoriser<br />

(T1CK=1) le comptage ou <strong>de</strong> l’arrêter (T1CK=0).<br />

IV.1.d<br />

Registres<br />

♦ TMR1 : Timer 1 Register<br />

Reset State : uuuu uuuu uuuu uuuu<br />

♦ PR1 : Period Register 1<br />

Reset State : 1111 1111 1111 1111<br />

M. <strong>Deloizy</strong> 81 dsPIC30F2023


♦ T1CON : Type A Time Base Register<br />

Timers<br />

R/W-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

TON — TSIDL — — — — —<br />

b15 b8<br />

U-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 U-0<br />

— TGATE TCKPS — TSYNC TCS —<br />

b7 b0<br />

bit 15 TON: Timer On Control bit<br />

1= Starts the timer<br />

0= Stops the timer<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13<br />

TSIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1= Discontinue timer operation when <strong>de</strong>vice enters Idle mo<strong>de</strong><br />

0= Continue timer operation in Idle mo<strong>de</strong><br />

bit 12-7 Unimplemented: Read as ‘0’<br />

bit 6 TGATE: Timer Gated Time Accumulation Enable bit<br />

1= Gated time accumulation enabled<br />

0= Gated time accumulation disabled<br />

(TCS must be set to ‘0’ when TGATE = 1. Reads as ‘0’ if TCS = 1)<br />

bit 5-4<br />

TCKPS: Timer Input Clock Prescale Select bits<br />

11 = 1:256 prescale value<br />

10 = 1:64 prescale value<br />

01 = 1:8 prescale value<br />

00 = 1:1 prescale value<br />

bit 3 Unimplemented: Read as ‘0’<br />

bit 2<br />

TSYNC: Timer External Clock Input Synchronization Select bit<br />

When TCS = 1:<br />

1= Synchronize external clock input<br />

0= Do not synchronize external clock input<br />

When TCS = 0:<br />

This bit is ignored. Read as ‘0’. Timer1 uses the internal clock when TCS = 0.<br />

bit 1 TCS: Timer Clock Source Select bit<br />

1= External clock from pin T1CK<br />

0= Internal clock (FOSC/4)<br />

bit 0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 82 dsPIC30F2023


Timers<br />

IV.2 TIMER2 et TIMER3<br />

IV.2.a Caractéristiques du Timer 32 bits<br />

• TMR2 : LSW, TMR3 : MSW<br />

• Mo<strong>de</strong> Timer<br />

• Mo<strong>de</strong> compteur synchrone<br />

• Déclenchement événement convertisseur analogique numérique<br />

• Mo<strong>de</strong> Gate<br />

• Prédiviseur programmable<br />

• Fonctionnement possible pendant le mo<strong>de</strong> IDLE<br />

• Déclenche une interruption quand :<br />

o [TMR3 :TMR2] est remis à 0 (suite au passage par [PR3 :PR2]).<br />

o Front <strong>de</strong>scendant <strong>de</strong> Gate (en mo<strong>de</strong> Gate)<br />

• T3CON ignoré. Seuls T2CON et T2CK (entrée gate) sont utilisés.<br />

L’interruption est contrôlée par TIMER3 (T3IE, T3IF).<br />

M. <strong>Deloizy</strong> 83 dsPIC30F2023


Timers<br />

IV.2. .b Schéma fonctionnel du Timer 32 bits<br />

M. <strong>Deloizy</strong><br />

84<br />

dsPIC30F2023


Timers<br />

♦ Mo<strong>de</strong> Timer<br />

Le timer 32 bits s’incrémente au rythme <strong>de</strong> F CY (à chaque instruction).<br />

Quand le timer atteint la valeur contenue dans [PR3 :PR2], le timer est<br />

remis à 0 et le cycle se poursuit.<br />

Pour lire la valeur courante du timer, il faut lire d’abord TMR2 : Ceci a<br />

pour effet <strong>de</strong> transférer simultanément la valeur <strong>de</strong> TMR3 dans le registre<br />

TMR3HLD qui peut être lu ensuite.<br />

Pour écrire dans le timer 32 bits, on écrit d’abord dans TMR3HLD, puis<br />

dans TMR2. Cette <strong>de</strong>rnière écriture transfert simultanément TMR3HLD<br />

dans TMR3.<br />

En mo<strong>de</strong> SLEEP, le timer s’arrête (plus d’horloge système).<br />

En mo<strong>de</strong> Idle, le timer continue <strong>de</strong> fonctionner si TSIDL (T2CON) = 0.<br />

Il s’arrête si TSIDL=1.<br />

♦ Mo<strong>de</strong> compteur (synchrone)<br />

Le compteur 32 bits s’incrémente à chaque front montant du signal<br />

appliqué sur T2CK. Ce signal est synchronisé sur l’horloge système.<br />

Quand le compteur atteint la valeur contenue dans [PR3 :PR2], le<br />

compteur est remis à 0 et le cycle se poursuit.<br />

En mo<strong>de</strong> SLEEP, le compteur s’arrête (plus d’horloge système).<br />

En mo<strong>de</strong> Idle, le compteur continue <strong>de</strong> fonctionner si TSIDL (T2CON)<br />

= 0. Il s’arrête si TSIDL=1.<br />

M. <strong>Deloizy</strong> 85 dsPIC30F2023


Timers<br />

♦ Mo<strong>de</strong> Gate<br />

Dans ce mo<strong>de</strong>, l’entrée T2CK fonctionne en Gate et permet d’autoriser<br />

(T2CK=1) le comptage ou <strong>de</strong> l’arrêter (T2CK=0).<br />

♦ Déclenchement événement convertisseur analogique<br />

Quand [TMR3 :TMR2]=[PR3 :PR2], un événement convertisseur<br />

analogique est déclenché par le timer 3.<br />

IV.2.c TIMER 2 et TIMER 3 en mo<strong>de</strong>s 16 bits<br />

Les Timers 2 et 3 fonctionnent comme le timer 1, sans le mo<strong>de</strong> compteur<br />

asynchrone.<br />

Ils ne peuvent pas fonctionner en mo<strong>de</strong> SLEEP.<br />

Le timer 2 dispose d’une synchronisation d’horloge en sortie du<br />

prédiviseur.<br />

Le timer 3 ne possè<strong>de</strong> pas d’entrée externe (mo<strong>de</strong>s compteur et gate<br />

impossibles).<br />

M. <strong>Deloizy</strong> 86 dsPIC30F2023


♦ Schéma fonctionnel du timer 2<br />

Timers<br />

M. <strong>Deloizy</strong><br />

87 dsPIC30F2023


♦ Schéma fonctionnel du timer 3<br />

Timers<br />

M. <strong>Deloizy</strong><br />

88 dsPIC30F2023


♦ TMR2 : Timer 2 Register<br />

Reset State : uuuu uuuu uuuu uuuu<br />

♦ PR2 : Period Register 2<br />

Reset State : 1111 1111 1111 1111<br />

♦ TMR3 : Timer 3 Register<br />

Reset State : uuuu uuuu uuuu uuuu<br />

♦ TMR3HLD : Timer3 Holding Register<br />

(For 32-bit timer operations only)<br />

Reset State : uuuu uuuu uuuu uuuu<br />

♦ PR3 : Period Register 3<br />

Reset State : 1111 1111 1111 1111<br />

Timers<br />

M. <strong>Deloizy</strong> 89 dsPIC30F2023


Timers<br />

♦ T2CON : Type B Time Base Register<br />

R/W-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

TON — TSIDL — — — — —<br />

b15 b8<br />

U-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0 U-0<br />

— TGATE TCKPS T32 — TCS —<br />

b7 b0<br />

bit 15 TON: Timer On bit<br />

When T32 = 1 (in 32-bit Timer mo<strong>de</strong>):<br />

1= Starts 32-bit TMR3:TMR2 timer pair<br />

0= Stops 32-bit TMR3:TMR2 timer pair<br />

When T32 = 0 (in 16-bit Timer mo<strong>de</strong>):<br />

1= Starts 16-bit timer<br />

0= Stops 16-bit timer<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13<br />

TSIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1= Discontinue timer operation when <strong>de</strong>vice enters Idle mo<strong>de</strong><br />

0= Continue timer operation in Idle mo<strong>de</strong><br />

bit 12-7 Unimplemented: Read as ‘0’<br />

bit 6 TGATE: Timer Gated Time Accumulation Enable bit<br />

1= Timer gated time accumulation enabled<br />

0= Timer gated time accumulation disabled<br />

(TCS must be set to logic ‘0’ when TGATE = 1)<br />

bit 5-4<br />

bit 3<br />

TCKPS: Timer Input Clock Prescale Select bits<br />

11 = 1:256 prescale value<br />

10 = 1:64 prescale value<br />

01 = 1:8 prescale value<br />

00 = 1:1 prescale value<br />

T32: 32-bit Timer Mo<strong>de</strong> Select bits<br />

1= TMR2 and TMR3 form a 32-bit timer<br />

0= TMR2 and TMR3 form separate 16-bit timer<br />

bit 2 Unimplemented: Read as ‘0’<br />

bit 1 TCS: Timer Clock Source Select bit<br />

1= External clock from pin T2CK<br />

0= Internal clock (FOSC/4)<br />

bit 0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 90 dsPIC30F2023


♦ T3CON: Type C Time Base Register<br />

Timers<br />

R/W-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

TON — TSIDL — — — — —<br />

b15 b8<br />

U-0 R/W-0 R/W-0 R/W-0 U-0 U-0 R/W-0 U-0<br />

— TGATE TCKPS — — TCS —<br />

b7 b0<br />

bit 15 TON: Timer On bit<br />

1= Starts 16-bit TMR3<br />

0= Stops 16-bit TMR3<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13<br />

TSIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1= Discontinue module operation when <strong>de</strong>vice enters Idle mo<strong>de</strong><br />

0= Continue module operation in Idle mo<strong>de</strong><br />

bit 12-7 Unimplemented: Read as ‘0’<br />

bit 6 TGATE: Timer Gated Time Accumulation Enable bit<br />

1= This mo<strong>de</strong> should not be used<br />

0= Timer gated time accumulation disabled (Read as ‘0’ if TCS = 1)<br />

(TCS must be set to logic ‘0’ when TGATE = 1)<br />

bit 5-4<br />

TCKPS: Timer Input Clock Prescale Select bits<br />

11 = 1:256 prescale value<br />

10 = 1:64 prescale value<br />

01 = 1:8 prescale value<br />

00 = 1:1 prescale value<br />

bit 3-2 Unimplemented: Read as ‘0’<br />

bit 1 TCS: Timer Clock Source Select bit<br />

1= This mo<strong>de</strong> should not be used<br />

0= Internal clock (FOSC/4)<br />

bit 0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 91 dsPIC30F2023


Timers<br />

♦ Applications<br />

On suppose que le dsPIC fonctionne à 30 MIPS.<br />

Temporisations<br />

Programmer le timer 1 pour déclencher <strong>de</strong>s interruptions toutes les ms<br />

Quelle est la durée maximale <strong>de</strong> comptage sans utiliser le prédiviseur <br />

En utilisant l’interruption précé<strong>de</strong>nte, écrire la fonction Delay :<br />

void Delay(unsigned ms).<br />

Peut-on créer une fonction <strong>de</strong> temporisation avec une résolution <strong>de</strong> 1 s <br />

Exemple :<br />

void Sleep(unsigned sec)<br />

Clavier<br />

Utiliser une interruption Timer pour gérer le clavier :<br />

• Mettre les caractères dans une FIFO lue par le programme principal<br />

Fonctions :<br />

int Getch(void)<br />

int KbHit(void)<br />

M. <strong>Deloizy</strong> 92 dsPIC30F2023


Convertisseur AN<br />

V Convertisseur Numérique Analogique<br />

V.1 Caractéristiques<br />

• 12 entrées analogiques<br />

• 1 convertisseur 10 bits<br />

• Entrées unipolaires<br />

• 2000 k-échantillons/secon<strong>de</strong> (en 5V) (2 conversions/μs)<br />

• 4 échantillonneurs bloqueurs dédiés, 1 échantillonneur commun<br />

• Ne fonctionne pas en mo<strong>de</strong> SLEEP<br />

• Nécessite le fonctionnement <strong>de</strong> la PLL<br />

• Plusieurs conversions peuvent être <strong>de</strong>mandées simultanément :<br />

Séquentiellement en commençant par les canaux d’ordre inférieur.<br />

• Conversions par paires <strong>de</strong> canaux.<br />

• Conversion d’une paire en 24 cycles.<br />

• 16 sources <strong>de</strong> déclenchement pour chaque paire.<br />

• Buffer résultat (ADCBUFx) pour chaque canal, avec 2 formats.<br />

• Système d’in<strong>de</strong>xation permettant la reconnaissance rapi<strong>de</strong> <strong>de</strong> la source<br />

d’interruption.<br />

M. <strong>Deloizy</strong> 93 dsPIC30F2023


V.2 Schéma fonctionnel<br />

Convertisseur AN<br />

M. <strong>Deloizy</strong> 94 dsPIC30F2023


V.3 Registres <strong>de</strong> contrôle<br />

Convertisseur AN<br />

♦ ADCON : A/D <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 U-0 R/W-0 U-0 U-0 R/W-0 U-0 R/W-0<br />

ADON — ADSIDL — — GSWTRG — FORM<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 U-0 U-0 R/W-0 R/W-1 R/W-1<br />

EIE ORDER SEQSAMP — — ADCS<br />

b7 b0<br />

bit 15 ADON: A/D Operating Mo<strong>de</strong> bit<br />

1 = A/D converter module is operating<br />

0 = A/D converter is off<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13 ADSIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1 = Discontinue module operation when <strong>de</strong>vice enters Idle mo<strong>de</strong><br />

0 = Continue module operation in Idle mo<strong>de</strong><br />

bit 12-11 Unimplemented: Read as ‘0’<br />

bit 10<br />

GSWTRG: Global Software Trigger bit<br />

When this bit is set by the user, it will trigger conversions if selected by the TRGSRC bits in the ADCPCx registers.<br />

This bit must be cleared by the user prior to initiating another global trigger (i.e., this bit is not auto-clearing).<br />

bit 9 Unimplemented: Read as ‘0’<br />

bit 8 FORM: Data Output Format bit<br />

1 = Fractional (DOUT = dddd dddd dd00 0000)<br />

0 = Integer (DOUT = 0000 00dd dddd dddd)<br />

bit 7 EIE: Early Interrupt Enable bit<br />

1 = Interrupt is generated after first conversion is completed<br />

0 = Interrupt is generated after second conversion is completed<br />

Note: This control bit can only be changed while ADC is disabled (ADON = 0).<br />

bit 6 ORDER: Conversion Or<strong>de</strong>r bit<br />

1 = Odd numbered analog input is converted first, followed by conversion of even numbered input<br />

0 = Even numbered analog input is converted first, followed by conversion of odd numbered input<br />

Note: This control bit can only be changed while ADC is disabled (ADON = 0).<br />

M. <strong>Deloizy</strong> 95 dsPIC30F2023


Convertisseur AN<br />

bit 5 SEQSAMP: Sequential Sample Enable.<br />

1 = Shared S&H is sampled at the start of the second conversion if ORDER = 0. If ORDER = 1, then the shared S&H is sampled at the<br />

start of the first conversion.<br />

0 = Shared S&H is sampled at the same time the <strong>de</strong>dicated S&H is sampled if the shared S&H is not currently busy with an existing<br />

conversion process. If the shared S&H is busy at the time the <strong>de</strong>dicated S&H is sampled, then the shared S&H will sample at the start<br />

of the new conversion cycle<br />

bit 4-3 Unimplemented: Read as ‘0’<br />

bit 2-0 ADCS: A/D Conversion Clock Divi<strong>de</strong>r Select bits<br />

If PLL is enabled (assume 15 MHz external clock as clock source):<br />

111 = FADC/18 = 13.3 MHz @ 30 MIPS<br />

110 = FADC/16 = 15.0 MHz @ 30 MIPS<br />

101 = FADC/14 = 17.1 MHz @ 30 MIPS<br />

100 = FADC/12 = 20.0 MHz @ 30 MIPS<br />

011 = FADC/10 = 24.0 MHz @ 30 MIPS<br />

010 = FADC/8 = 30.0 MHz @ 30 MIPS<br />

001 = FADC/6 = Reserved, <strong>de</strong>faults to 30 MHz @ 30 MIPS<br />

000 = FADC/4 = Reserved, <strong>de</strong>faults to 30 MHz @ 30 MIPS<br />

If PLL is disabled (assume 15 MHz external clock as clock source):<br />

111 = FADC/18 = 0.83 MHz @ 7.5 MIPS<br />

110 = FADC/16 = 0.93 MHz @ 7.5 MIPS<br />

101 = FADC/14 = 1.07 MHz @ 7.5 MIPS<br />

100 = FADC/12 = 1.25 MHz @ 7.5 MIPS<br />

011 = FADC/10 = 1.5 MHz @ 7.5 MIPS<br />

010 = FADC/8 = 1.87 MHz @ 7.5 MIPS<br />

001 = FADC/6 = 2.5 MHz @ 7.5 MIPS<br />

000 = FADC/4 = 3.75 MHz @ 7.5 MIPS<br />

M. <strong>Deloizy</strong> 96 dsPIC30F2023


Convertisseur AN<br />

♦ ADSTAT : A/D STATUS <strong>REGISTER</strong><br />

U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0<br />

— — — — — — — —<br />

b15 b8<br />

U-0 U-0 R/C-0<br />

H-S<br />

R/C-0<br />

H-S<br />

R/C-0<br />

H-S<br />

R/C-0<br />

H-S<br />

R/C-0<br />

H-S<br />

R/C-0<br />

H-S<br />

— — P5RDY P4RDY P3RDY P2RDY P1RDY P0RDY<br />

b7 b0<br />

C = Clear in software H-S = Set by hardware<br />

bit 15-6 Unimplemented: Read as ‘0’<br />

bit 5 P5RDY: Conversion Data for Pair #5 Ready bit<br />

Bit set when data is ready in buffer, cleared when a ‘0’ is written to this bit.<br />

bit 4 P4RDY: Conversion Data for Pair #4 Ready bit<br />

Bit set when data is ready in buffer, cleared when a ‘0’ is written to this bit.<br />

bit 3 P3RDY: Conversion Data for Pair #3 Ready bit<br />

Bit set when data is ready in buffer, cleared when a ‘0’ is written to this bit.<br />

bit 2 P2RDY: Conversion Data for Pair #2 Ready bit<br />

Bit set when data is ready in buffer, cleared when a ‘0’ is written to this bit.<br />

bit 1 P1RDY: Conversion Data for Pair #1 Ready bit<br />

Bit set when data is ready in buffer, cleared when a ‘0’ is written to this bit.<br />

bit 0 P0RDY: Conversion Data for Pair #0 Ready bit<br />

Bit set when data is ready in buffer, cleared when a ‘0’ is written to this bit.<br />

M. <strong>Deloizy</strong> 97 dsPIC30F2023


Convertisseur AN<br />

♦ ADBASE : A/D BASE <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

ADBASE<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0<br />

ADBASE —<br />

b7 b0<br />

bit 15-1 ADC Base Register: This register contains the base address of the user’s ADC Interrupt Service Routine jump table. This register, when<br />

read, contains the sum of the ADBASE register contents and the enco<strong>de</strong>d value of the PxRDY Status bits.<br />

The enco<strong>de</strong>r logic provi<strong>de</strong>s the bit number of the highest priority PxRDY bits where P0RDY is the highest priority, and P5RDY is<br />

lowest priority.<br />

Note: The encoding results are shifted left two bits so bits 1-0 of the result are always zero.<br />

bit 0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 98 dsPIC30F2023


Convertisseur AN<br />

♦ ADPCFG : A/D PORT CONFIGURATION <strong>REGISTER</strong><br />

U-0 U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— — — — PCFG11 PCFG10 PCFG9 PCFG8<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PCFG7 PCFG6 PCFG5 PCFG4 PCFG3 PCFG2 PCFG1 PCFG0<br />

b7 b0<br />

bit 15-12 Unimplemented: Read as ‘0’<br />

bit 11-0 PCFG: A/D Port Configuration Control bits<br />

1 = Port pin in Digital mo<strong>de</strong>, port read input enabled, A/D input multiplexor connected to AVSS<br />

0 = Port pin in Analog mo<strong>de</strong>, port read input disabled, A/D samples pin voltage<br />

M. <strong>Deloizy</strong> 99 dsPIC30F2023


Convertisseur AN<br />

♦ ADCPCn : A/D CONVERT PAIR <strong>CONTROL</strong> <strong>REGISTER</strong> #n<br />

ADCPC0 : contrôle <strong>de</strong> la conversion <strong>de</strong>s paires (AN0, AN1) et (AN2, AN3)<br />

n=0 x=0 y=1 c=0<br />

ADCPC1 : contrôle <strong>de</strong> la conversion <strong>de</strong>s paires (AN4, AN5) et (AN6, AN7)<br />

n=1 x=2 y=3 c=4<br />

ADCPC2 : contrôle <strong>de</strong> la conversion <strong>de</strong>s paires (AN8, AN9) et (AN10, AN11)<br />

n=2 x=4 y=5 c=8<br />

M. <strong>Deloizy</strong> 100 dsPIC30F2023


Convertisseur AN<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

IRQENy PENDy SWTRGy<br />

TRGSRCy<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

IRQENx PENDx SWTRGx<br />

TRGSRCx<br />

b7 b0<br />

bit 15<br />

bit 14<br />

bit 13<br />

bit 12-8<br />

IRQENy: Interrupt Request Enable y bit<br />

1 = Enable IRQ generation when requested conversion of channels AN(c+3) and AN(c+2) is completed<br />

0 = IRQ is not generated<br />

PENDy: Pending Conversion Status y bit<br />

1 = Conversion of channels AN(c+3) and AN(c+2) is pending. Set when selected trigger is asserted<br />

0 = Conversion is complete<br />

SWTRGy: Software Trigger y bit<br />

1 = Start conversion of AN(c+3) and AN(c+2) (if selected in TRGSRC bits). If other conversions are in progress, then conversion will be<br />

performed when the conversion resources are available. This bit will be reset when the PEND bit is set.<br />

TRGSRy: Trigger y Source Selection bits<br />

Selects trigger source for conversion of analog channels AN(c+3) and AN(c+2).<br />

00000 = No conversion enabled<br />

00001 = Individual software trigger selected<br />

00010 = Global software trigger selected (voir GSWTRG, ADCON)<br />

00011 = <strong>PWM</strong> Special Event Trigger selected<br />

00100 = <strong>PWM</strong> generator #1 trigger selected<br />

00101 = <strong>PWM</strong> generator #2 trigger selected<br />

00110 = <strong>PWM</strong> generator #3 trigger selected<br />

00111 = <strong>PWM</strong> generator #4 trigger selected<br />

01100 = Timer #1 period match<br />

01101 = Timer #2 period match<br />

01110 = <strong>PWM</strong> GEN #1 current-limit ADC trigger<br />

01111 = <strong>PWM</strong> GEN #2 current-limit ADC trigger<br />

10000 = <strong>PWM</strong> GEN #3 current-limit ADC trigger<br />

10001 = <strong>PWM</strong> GEN #4 current-limit ADC trigger<br />

10110 = <strong>PWM</strong> GEN #1 fault ADC trigger<br />

10111 = <strong>PWM</strong> GEN #2 fault ADC trigger<br />

11000 = <strong>PWM</strong> GEN #3 fault ADC trigger<br />

11001 = <strong>PWM</strong> GEN #4 fault ADC trigger<br />

M. <strong>Deloizy</strong> 101 dsPIC30F2023


it 7<br />

bit 6<br />

bit 5<br />

bit 4-0<br />

Convertisseur AN<br />

IRQENx: Interrupt Request Enable x bit<br />

1 = Enable IRQ generation when requested conversion of channels AN(c+1) and AN(c+0) is completed<br />

0 = IRQ is not generated<br />

PENDx: Pending Conversion Status x bit<br />

1 = Conversion of channels AN(c+1) and AN(c+0) is pending. Set when selected trigger is asserted.<br />

0 = Conversion is complete<br />

SWTRGx: Software Trigger x bit<br />

1 = Start conversion of AN(c+1) and AN(c+0) (if selected by TRGSRC bits). If other conversions are in progress, then conversion will<br />

be performed when the conversion resources are available. This bit will be reset when the PEND bit is set<br />

TRGSRCx: Trigger x Source Selection bits<br />

Selects trigger source for conversion of analog channels AN(c+1) and AN(c+0).<br />

00000 = No conversion enabled<br />

00001 = Individual software trigger selected<br />

00010 = Global software trigger selected<br />

00011 = <strong>PWM</strong> Special Event Trigger selected<br />

00100 = <strong>PWM</strong> generator #1 trigger selected<br />

00101 = <strong>PWM</strong> generator #2 trigger selected<br />

00110 = <strong>PWM</strong> generator #3 trigger selected<br />

00111 = <strong>PWM</strong> generator #4 trigger selected<br />

01100 = Timer #1 period match<br />

01101 = Timer #2 period match<br />

01110 = <strong>PWM</strong> GEN #1 current-limit ADC trigger<br />

01111 = <strong>PWM</strong> GEN #2 current-limit ADC trigger<br />

10000 = <strong>PWM</strong> GEN #3 current-limit ADC trigger<br />

10001 = <strong>PWM</strong> GEN #4 current-limit ADC trigger<br />

10110 = <strong>PWM</strong> GEN #1 fault ADC trigger<br />

10111 = <strong>PWM</strong> GEN #2 fault ADC trigger<br />

11000 = <strong>PWM</strong> GEN #3 fault ADC trigger<br />

11001 = <strong>PWM</strong> GEN #4 fault ADC trigger<br />

M. <strong>Deloizy</strong> 102 dsPIC30F2023


V.4 Séquence <strong>de</strong> conversionn<br />

(SEQSAMP<br />

= 0)<br />

Convertisseur AN<br />

M. <strong>Deloizy</strong><br />

103<br />

dsPIC30F2023


Convertisseur AN<br />

V.5 Interruptions<br />

V.5.a Interruption par groupe<br />

• Interruption unique pour le module <strong>de</strong> conversion analogique.<br />

• On autorise les interruptions <strong>de</strong> chaque paire dans les registres ADCPCn.<br />

• L’interruption est déclenchée quand la conversion est terminée :<br />

o Le bit PxRDY (dans ADSTAT) est mis à 1 (mis à 0 par programme)<br />

o ADIF (IFS0) est mis à 1 (mis à 0 avant PxRDY par programme)<br />

V.5.b Interruption individuelle (par paire)<br />

• Ces interruptions sont toujours autorisées par le module <strong>de</strong> conversion<br />

analogique<br />

• Autorisations par les flags ADCPxIE dans le registre IEC2<br />

V.5.c Interruption anticipée<br />

• Une interruption peut être déclenchée dès la fin <strong>de</strong> conversion du<br />

premier canal <strong>de</strong> la paire grâce à EIE (ADCON).<br />

• Le bit PENDx <strong>de</strong>s registres ADCPCn restent à 1 tant que les <strong>de</strong>ux<br />

canaux ne sont pas convertis.<br />

• Quand la conversion <strong>de</strong> la paire est terminée, PENDx = 0 et PxRDY<br />

(dans ADSTAT) passe à 1.<br />

M. <strong>Deloizy</strong> 104 dsPIC30F2023


♦ Application<br />

Convertisseur AN<br />

Lire la tension analogique présente sur AN3.<br />

Quelle est la valeur numérique obtenue si la tension vaut :<br />

- 1 volt <br />

- 2,5 volts <br />

- 3 volts <br />

- 5 volts <br />

- 5,5 volts <br />

Quelle est la résolution obtenue <br />

On souhaite mesurer le courant circulant dans une<br />

résistance avec le montage suivant :<br />

• On mémorise 256 échantillons à 10 KHz<br />

• On utilise le timer 2.<br />

• R=100Ω. I exprimé en μA (1u/μA)<br />

R<br />

I V 0<br />

V 1<br />

AN0<br />

AN1<br />

M. <strong>Deloizy</strong> 105 dsPIC30F2023


Capture Compare<br />

VI Modules Capture Compare<br />

M. <strong>Deloizy</strong> 106 dsPIC30F2023


Capture Compare<br />

VI.1 Module Capture<br />

VI.1.a Caractéristiques<br />

• Détection <strong>de</strong> l’instant d’un événement<br />

• 1 entrée capture (IC1, multiplexée avec RD0. Doit être configurée en entrée.)<br />

• Utilisation du Timer 2 ou du Timer 3<br />

• Événement sur IC1 :<br />

o Front <strong>de</strong>scendant<br />

o Front montant<br />

o Tous les 4 fronts montants<br />

o Tous les 16 fronts montants<br />

o Chaque front (montant ou <strong>de</strong>scendant)<br />

• FIFO à 4 niveaux<br />

• Détection d’un overflow<br />

• Déclenchement d’interruptions<br />

• Possibilités <strong>de</strong> fonctionnement en mo<strong>de</strong>s IDLE ou SLEEP<br />

M. <strong>Deloizy</strong> 107 dsPIC30F2023


VI.1. .b Schéma fonctionnel<br />

Capture Compare<br />

M. <strong>Deloizy</strong><br />

108<br />

dsPIC30F2023


VI.1.c<br />

Registres associés<br />

♦ IC1BUF : Input 1 Capture Register<br />

Reset State : uuuu uuuu uuuu uuuu<br />

Capture Compare<br />

M. <strong>Deloizy</strong> 109 dsPIC30F2023


Capture Compare<br />

♦ IC1CON: Input Capture 1 Control Register<br />

U-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

— — ICSIDL — — — — —<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R-0, HC R-0, HC R/W-0 R/W-0 R/W-0<br />

ICTMR ICI ICOV ICBNE ICM<br />

b7 b0<br />

bit 15-14 Unimplemented: Read as ‘0’<br />

bit 13<br />

ICSIDL: Input Capture Module Stop in Idle Control bit<br />

1= Input capture module will halt in CPU Idle mo<strong>de</strong><br />

0= Input capture module will continue to operate in CPU Idle mo<strong>de</strong><br />

bit 12-8 Unimplemented: Read as ‘0’<br />

bit 7<br />

bit 6-5<br />

ICTMR: Input Capture Timer Select bits<br />

1= TMR2 contents are captured on capture event<br />

0= TMR3 contents are captured on capture event<br />

Note: Timer selections may vary. Refer to the <strong>de</strong>vice data sheet for <strong>de</strong>tails.<br />

ICI: Select Number of Captures per Interrupt bits<br />

11= Interrupt on every fourth capture event<br />

10= Interrupt on every third capture event<br />

01= Interrupt on every second capture event<br />

00= Interrupt on every capture event<br />

bit 4 ICOV: Input Capture Overflow Status Flag (Read Only) bit<br />

1= Input capture overflow occurred<br />

0= No input capture overflow occurred<br />

bit 3 ICBNE: Input Capture Buffer Empty Status (Read Only) bit<br />

1= Input capture buffer is not empty, at least one more capture value can be read<br />

0= Input capture buffer is empty<br />

bit 2-0<br />

ICM: Input Capture Mo<strong>de</strong> Select bits<br />

111 = Input Capture functions as interrupt pin only, when <strong>de</strong>vice is in Sleep or Idle mo<strong>de</strong> (Rising edge <strong>de</strong>tect only, all other control bits<br />

are not applicable.)<br />

110 = Unused (module disabled)<br />

101 = Capture mo<strong>de</strong>, every 16th rising edge<br />

100 = Capture mo<strong>de</strong>, every 4th rising edge<br />

011 = Capture mo<strong>de</strong>, every rising edge<br />

010 = Capture mo<strong>de</strong>, every falling edge<br />

001 = Capture mo<strong>de</strong>, every edge (rising and falling) (ICI does not control interrupt generation for this mo<strong>de</strong>.)<br />

000 = Input capture module turned off<br />

M. <strong>Deloizy</strong> 110 dsPIC30F2023


Capture Compare<br />

VI.2 Module Compare<br />

VI.2.a Caractéristiques<br />

• 2 sorties Compare (OC1 et OC2, doivent être configurées en sortie)<br />

• Déclenchement d’un événement à un instant prédéterminé.<br />

• Utilisation <strong>de</strong> Timer 2 ou Timer 3<br />

• Fonctions possibles :<br />

o OCx mis à 0<br />

o OCx mis à 1<br />

o OCx inversé (toggle)<br />

o Génération <strong>PWM</strong> (avec possibilité entrée défaut OCFLTA)<br />

o Génération d’impulsions simples ou continues<br />

• Déclenchement possible d’interruptions<br />

M. <strong>Deloizy</strong> 111 dsPIC30F2023


VI.2. .b Schéma fonctionnel<br />

Capture Compare<br />

M. <strong>Deloizy</strong><br />

112<br />

dsPIC30F2023


Capture Compare<br />

VI.2.c Mo<strong>de</strong> comparaison simple<br />

• Mise à 0, 1 ou inversion <strong>de</strong> la sortie quand la valeur du timer atteint<br />

celle contenue dans le registre OCxR<br />

• Si le timer effectue repasse par 0 avant d’atteindre OCxR, la sortie<br />

n’est pas modifiée<br />

• Le niveau <strong>de</strong> la sortie est initialisé à l'état 1 pour une mise à 0, et à<br />

l’état 0 pour une mise à 1, lors <strong>de</strong> la programmation <strong>de</strong> ces mo<strong>de</strong>s.<br />

• Une interruption est déclenchée à la suite <strong>de</strong> la comparaison.<br />

M. <strong>Deloizy</strong> 113 dsPIC30F2023


Capture Compare<br />

VI.2.d Mo<strong>de</strong> comparaison double<br />

Permet <strong>de</strong> générer une impulsion ou <strong>de</strong>s impulsions continues.<br />

• L’impulsion débute à la valeur contenue dans OCxR. Elle se termine à<br />

la valeur contenue dans OCxRS. Le registre <strong>de</strong> pério<strong>de</strong> du timer doit<br />

avoir une valeur supérieure à OCxRS.<br />

• Le niveau initial <strong>de</strong> la sortie est 0, dès la programmation du mo<strong>de</strong><br />

(OCM = 100 ou 101)<br />

• En mo<strong>de</strong> impulsion simple (OCM = 100), une nouvelle impulsion<br />

peut être générée en reprogrammant le mo<strong>de</strong> (OCM = 100).<br />

• En mo<strong>de</strong> impulsion continue, l’impulsion est générée à chaque pério<strong>de</strong><br />

définie par le timer.<br />

• Une interruption est déclenchée à la fin <strong>de</strong> l’impulsion.<br />

M. <strong>Deloizy</strong> 114 dsPIC30F2023


Capture Compare<br />

VI.2. .e Mo<strong>de</strong><br />

<strong>PWM</strong><br />

• La pério<strong>de</strong> <strong>de</strong> la<br />

<strong>PWM</strong> (fréquen<br />

nce porteuse) est fixée<br />

pério<strong>de</strong><br />

du timer.<br />

• Le rapport cyclique est<br />

contenu dans OCxRS<br />

• OCxR <strong>de</strong>vient en lecture seulee<br />

• Fonctionnement :<br />

par le registre <strong>de</strong><br />

Timer<br />

is cleared and new duty<br />

cycle value is loa<strong>de</strong>d from<br />

OCxRS<br />

into OCxR.<br />

Timer<br />

value equals value in the OCxR register, OCx Pin is driven<br />

low.<br />

Timer<br />

overflow, value<br />

from OCxRS is loa<strong>de</strong>d into OCxR, OCx pin<br />

driven<br />

high.<br />

TyIF interrupt<br />

flag is asserted.<br />

M. <strong>Deloizy</strong><br />

115<br />

dsPIC30F2023


Capture Compare<br />

• En mo<strong>de</strong> <strong>PWM</strong> avec entrée défaut (fault), la patte OCFLTA (RA9) est<br />

utilisée. Si cette patte passe au niveau 0, la sortie <strong>PWM</strong> (OC1 ou OC2)<br />

passe en haute impédance<br />

o Tant que le défaut subsiste<br />

o Tant que le mo<strong>de</strong> n’est pas reprogrammé<br />

M. <strong>Deloizy</strong> 116 dsPIC30F2023


VI.2.f<br />

Registres<br />

Capture Compare<br />

♦ OCxCON: Output Compare x Control Register (OC1CON, OC2CON)<br />

U-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

— — OCSIDL — — — — —<br />

b15 b8<br />

U-0 U-0 U-0 R-0, HC R/W-0 R/W-0 R/W-0 R/W-0<br />

— — — OCFLT OCTSEL OCM<br />

b7 b0<br />

bit 15-14 Unimplemented: Read as ‘0’<br />

bit 13<br />

OCSIDL: Stop Output Compare in Idle Mo<strong>de</strong> Control bit<br />

1= Output compare x will halt in CPU Idle mo<strong>de</strong><br />

0= Output compare x will continue to operate in CPU Idle mo<strong>de</strong><br />

bit 12-5 Unimplemented: Read as ‘0’<br />

bit 4<br />

bit 3<br />

bit 2-0<br />

OCFLT: <strong>PWM</strong> Fault Condition Status bit<br />

1= <strong>PWM</strong> Fault condition has occurred (cleared in HW only)<br />

0= No <strong>PWM</strong> Fault condition has occurred<br />

(This bit is only used when OCM = 111.)<br />

OCTSEL: Output Compare Timer Select bit<br />

1= Timer3 is the clock source for compare x<br />

0= Timer2 is the clock source for compare x<br />

Note: Refer to the <strong>de</strong>vice data sheet for specific time bases available to the output compare module.<br />

OCM: Output Compare Mo<strong>de</strong> Select bits<br />

111 = <strong>PWM</strong> mo<strong>de</strong> on OCx, Fault pin enabled<br />

110 = <strong>PWM</strong> mo<strong>de</strong> on OCx, Fault pin disabled<br />

101 = Initialize OCx pin low, generate continuous output pulses on OCx pin<br />

100 = Initialize OCx pin low, generate single output pulse on OCx pin<br />

011 = Compare event toggles OCx pin<br />

010 = Initialize OCx pin high, compare event forces OCx pin low<br />

001 = Initialize OCx pin low, compare event forces OCx pin high<br />

000 = Output compare channel is disabled<br />

M. <strong>Deloizy</strong> 117 dsPIC30F2023


Capture Compare<br />

♦ OCxRS : Output Compare x Slave Register (OC1RS, OC2RS)<br />

Reset State : 0000 0000 0000 0000<br />

♦ OCxR : Output Compare x Master Register (OC1R, OC2R)<br />

Reset State : 0000 0000 0000 0000<br />

M. <strong>Deloizy</strong> 118 dsPIC30F2023


♦ Application<br />

Capture Compare<br />

Faire la mesure <strong>de</strong> la pério<strong>de</strong> d’un signal rectangulaire<br />

pour un signal dont la fréquence peut varier :<br />

• Entre 10 et 20 KHz.<br />

• Entre 10 Hz et 2 KHz<br />

T<br />

Mesurer (en %) le rapport cyclique défini par : <br />

<br />

<br />

Générer une impulsion <strong>de</strong> 100μs toutes les ms<br />

Utiliser la sortie <strong>PWM</strong> pour générer une tension continue <strong>de</strong> :<br />

• 1 volt<br />

• 3 volts<br />

On utilise le filtre suivant : R<br />

R=10kΩ - C=10μF<br />

C<br />

M. <strong>Deloizy</strong> 119 dsPIC30F2023


<strong>PWM</strong><br />

VII Module <strong>PWM</strong><br />

VII.1 Caractéristiques<br />

La PLL doit être active (voir FNOSC dans FOSCSEL) pour que le<br />

module <strong>PWM</strong> fonctionne.<br />

• 4 Générateurs <strong>PWM</strong> (MLI) avec 8 entrées/sorties<br />

• 4 bases <strong>de</strong> temps indépendantes<br />

• Résolution du rapport cyclique <strong>de</strong> 1.1 ns @ 30 MIPS<br />

• Résolution <strong>de</strong>s temps morts <strong>de</strong> 4.2 ns @ 30 MIPS<br />

• Résolution <strong>de</strong> phase <strong>de</strong> 4.2 ns @ 30 MIPS<br />

• Résolution <strong>de</strong> fréquence <strong>de</strong> 8.4 ns @ 30 MIPS<br />

M. <strong>Deloizy</strong> 120 dsPIC30F2023


<strong>PWM</strong><br />

• Mo<strong>de</strong>s <strong>PWM</strong> supportés :<br />

o <strong>PWM</strong> standard alignée sur fronts<br />

o <strong>PWM</strong> complémentaire<br />

o <strong>PWM</strong> Push-Pull<br />

o <strong>PWM</strong> Multi-Phase<br />

o <strong>PWM</strong> à phase variable<br />

o <strong>PWM</strong> à temps d’allumage ou d’extinction constants (réinitialisation<br />

par courant)<br />

o <strong>PWM</strong> à limitation <strong>de</strong> courant<br />

o <strong>PWM</strong> à bases <strong>de</strong> temps indépendantes<br />

• Changement dynamique <strong>de</strong> la fréquence, du rapport cyclique et <strong>de</strong> la<br />

phase<br />

• Contrôle forcé <strong>de</strong>s sorties<br />

• Entrées défaut et limitation <strong>de</strong> courant indépendantes<br />

• Comparateur d’événement spécial pour comman<strong>de</strong>r d’autres<br />

périphériques<br />

• Chaque générateur <strong>PWM</strong> a un comparateur pour déclencher <strong>de</strong>s<br />

conversions analogiques.<br />

M. <strong>Deloizy</strong> 121 dsPIC30F2023


VII.2<br />

Schéma fonctionnel<br />

<strong>PWM</strong><br />

M. <strong>Deloizy</strong><br />

122 dsPIC30F2023


VII.3 Fonctionnalités<br />

VII.3.a <strong>PWM</strong> alignée sur fronts<br />

• <strong>PWM</strong> standard<br />

• Un compteur compte <strong>de</strong> 0 à la valeur <strong>de</strong> la pério<strong>de</strong><br />

Quand le compteur a une valeur inférieure à celle contenue dans le<br />

registre contenant le rapport cyclique, la sortie <strong>PWM</strong> vaut 1, et 0<br />

sinon.<br />

<strong>PWM</strong><br />

M. <strong>Deloizy</strong> 123 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.b <strong>PWM</strong> complémentaire<br />

• Fonctionnement i<strong>de</strong>ntique à la <strong>PWM</strong> alignée sur fronts<br />

• Génération <strong>de</strong>s comman<strong>de</strong>s <strong>de</strong> bras :<br />

o Comman<strong>de</strong> du transistor du haut (<strong>PWM</strong>H)<br />

o Comman<strong>de</strong> du transistor du bas (<strong>PWM</strong>L)<br />

• Insertion <strong>de</strong>s temps morts<br />

• Exemple d’utilisation :<br />

M. <strong>Deloizy</strong> 124 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.c <strong>PWM</strong> push-pull<br />

• Fonctionnement i<strong>de</strong>ntique à la <strong>PWM</strong> alignée sur<br />

fronts adapté à la comman<strong>de</strong> par<br />

transformateurs :<br />

o Évite composante continue dans les<br />

bobinages<br />

• Le signal <strong>PWM</strong> est généré alternativement sur<br />

<strong>PWM</strong>H et <strong>PWM</strong>L, avec le même rapport cyclique.<br />

• Exemple d’utilisation :<br />

M. <strong>Deloizy</strong> 125 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.d <strong>PWM</strong> multiphase<br />

• Utilise les valeurs <strong>de</strong> déphasage contenue dans les<br />

registres <strong>de</strong> phases (PHASEx)<br />

• Exemple d’utilisation :<br />

M. <strong>Deloizy</strong> 126 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.e <strong>PWM</strong> à phase variable<br />

• Contrôle <strong>de</strong> la différence <strong>de</strong> phase entre 2 signaux<br />

<strong>PWM</strong><br />

• Rapport cyclique constant (souvent ½)<br />

• Mise à jour du déphasage quand les sorties sont<br />

à 0<br />

• Possibilité <strong>de</strong> générer les sorties complémentaires<br />

M. <strong>Deloizy</strong> 127 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.f <strong>PWM</strong> à limitation <strong>de</strong> courant<br />

• <strong>PWM</strong> à fréquence constante<br />

• La sortie <strong>PWM</strong> est forcée à la valeur indiquée<br />

dans FLTDAT <strong>de</strong> IOCONx jusqu’à la fin <strong>de</strong> la<br />

pério<strong>de</strong>.<br />

M. <strong>Deloizy</strong> 128 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.g <strong>PWM</strong> à Reset par courant<br />

• <strong>PWM</strong> à fréquence variable<br />

• La base <strong>de</strong> temps du signal <strong>PWM</strong> est remise à 0<br />

par un signal extérieur avant la pério<strong>de</strong><br />

programmée<br />

♦ <strong>PWM</strong> à temps d’extinction constant<br />

• Utilisation <strong>de</strong> la sortie complémentaire (<strong>PWM</strong>L)<br />

M. <strong>Deloizy</strong> 129 dsPIC30F2023


<strong>PWM</strong><br />

♦ <strong>PWM</strong> à temps d’allumage constant<br />

• Utilisation <strong>de</strong> la sortie haute (<strong>PWM</strong>H)<br />

• Exemple d’utilisation :<br />

M. <strong>Deloizy</strong> 130 dsPIC30F2023


<strong>PWM</strong><br />

VII.3.h <strong>PWM</strong> à bases <strong>de</strong> temps indépendantes<br />

• Permet le contrôle <strong>de</strong> dispositifs différents,<br />

fonctionnant à <strong>de</strong>s fréquences <strong>de</strong> hachage<br />

différentes<br />

• Les signaux <strong>PWM</strong> sont indépendants<br />

M. <strong>Deloizy</strong> 131 dsPIC30F2023


<strong>PWM</strong><br />

VII.4 Base <strong>de</strong> temps primaire<br />

• Base <strong>de</strong> temps (PTMR) pour la totalité du module <strong>PWM</strong><br />

• Non accessible par programme<br />

• Ca<strong>de</strong>ncé à 120 MHz @ 30 MIPS.<br />

• Indique quand il y a égalité entre PTMR et<br />

PTPER.<br />

La fréquence correspondante est donnée par :<br />

4· <br />

<br />

15: 3 1<br />

• Chaque générateur <strong>PWM</strong> dispose <strong>de</strong> sa base <strong>de</strong> temps propre<br />

• Gère<br />

o la mise à jour <strong>de</strong>s registres <strong>de</strong> rapport cyclique et <strong>de</strong> phase<br />

o les déclenchements d’événements spéciaux<br />

o les interruptions liées au timer<br />

• Peut être remis à 0 par un signal externe défini par les bits<br />

SYNCSRC dans PTCON, si autorisé par SYNCEN (PTCON).<br />

• Possibilité <strong>de</strong> synchronisation sur la base <strong>de</strong> temps d’un autre dsPIC <strong>de</strong><br />

même type.<br />

M. <strong>Deloizy</strong> 132 dsPIC30F2023


VII.5 Compteur <strong>de</strong> cycles (Roll counter) du compteur primaire<br />

• Compteur 6 bits non accessible par programme<br />

• Compte les cycles du timer primaire<br />

• Permet d’indiquer l’instant du déclenchement <strong>de</strong> l’événement à<br />

<strong>de</strong>stination du convertisseur analogique, à partir <strong>de</strong>s bits<br />

TRGSTRT dans les registres TRGCONx.<br />

<strong>PWM</strong><br />

M. <strong>Deloizy</strong> 133 dsPIC30F2023


<strong>PWM</strong><br />

VII.6 Bases <strong>de</strong> temps individuelles<br />

Le bit ITB <strong>de</strong>s registres <strong>PWM</strong>CONx permet <strong>de</strong><br />

fonctionner à la fréquence donnée par le compteur<br />

primaire (PTPER) ou à partir du registre <strong>de</strong> phase.<br />

Dans ce cas, la fréquence <strong>de</strong> la <strong>PWM</strong> est donnée par :<br />

4· <br />

<br />

1<br />

VII.7 Rapport cyclique<br />

• Chaque générateur <strong>PWM</strong> possè<strong>de</strong> un registre <strong>de</strong><br />

rapport cyclique (PDCx) ou peut utiliser le<br />

registre <strong>de</strong> rapport cyclique commun (MDC).<br />

• La sortie est active quand la valeur du compteur est inférieure ou égale<br />

aux 13 bits <strong>de</strong> poids fort du registre <strong>de</strong> rapport cyclique.<br />

• La durée du niveau actif est donnée par :<br />

<br />

<br />

<br />

· <br />

• La résolution <strong>de</strong> la <strong>PWM</strong> est <strong>de</strong> 8.4 ns @30MIPS<br />

• Le rapport cyclique (PDCx ou MDC) doit être<br />

compris entre 0x0008 et 0xFFEF :<br />

o 0x0000 mettra 0 en sortie<br />

o 0xFFFF mettra 1 en sortie<br />

M. <strong>Deloizy</strong> 134 dsPIC30F2023


VII.8 Temps morts<br />

• Des temps morts peuvent être insérés entre les sorties <strong>PWM</strong><br />

complémentaires.<br />

• Les temps morts peuvent être négatifs.<br />

• La génération <strong>de</strong>s temps morts est activée par les bits DTC <strong>de</strong>s<br />

registres <strong>PWM</strong>CONx.<br />

• DTRx spécifie le temps mort appliqué au signal <strong>PWM</strong>H et ALTDTRx<br />

celui appliqué au signal <strong>PWM</strong>L.<br />

• La durée du temps mort est donnée par :<br />

<br />

<br />

<br />

· <br />

<strong>PWM</strong><br />

VII.9 Déclenchement d’événement spécial<br />

Synchronisation <strong>de</strong> conversions analogiques sur la <strong>PWM</strong><br />

VII.9.a Commun<br />

• Basé sur la base <strong>de</strong> temps primaire<br />

• L’événement spécial est toujours généré, mais pas forcément utilisé<br />

par le module analogique.<br />

• Géré par les bits SEVTPS <strong>de</strong> PTCON et le registre SEVTCMP<br />

• Quand PTRM atteint SEVTCMP, un événement spécial est déclenché.<br />

• Un post-diviseur d’événement spécial peut être programmé par<br />

SEVTPS <strong>de</strong> PTCON<br />

M. <strong>Deloizy</strong> 135 dsPIC30F2023


<strong>PWM</strong><br />

VII.9.b Individuel<br />

• Déclenché tant que la valeur <strong>de</strong> TRIGx est inférieure à la base <strong>de</strong> temps<br />

locale<br />

• Génère une interruption si le bit<br />

TRGIEN <strong>de</strong> <strong>PWM</strong>CONx est à 1.<br />

• Un post-diviseur est programmable par<br />

TRGDIV <strong>de</strong> TRGCONx<br />

M. <strong>Deloizy</strong> 136 dsPIC30F2023


<strong>PWM</strong><br />

VII.10 Défauts et sur-courants<br />

• Les registres IOCONx et FCLCONx permettent <strong>de</strong> gérer les défauts.<br />

• Chaque générateur <strong>PWM</strong> peut sélectionner une <strong>de</strong>s 12 pattes <strong>de</strong> défaut<br />

ou sur-courants, selon les bits FLTSRC <strong>de</strong> <strong>PWM</strong>CONx.<br />

• Les bits FLTPOL <strong>de</strong>s registres FCLCONx permettent <strong>de</strong> fixer la polarité<br />

<strong>de</strong>s défauts.<br />

• Lorsqu’un défaut est détecté, on peut forcer l’état <strong>de</strong> la sortie <strong>PWM</strong><br />

selon les bits FLTDAT <strong>de</strong> IOCONx.<br />

• Deux mo<strong>de</strong>s <strong>de</strong> fonctionnement existent lors <strong>de</strong> l’apparition du défaut :<br />

o Mo<strong>de</strong> verrouillé :<br />

La sortie <strong>PWM</strong> est figée dans l’état indiqué par FLTDAT tant que le<br />

défaut subsiste et que les flags d’interruption ne sont pas remis à 0.<br />

o Mo<strong>de</strong> cycle par cycle :<br />

<strong>PWM</strong>H est mis à 0, <strong>PWM</strong>L est mis à 1 tant que le défaut subsiste.<br />

M. <strong>Deloizy</strong> 137 dsPIC30F2023


<strong>PWM</strong><br />

VII.11 Interruptions<br />

Les interruptions peuvent être déclenchées à partir <strong>de</strong>s bases <strong>de</strong> temps ou<br />

<strong>de</strong>s lignes <strong>de</strong> défaut ou <strong>de</strong> sur-courants :<br />

• Base <strong>de</strong> temps primaire, lors du déclenchement <strong>de</strong> l’événement spécial,<br />

si autorisé par le bit SEIEN <strong>de</strong> PTCON.<br />

• Bases <strong>de</strong> temps individuelles, lors du déclenchement <strong>de</strong> l’événement<br />

spécial, si autorisé par le bit TRGIEN <strong>de</strong> <strong>PWM</strong>CONx.<br />

• Les lignes FLTx (quand=1) peuvent déclencher <strong>de</strong>s interruptions si<br />

autorisé par les bits FLTIENx <strong>de</strong> <strong>PWM</strong>CONx<br />

• Les sur-courants peuvent être détectés avec le module comparateur et<br />

peuvent déclencher <strong>de</strong>s interruptions si autorisé par les bits CLIEN <strong>de</strong><br />

<strong>PWM</strong>CONx<br />

M. <strong>Deloizy</strong> 138 dsPIC30F2023


VII.12 Registres<br />

<strong>PWM</strong><br />

♦ PTCON: <strong>PWM</strong> TIME BASE <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PTEN — PTSIDL SESTAT SEIEN EIPU SYNCPOL SYNCOEN<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

SYNCEN SYNCSRC SEVTPS<br />

b7 b0<br />

bit 15 PTEN: <strong>PWM</strong> Module Enable bit<br />

1 = <strong>PWM</strong> module is enabled<br />

0 = <strong>PWM</strong> module is disabled<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13<br />

bit 12<br />

bit 11<br />

bit 10<br />

bit 9<br />

bit 8<br />

bit 7<br />

PTSIDL: <strong>PWM</strong> Time Base Stop in Idle Mo<strong>de</strong> bit<br />

1 = <strong>PWM</strong> time base halts in CPU Idle mo<strong>de</strong><br />

0 = <strong>PWM</strong> time base runs in CPU Idle mo<strong>de</strong><br />

SESTAT: Special Event Interrupt Status bit<br />

1 = Special Event Interrupt is pending<br />

0 = Special Event Interrupt is not pending<br />

SEIEN: Special Event Interrupt Enable bit<br />

1 = Special Event Interrupt is enabled<br />

0 = Special Event Interrupt is disabled<br />

EIPU: Enable Immediate Period Updates bit<br />

1 = Active Period register is updated immediately<br />

0 = Active Period register updates occur on <strong>PWM</strong> cycle boundaries<br />

SYNCPOL: Synchronize Input Polarity bit<br />

1 = SYNCIN polarity is inverted (low active)<br />

0 = SYNCIN is high active<br />

SYNCOEN: Primary Time Base Sync Enable bit<br />

1 = SYNCO output is enabled<br />

0 = SYNCO output is disabled<br />

SYNCEN: External Time Base Synchronization Enable bit<br />

1 = External synchronization of primary time base is enabled<br />

0 = External synchronization of primary time base is disabled<br />

M. <strong>Deloizy</strong> 139 dsPIC30F2023


it 6-4<br />

bit 3-0<br />

<strong>PWM</strong><br />

SYNCSRC: Sync Source Selection bits<br />

000 = SYNCI<br />

001 = Reserved<br />

.<br />

.<br />

111 = Reserved<br />

SEVTPS: <strong>PWM</strong> Special Event Trigger Output Postscale Select bits<br />

0000 = 1:1 Postscale<br />

0001 = 1:2 Postscale<br />

| |<br />

| |<br />

1111 = 1:16 Postscale<br />

M. <strong>Deloizy</strong> 140 dsPIC30F2023


<strong>PWM</strong><br />

♦ PTPER: PRIMARY TIME BASE <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0 U-0<br />

— — —<br />

b7 b0<br />

bit 15-3 Primary Time Base (PTMR) Period Value bits<br />

bit 2-0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 141 dsPIC30F2023


<strong>PWM</strong><br />

♦ SEVTCMP: <strong>PWM</strong> SPECIAL EVENT COMPARE <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

SEVTCMP <br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0 U-0<br />

SEVTCMP — — —<br />

b7 b0<br />

bit 15-3 Special Event Compare Count Value bit<br />

bit 2-0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 142 dsPIC30F2023


<strong>PWM</strong><br />

♦ MDC: <strong>PWM</strong> MASTER DUTY CYCLE <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

MDC<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

MDC<br />

b15 b8<br />

bit 15-0<br />

Master <strong>PWM</strong> Duty Cycle Value bits<br />

The minimum value for this register is 0x0008 and the maximum value is 0xFFEF.<br />

M. <strong>Deloizy</strong> 143 dsPIC30F2023


<strong>PWM</strong><br />

♦ <strong>PWM</strong>CONx: <strong>PWM</strong> <strong>CONTROL</strong> <strong>REGISTER</strong><br />

HS/HC-0 HS/HC- HS/HC-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

0<br />

FLTSTAT CLSTAT TRGSTAT FLTIEN CLIEN TRGIEN ITB MDCS<br />

b15 b8<br />

R/W-0 R/W-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0<br />

DTC — — — — XPRES IUE<br />

b7 b0<br />

bit 15 FLTSTAT: Fault Interrupt Status<br />

1 = Fault Interrupt is pending<br />

0 = No Fault Interrupt is pending<br />

This bit is cleared by setting FLTIEN = 0.<br />

Note: Software must clear the interrupt status here, and the corresponding IFS bit in Interrupt Controller.<br />

bit 14 CLSTAT: Current-Limit Interrupt Status bit<br />

1 = Current-limit interrupt is pending<br />

0 = No current-limit interrupt is pending<br />

This bit is cleared by setting CLIEN = 0.<br />

Note: Software must clear the interrupt status here, and the corresponding IFS bit in Interrupt Controller.<br />

bit 13 TRGSTAT: Trigger Interrupt Status bit<br />

1 = Trigger interrupt is pending<br />

0 = No trigger interrupt is pending<br />

This bit is cleared by setting TRGIEN = 0.<br />

bit 12 FLTIEN: Fault Interrupt Enable bit<br />

1 = Fault interrupt enabled<br />

0 = Fault interrupt disabled and FLTSTAT bit is cleared<br />

bit 11 CLIEN: Current-Limit Interrupt Enable bit<br />

1 = Current-limit interrupt enabled<br />

0 = Current-limit interrupt disabled and CLSTAT bit is cleared<br />

bit 10 TRGIEN: Trigger Interrupt Enable bit<br />

1 = A trigger event generates an interrupt request<br />

0 = Trigger event interrupts are disabled and TRGSTAT bit is cleared<br />

bit 9 ITB: In<strong>de</strong>pen<strong>de</strong>nt Time Base Mo<strong>de</strong> bit<br />

1 = Phasex register provi<strong>de</strong>s time base period for this <strong>PWM</strong> generator<br />

0 = Primary time base provi<strong>de</strong>s timing for this <strong>PWM</strong> generator<br />

M. <strong>Deloizy</strong> 144 dsPIC30F2023


<strong>PWM</strong><br />

bit 8 MDCS: Master Duty Cycle Register Select bit<br />

1 = MDC register provi<strong>de</strong>s duty cycle information for this <strong>PWM</strong> generator<br />

0 = PDCx register provi<strong>de</strong>s duty cycle information for this <strong>PWM</strong> generator<br />

bit 7-6 DTC: Dead-time Control bits<br />

00 = Positive <strong>de</strong>ad time actively applied for all output mo<strong>de</strong>s<br />

01 = Negative <strong>de</strong>ad time actively applied for all output mo<strong>de</strong>s<br />

10 = Dead-time function is disabled<br />

11 = Reserved<br />

bit 5-2 Unimplemented: Read as ‘0’<br />

bit 1 XPRES: External <strong>PWM</strong> Reset Control bit<br />

1 = Current-limit source resets time base for this <strong>PWM</strong> generator if it is in in<strong>de</strong>pen<strong>de</strong>nt time base mo<strong>de</strong><br />

0 = External pins do not affect <strong>PWM</strong> time base<br />

bit 0 IUE: Immediate Update Enable bit<br />

1 = Updates to the active PDC registers are immediate<br />

0 = Updates to the active PDC registers are synchronized to the <strong>PWM</strong> time base<br />

M. <strong>Deloizy</strong> 145 dsPIC30F2023


<strong>PWM</strong><br />

♦ PDCx: <strong>PWM</strong> GENERATOR DUTY CYCLE <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PDCx<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PDCx<br />

b7 b0<br />

bit 15-0<br />

<strong>PWM</strong> Generator #x Duty Cycle Value bits<br />

The minimum value for this register is 0x0008 and the maximum value is 0xFFEF.<br />

M. <strong>Deloizy</strong> 146 dsPIC30F2023


<strong>PWM</strong><br />

♦ PHASEx: <strong>PWM</strong> PHASE-SHIFT <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PHASEx<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0<br />

PHASEx — —<br />

b7 b0<br />

bit 15-2 PHASEx: <strong>PWM</strong> Phase-Shift Value or In<strong>de</strong>pen<strong>de</strong>nt Time Base Period for this <strong>PWM</strong> Generator bits<br />

Note: If used as an in<strong>de</strong>pen<strong>de</strong>nt time base, bits are not used.<br />

bit 1-0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 147 dsPIC30F2023


<strong>PWM</strong><br />

♦ DTRx: <strong>PWM</strong> DEAD-TIME <strong>REGISTER</strong><br />

U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— — DTRx<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0<br />

DTRx — —<br />

b7 b0<br />

bit 15-14 Unimplemented: Read as ‘0’<br />

bit 13-2 DTRx: Unsigned 12-bit Dead-Time Value bits for <strong>PWM</strong>x Dead-Time Unit bits<br />

bit 1-0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 148 dsPIC30F2023


<strong>PWM</strong><br />

♦ ALTDTRx: <strong>PWM</strong> ALTERNATE DEAD-TIME <strong>REGISTER</strong><br />

U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— — ALTDTRx<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0<br />

ALTDTRx — —<br />

b7 b0<br />

bit 15-14 Unimplemented: Read as ‘0’<br />

bit 13-2 ALTDTRx: Unsigned 12-bit Dead-Time Value bits for <strong>PWM</strong>x Dead-Time Unit bits<br />

bit 1-0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 149 dsPIC30F2023


<strong>PWM</strong><br />

♦ TRGCONx: <strong>PWM</strong> TRIGGER <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

TRGDIV — — — — —<br />

b15 b8<br />

U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— — TRGSTRT<br />

b7 b0<br />

bit 15-13 TRGDIV: Trigger Output Divi<strong>de</strong>r bits<br />

000 = Trigger output for every trigger event<br />

001 = Trigger output for every 2nd trigger event<br />

010 = Trigger output for every 3rd trigger event<br />

011 = Trigger output for every 4th trigger event<br />

100 = Trigger output for every 5th trigger event<br />

101 = Trigger output for every 6th trigger event<br />

110 = Trigger output for every 7th trigger event<br />

111 = Trigger output for every 8th trigger event<br />

bit 12-6 Unimplemented: Read as ‘0’<br />

bit 5-0 TRGSTRT: Trigger Postscaler Start Enable Select bits<br />

This value specifies the ROLL counter value nee<strong>de</strong>d for a match that will then enable the trigger<br />

postscaler logic to begin counting trigger events.<br />

M. <strong>Deloizy</strong> 150 dsPIC30F2023


<strong>PWM</strong><br />

♦ IOCONx: <strong>PWM</strong> I/O <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PENH PENL POLH POLL PMOD OVRENH OVRENL<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 R/W-0<br />

OVRDAT FLTDAT CLDAT — OSYNC<br />

b7 b0<br />

bit 15<br />

bit 14<br />

bit 13<br />

bit 12<br />

bit 11-10<br />

PENH: <strong>PWM</strong>H Output Pin Ownership bit<br />

1 = <strong>PWM</strong> module controls <strong>PWM</strong>xH pin<br />

0 = GPIO module controls <strong>PWM</strong>xH pin<br />

PENL: <strong>PWM</strong>L Output Pin Ownership bit<br />

1 = <strong>PWM</strong> module controls <strong>PWM</strong>xL pin<br />

0 = GPIO module controls <strong>PWM</strong>xL pin<br />

POLH: <strong>PWM</strong>H Output Pin Polarity bit<br />

1 = <strong>PWM</strong>xH pin is low active<br />

0 = <strong>PWM</strong>xH pin is high active<br />

POLL: <strong>PWM</strong>L Output Pin Polarity bit<br />

1 = <strong>PWM</strong>xL pin is low active<br />

0 = <strong>PWM</strong>xL pin is high active<br />

PMOD: <strong>PWM</strong> #x I/O Pin Mo<strong>de</strong> bits<br />

00 = <strong>PWM</strong> I/O pin pair is in the Complementary Output mo<strong>de</strong><br />

01 = <strong>PWM</strong> I/O pin pair is in the In<strong>de</strong>pen<strong>de</strong>nt Output mo<strong>de</strong><br />

10 = <strong>PWM</strong> I/O pin pair is in the Push-Pull Output mo<strong>de</strong><br />

11 = Reserved<br />

bit 9 OVRENH: Overri<strong>de</strong> Enable for <strong>PWM</strong>xH Pin bit<br />

1 = OVRDAT provi<strong>de</strong>s data for output on <strong>PWM</strong>xH pin<br />

0 = <strong>PWM</strong> generator provi<strong>de</strong>s data for <strong>PWM</strong>xH pin<br />

bit 8 OVRENL: Overri<strong>de</strong> Enable for <strong>PWM</strong>xL Pin bit<br />

1 = OVRDAT provi<strong>de</strong>s data for output on <strong>PWM</strong>xL pin<br />

0 = <strong>PWM</strong> generator provi<strong>de</strong>s data for <strong>PWM</strong>xL pin<br />

bit 7-6 OVRDAT: Data for <strong>PWM</strong>xH,L Pins if Overri<strong>de</strong> is Enabled bits<br />

If OVERENH = 1 then OVRDAT provi<strong>de</strong>s data for <strong>PWM</strong>xH<br />

If OVERENL = 1 then OVRDAT provi<strong>de</strong>s data for <strong>PWM</strong>xL<br />

M. <strong>Deloizy</strong> 151 dsPIC30F2023


<strong>PWM</strong><br />

bit 5-4 FLTDAT: Data for <strong>PWM</strong>xH,L Pins if FLTMODE is Enabled bits<br />

If Fault active, then FLTDAT provi<strong>de</strong>s data for <strong>PWM</strong>xH<br />

If Fault active, then FLTDAT provi<strong>de</strong>s data for <strong>PWM</strong>xL<br />

bit 3-2 CLDAT: Data for <strong>PWM</strong>xH,L Pins if CLMODE is Enabled bits<br />

If current limit active, then CLDAT provi<strong>de</strong>s data for <strong>PWM</strong>xH<br />

If current limit active, then CLDAT provi<strong>de</strong>s data for <strong>PWM</strong>xL<br />

bit 1 Unimplemented: Read as ‘0’<br />

bit 0 OSYNC: Output Overri<strong>de</strong> Synchronization bit<br />

1 = Output overri<strong>de</strong>s via the OVRDAT bits are synchronized to the <strong>PWM</strong> time bas<br />

0 = Output overri<strong>de</strong>s via the OVDDAT bits occur on next clock boundary<br />

M. <strong>Deloizy</strong> 152 dsPIC30F2023


<strong>PWM</strong><br />

♦ FCLCONx: <strong>PWM</strong> FAULT CURRENT-LIMIT <strong>CONTROL</strong> <strong>REGISTER</strong><br />

U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— — — CLSRC CLPOL<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

CLMODE FLTSRC FLTPOL FLTMOD<br />

b7 b0<br />

bit 15-13 Unimplemented: Read as ‘0’<br />

bit 12-9 CLSRC: Current-Limit Control Signal Source Select for <strong>PWM</strong> #X Generator bits<br />

0000 = Analog Comparator #1<br />

0001 = Analog Comparator #2<br />

0010 = Analog Comparator #3<br />

0011 = Analog Comparator #4<br />

0100 = Reserved<br />

0101 = Reserved<br />

0110 = Reserved<br />

0111 = Reserved<br />

1000 = Shared Fault #1 (SFLT1)<br />

1001 = Shared Fault #2 (SFLT2)<br />

1020 = Shared Fault #3 (SFLT3)<br />

1011 = Shared Fault #4 (SFLT4)<br />

1100 = Reserved<br />

1101 = In<strong>de</strong>pen<strong>de</strong>nt Fault #2 (IFLT2)<br />

1110 = Reserved<br />

1111 = In<strong>de</strong>pen<strong>de</strong>nt Fault #4 (IFLT4)<br />

bit 8 CLPOL: Current-Limit Polarity for <strong>PWM</strong> Generator #X bit<br />

1 = The selected current-limit source is low active<br />

0 = The selected current-limit source is high active<br />

bit 7 CLMODE: Current-Limit Mo<strong>de</strong> Enable for <strong>PWM</strong> Generator #X bit<br />

1 = Current-limit function is enabled<br />

bit 6-3<br />

0 = Current-limit function is disabled<br />

FLTSRC: Fault Control Signal Source Select for <strong>PWM</strong> Generator #X bits<br />

0000 = Analog Comparator #1<br />

0001 = Analog Comparator #2<br />

0010 = Analog Comparator #3<br />

M. <strong>Deloizy</strong> 153 dsPIC30F2023


<strong>PWM</strong><br />

0011 = Analog Comparator #4<br />

0100 = Reserved<br />

0101 = Reserved<br />

0110 = Reserved<br />

0111 = Reserved<br />

1000 = Shared Fault #1 (SFLT1)<br />

1001 = Shared Fault #2 (SFLT2)<br />

1020 = Shared Fault #3 (SFLT3)<br />

1011 = Shared Fault #4 (SFLT4)<br />

1100 = Reserved<br />

1101 = In<strong>de</strong>pen<strong>de</strong>nt Fault #2 (IFLT2)<br />

1110 = Reserved<br />

1111 = In<strong>de</strong>pen<strong>de</strong>nt Fault #4 (IFLT4)<br />

bit 2 FLTPOL: Fault Polarity for <strong>PWM</strong> Generator #X bit<br />

1 = The selected Fault source is low active<br />

0 = The selected Fault source is high active<br />

bit 1-0 FLTMOD: Fault Mo<strong>de</strong> for <strong>PWM</strong> Generator #x bits<br />

00 = The selected Fault source forces <strong>PWM</strong>xH, <strong>PWM</strong>xL pins to FLTDAT values (latched condition)<br />

01 = The selected Fault source forces <strong>PWM</strong>xH, <strong>PWM</strong>xL pins to FLTDAT values (cycle)<br />

10 = Reserved<br />

11 = Fault input is disabled<br />

M. <strong>Deloizy</strong> 154 dsPIC30F2023


<strong>PWM</strong><br />

♦ TRIGx: <strong>PWM</strong> TRIGGER COMPARE VALUE <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

TRGCMP<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0 U-0<br />

TRGCMP — — —<br />

b7 b0<br />

bit 15-3 TRGCMP: Trigger Control Value bits<br />

Register contains the compare value for <strong>PWM</strong>x time base for generating a trigger to the ADC modu<br />

for initiating a sample and conversion process, or generating a trigger interrupt.<br />

bit 2-0 Unimplemented: Read as ‘0’<br />

The minimum usable value for this register is 0x0008<br />

A value of 0x0000 does not produce a trigger.<br />

If the TRIGx value is being calculated based on duty cycle value, you must ensure that a minimum TRIGx value is written into the<br />

register at all times.<br />

M. <strong>Deloizy</strong> 155 dsPIC30F2023


<strong>PWM</strong><br />

♦ LEBCONx: LEADING EDGE BLANKING <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

PHR PHF PLR PLF FLTLEBEN CLLEBEN LEB<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 U-0 U-0 U-0<br />

LEB — — —<br />

b7 b0<br />

bit 15<br />

bit 14<br />

bit 13<br />

bit 12<br />

bit 11<br />

bit 10<br />

PHR: <strong>PWM</strong>H Rising Edge Trigger Enable bit<br />

1 = Rising edge of <strong>PWM</strong>H will trigger LEB counter<br />

0 = LEB ignores rising edge of <strong>PWM</strong>H<br />

PHL: <strong>PWM</strong>H Falling Edge Trigger Enable bit<br />

1 = Falling edge of <strong>PWM</strong>H will trigger LEB counter<br />

0 = LEB ignores falling edge of <strong>PWM</strong>H<br />

PLR: <strong>PWM</strong>L Rising Edge Trigger Enable bit<br />

1 = Rising edge of <strong>PWM</strong>L will trigger LEB counter<br />

0 = LEB ignores rising edge of <strong>PWM</strong>L<br />

PLF: <strong>PWM</strong>L Falling Edge Trigger Enable bit<br />

1 = Falling edge of <strong>PWM</strong>L will trigger LEB counter<br />

0 = LEB ignores falling edge of <strong>PWM</strong>L<br />

FLTLEBEN: Fault Input Leading Edge Blanking Enable bit<br />

1 = Leading Edge Blanking is applied to selected Fault Input<br />

0 = Leading Edge Blanking is not applied to selected Fault Input<br />

CLLEBEN: Current-Limit Leading Edge Blanking Enable bit<br />

1 = Leading Edge Blanking is applied to selected Current-Limit Input<br />

0 = Leading Edge Blanking is not applied to selected Current-Limit Input<br />

bit 9-3 LEB: Leading Edge Blanking for Current-Limit and Fault Inputs bits Value is 8 nsec increments<br />

bit 2-0 Unimplemented: Read as ‘0’<br />

M. <strong>Deloizy</strong> 156 dsPIC30F2023


I²C<br />

VIII Module I²C<br />

VIII.1 Registres<br />

♦ I2CCON: I2C Control Register<br />

R/W-0 U-0 R/W-0 R/W-1<br />

HC<br />

R/W-0 R/W-0 R/W-0 R/W-0<br />

I2CEN — I2CSIDL SCLREL IPMIEN A10M DISSLW SMEN<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

R/W-0<br />

HC<br />

HC HC HC HC<br />

GCEN STREN ACKDT ACKEN RCEN PEN RSEN SEN<br />

b7 b0<br />

bit 15 I2CEN: I2C Enable bit<br />

1 = Enables the I2C module and configures the SDA and SCL pins as serial port pins<br />

0 = Disables I2C module. All I2C pins are controlled by port functions.<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13 I2CSIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1 = Discontinue module operation when <strong>de</strong>vice enters an Idle mo<strong>de</strong><br />

0 = Continue module operation in Idle mo<strong>de</strong><br />

bit 12 SCLREL: SCL Release Control bit (when operating as I2C Slave)<br />

1 = Release SCL clock<br />

0 = Hold SCL clock low (clock stretch)<br />

If STREN = 1:<br />

Bit is R/W (i.e., software may write ‘0’ to initiate stretch and write ‘1’ to release clock)<br />

Hardware clear at beginning of slave transmission.<br />

Hardware clear at end of slave reception.<br />

If STREN = 0:<br />

Bit is R/S (i.e., software may only write ‘1’ to release clock)<br />

Hardware clear at beginning of slave transmission.<br />

bit 11 IPMIEN: Intelligent Peripheral Management Interface (IPMI) Enable bit<br />

1 = Enable IPMI Support mo<strong>de</strong>. All addresses Acknowledged.<br />

M. <strong>Deloizy</strong> 157 dsPIC30F2023


I²C<br />

0 = IPMI mo<strong>de</strong> not enabled<br />

bit 10 A10M: 10-bit Slave Address bit<br />

1 = I2CADD is a 10-bit slave address<br />

0 = I2CADD is a 7-bit slave address<br />

bit 9 DISSLW: Disable Slew Rate Control bit<br />

1 = Slew rate control disabled<br />

0 = Slew rate control enabled<br />

bit 8 SMEN: SMBus Input Levels bit<br />

1 = Enable I/O pin thresholds compliant with SMBus specification<br />

0 = Disable SMBus input thresholds<br />

bit 7 GCEN: General Call Enable bit (when operating as I2C slave)<br />

1 = Enable interrupt when a general call address is received in the I2CRSR (module is enabled for reception)<br />

0 = General call address disabled<br />

bit 6 STREN: SCL Clock Stretch Enable bit (when operating as I2C slave)<br />

Used in conjunction with SCLREL bit.<br />

1 = Enable software or receive clock stretching<br />

0 = Disable software or receive clock stretching<br />

bit 5 ACKDT: Acknowledge Data bit (When operating as I2C Master. Applicable during master receive.)<br />

Value that will be transmitted when the software initiates an Acknowledge sequence.<br />

1 = Send NACK during acknowledge<br />

0 = Send ACK during acknowledge<br />

bit 4 ACKEN: Acknowledge Sequence Enable bit<br />

(When operating as I2C master. Applicable during master receive.)<br />

1 = Initiate Acknowledge sequence on SDA and SCL pins, and transmit ACKDT data bit<br />

Hardware clear at end of master Acknowledge sequence.<br />

0 = Acknowledge sequence not in progress<br />

bit 3 RCEN: Receive Enable bit (when operating as I2C master)<br />

1 = Enables Receive mo<strong>de</strong> for I2C<br />

Hardware clear at end eighth bit of master receive data byte.<br />

0 = Receive sequence not in progress<br />

bit 2 PEN: Stop Condition Enable bit (when operating as I2C master)<br />

1 = Initiate Stop condition on SDA and SCL pins<br />

Hardware clear at end of master Stop sequence.<br />

0 = Stop condition not in progress<br />

bit 1 RSEN: Repeated Start Condition Enabled bit (when operating as I2C master)<br />

1 = Initiate Repeated Start condition on SDA and SCL pins<br />

Hardware clear at end of master Repeated Start sequence.<br />

0 = Repeated Start condition not in progress<br />

bit 0 SEN: Start Condition Enabled bit (when operating as I2C master)<br />

1 = Initiate Start condition on SDA and SCL pins<br />

Hardware clear at end of master Start sequence.<br />

0 = Start condition not in progress<br />

M. <strong>Deloizy</strong> 158 dsPIC30F2023


I²C<br />

♦ I2CSTAT: I2C Status Register<br />

R-0<br />

HS, HC<br />

R-0<br />

HS, HC<br />

U-0 U-0 U-0 R/C-0<br />

HS<br />

R-0<br />

HS, HC<br />

R-0<br />

HS, HC<br />

ACKSTAT TRSTAT — — — BCL GCSTAT ADD10<br />

b15 b8<br />

R/C-0 R/W-0 R-0 R/C-0 R/C-0 R-0 R-0 R-0<br />

HS HS HS, HC HS, HC HS, HC HS, HC HS, HC HS, HC<br />

IWCOL I2COV D_A P S R_W RBF TBF<br />

b7 b0<br />

bit 15 ACKSTAT: Acknowledge Status bit (When operating as I2C master. Applicable to master transmit operation.)<br />

1= NACK received from slave<br />

0= ACK received from slave<br />

Hardware set or clear at end of slave Acknowledge.<br />

bit 14 TRSTAT: Transmit Status bit<br />

(When operating as I2C master. Applicable to master transmit operation.)<br />

1= Master transmit is in progress (8 bits + ACK)<br />

0= Master transmit is not in progress<br />

Hardware set at beginning of master transmission.<br />

Hardware clear at end of slave Acknowledge.<br />

bit 13-11 Unimplemented: Read as ‘0’<br />

bit 10 BCL: Master Bus Collision Detect bit<br />

1= A bus collision has been <strong>de</strong>tected during a master operation<br />

0= No collision<br />

Hardware set at <strong>de</strong>tection of bus collision.<br />

bit 9 GCSTAT: General Call Status bit<br />

1= General call address was received<br />

0= General call address was not received<br />

Hardware set when address matches general call address.<br />

Hardware clear at Stop <strong>de</strong>tection.<br />

bit 8 ADD10: 10-bit Address Status bit<br />

1 = 10-bit address was matched<br />

0 = 10-bit address was not matched<br />

Hardware set at match of 2nd byte of matched 10-bit address.<br />

M. <strong>Deloizy</strong> 159 dsPIC30F2023


I²C<br />

Hardware clear at Stop <strong>de</strong>tection.<br />

bit 7 IWCOL: Write Collision Detect bit<br />

1= An attempt to write the I2CTRN register failed because the I2C module is busy<br />

0= No collision<br />

Hardware set at occurrence of write to I2CTRN while busy (cleared by software).<br />

bit 6 I2COV: Receive Overflow Flag bit<br />

1= A byte was received while the I2CRCV register is still holding the previous byte<br />

0= No overflow<br />

Hardware set at attempt to transfer I2CRSR to I2CRCV (cleared by software).<br />

bit 5 D_A: Data/Address bit (when operating as I2C slave)<br />

1= Indicates that the last byte received was data<br />

0= Indicates that the last byte received was <strong>de</strong>vice address<br />

Hardware clear at <strong>de</strong>vice address match.<br />

Hardware set by write to I2CTRN or by reception of slave byte.<br />

bit 4 P: Stop bit<br />

1= Indicates that a Stop bit has been <strong>de</strong>tected last<br />

0= Stop bit was not <strong>de</strong>tected last<br />

Hardware set or clear when Start, Repeated Start or Stop <strong>de</strong>tected.<br />

bit 3 S: Start bit<br />

1= Indicates that a Start (or Repeated Start) bit has been <strong>de</strong>tected last<br />

0= Start bit was not <strong>de</strong>tected last<br />

Hardware set or clear when Start, Repeated Start or Stop <strong>de</strong>tected.<br />

bit 2 R_W: Read/Write bit Information (when operating as I2C slave)<br />

1= Read - indicates data transfer is output from slave<br />

0= Write - indicates data transfer is input to slave Hardware set or clear after reception of I2C <strong>de</strong>vice address byte.<br />

bit 1 RBF: Receive Buffer Full Status bit<br />

1 = Receive complete, I2CRCV is full<br />

0= Receive not complete, I2CRCV is empty<br />

Hardware set when I2CRCV written with received byte.<br />

Hardware clear when software reads I2CRCV.<br />

bit 0 TBF: Transmit Buffer Full Status bit<br />

1= Transmit in progress, I2CTRN is full<br />

0 = Transmit complete, I2CTRN is empty<br />

Hardware set when software writes I2CTRN.<br />

Hardware clear at completion of data transmission.<br />

M. <strong>Deloizy</strong> 160 dsPIC30F2023


♦ I2CRCV : Receive Register<br />

Reset State : 0000 0000 0000 0000<br />

♦ I2CTRN : Transmit Register<br />

Reset State : 0000 0000 1111 1111<br />

♦ I2CBRG : Baud Rate Generator<br />

Reset State : 0000 0000 0000 0000<br />

♦ I2CADD : Address Register<br />

Reset State : 0000 0000 0000 0000<br />

I²C<br />

M. <strong>Deloizy</strong> 161 dsPIC30F2023


Exemple <strong>de</strong> gestion (mo<strong>de</strong> maître)<br />

#<strong>de</strong>fine FREQI2C 1E5 // Fréquence bus I²C<br />

I²C<br />

#<strong>de</strong>fine TRIS_SCL _TRISG2<br />

#<strong>de</strong>fine TRIS_SDA _TRISG3<br />

// Gestion I2C<br />

#<strong>de</strong>fine ACK 0<br />

#<strong>de</strong>fine NACK 1<br />

#<strong>de</strong>fine WRITE 0<br />

#<strong>de</strong>fine READ 1<br />

#<strong>de</strong>fine I2CAD 0x40 // Adresse du périphérique I²C<br />

static void I2cMasterInit(void)<br />

{<br />

TRIS_SCL=1;<br />

TRIS_SDA=1;<br />

I2CBRG=(unsigned)(FCY/FREQI2C-FCY/1111111.-1+0.5);<br />

I2CCON=0x9040; // 1001 0000 0100 0000<br />

}<br />

M. <strong>Deloizy</strong> 162 dsPIC30F2023


static void I2cStart(void)<br />

{<br />

_SEN=1;<br />

while(_SEN);<br />

}<br />

I²C<br />

static void I2cRStart(void)<br />

{<br />

_RSEN=1;<br />

while(_RSEN);<br />

}<br />

static void I2cStop(void)<br />

{<br />

_PEN=1;<br />

while(_PEN);<br />

}<br />

M. <strong>Deloizy</strong> 163 dsPIC30F2023


I²C<br />

static unsigned char I2cMasterWrite(unsigned char b)<br />

{<br />

I2CTRN=b;<br />

while(_TRSTAT);<br />

return _ACKSTAT;<br />

}<br />

static unsigned char I2cMasterRead(unsigned char ack)<br />

{<br />

unsigned char x;<br />

_RCEN=1;<br />

while(_RCEN);<br />

x=I2CRCV;<br />

_ACKDT=ack;<br />

_ACKEN=1;<br />

while(_ACKEN);<br />

return x;<br />

}<br />

Exemple d’utilisation :<br />

I2cStart();<br />

while(I2cMasterWrite(I2CAD|WRITE)!=ACK) I2cRStart();<br />

I2cMasterWrite(0); // accès au registre d’adresse 0<br />

I2cRStart();<br />

I2cMasterWrite(I2CAD|READ);<br />

nb=I2cMasterRead(NACK);<br />

I2cStop();<br />

M. <strong>Deloizy</strong> 164 dsPIC30F2023


SPI<br />

IX Interface SPI<br />

IX.1 Registres<br />

♦ SPIxSTAT: SPIx STATUS AND <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

SPIEN — SPISIDL — — — — —<br />

b15 b8<br />

U-0 R/C-0 U-0 U-0 U-0 U-0 R-0 R-0<br />

— SPIROV — — — — SPITBF SPIRBF<br />

b7 b0<br />

bit 15 SPIEN: SPIx Enable bit<br />

1 = Enables module and configures SCKx, SDOx, SDIx and SSx as serial port pins<br />

0 = Disables module<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13 SPISIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1 = Discontinue module operation when <strong>de</strong>vice enters Idle mo<strong>de</strong><br />

0 = Continue module operation in Idle mo<strong>de</strong><br />

bit 12-7 Unimplemented: Read as ‘0’<br />

bit 6<br />

SPIROV: Receive Overflow Flag bit<br />

1 = A new byte/word is completely received and discar<strong>de</strong>d. The user software has not read the previous data in the SPIxBUF register.<br />

0 = No overflow has occurred<br />

bit 5-2 Unimplemented: Read as ‘0’<br />

bit 1 SPITBF: SPIx Transmit Buffer Full Status bit<br />

1 = Transmit not yet started, SPIxTXB is full<br />

0 = Transmit started, SPIxTXB is empty Automatically set in hardware when CPU writes SPIxBUF location, loading SPIxTXB.<br />

Automatically cleared in hardware when SPIx module transfers data from SPIxTXB to SPIxSR.<br />

bit 0 SPIRBF: SPIx Receive Buffer Full Status bit<br />

1 = Receive complete, SPIxRXB is full<br />

0 = Receive is not complete, SPIxRXB is empty Automatically set in hardware when SPIx transfers data from SPIxSR to SPIxRXB.<br />

Automatically cleared in hardware when core reads SPIxBUF location, reading SPIxRXB.<br />

M. <strong>Deloizy</strong> 165 dsPIC30F2023


SPI<br />

SPIXCON1: SPIx <strong>CONTROL</strong> <strong>REGISTER</strong> 1<br />

U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

— — — DISSCK DISSDO MODE16 SMP CKE(1)<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

SSEN CKP MSTEN SPRE PPRE<br />

b7 b0<br />

bit 15-13 Unimplemented: Read as ‘0’<br />

bit 12<br />

DISSCK: Disable SCKx pin bit (SPI Master mo<strong>de</strong>s only)<br />

1 = Internal SPI clock is disabled, pin functions as I/O<br />

0 = Internal SPI clock is enabled<br />

bit 11 DISSDO: Disable SDOx pin bit<br />

1 = SDOx pin is not used by module; pin functions as I/O<br />

0 = SDOx pin is controlled by the module<br />

bit 10<br />

MODE16: Word/Byte Communication Select bit<br />

1 = Communication is word-wi<strong>de</strong> (16 bits)<br />

0 = Communication is byte-wi<strong>de</strong> (8 bits)<br />

bit 9 SMP: SPIx Data Input Sample Phase bit<br />

Master mo<strong>de</strong>:<br />

1 = Input data sampled at end of data output time<br />

0 = Input data sampled at middle of data output time<br />

Slave mo<strong>de</strong>:<br />

SMP must be cleared when SPIx is used in Slave mo<strong>de</strong>.<br />

bit 8 CKE: SPIx Clock Edge Select bit(1)<br />

1 = Serial output data changes on transition from active clock state to Idle clock state (see bit 6)<br />

0 = Serial output data changes on transition from Idle clock state to active clock state (see bit 6)<br />

bit 7 SSEN: Slave Select Enable bit (Slave mo<strong>de</strong>)<br />

1 = SSx pin used for Slave mo<strong>de</strong><br />

0 = SSx pin not used by module. Pin controlled by port function.<br />

bit 6 CKP: Clock Polarity Select bit<br />

1 = Idle state for clock is a high level; active state is a low level<br />

0 = Idle state for clock is a low level; active state is a high level<br />

bit 5 MSTEN: Master Mo<strong>de</strong> Enable bit<br />

1 = Master mo<strong>de</strong><br />

0 = Slave mo<strong>de</strong><br />

M. <strong>Deloizy</strong> 166 dsPIC30F2023


SPI<br />

bit 4-2 SPRE: Secondary Prescale bits (Master mo<strong>de</strong>)<br />

111 = Secondary prescale 1:1<br />

110 = Secondary prescale 2:1<br />

...<br />

000 = Secondary prescale 8:1<br />

bit 1-0 PPRE: Primary Prescale bits (Master mo<strong>de</strong>)<br />

11 = Primary prescale 1:1<br />

10 = Primary prescale 4:1<br />

01 = Primary prescale 16:1<br />

00 = Primary prescale 64:1<br />

Note 1: The CKE bit is not used in the Framed SPI mo<strong>de</strong>s. The user should program this bit to ‘0’ for the Framed<br />

SPI mo<strong>de</strong>s (FRMEN = 1).<br />

♦ SPIxCON2: SPIx <strong>CONTROL</strong> <strong>REGISTER</strong> 2<br />

R/W-0 R/W-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

FRMEN SPIFSD FRMPOL — — — — —<br />

b15 b8<br />

U-0 U-0 U-0 U-0 U-0 U-0 R/W-0 U-0<br />

— — — — — — FRMDLY —<br />

b7 b0<br />

bit 15<br />

bit 14<br />

bit 13<br />

FRMEN: Framed SPIx Support bit<br />

1 = Framed SPIx support enabled (SSx pin used as frame sync pulse input/output)<br />

0 = Framed SPIx support disabled<br />

SPIFSD: Frame Sync Pulse Direction Control bit<br />

1 = Frame sync pulse input (slave)<br />

0 = Frame sync pulse output (master)<br />

FRMPOL: Frame Sync Pulse Polarity bit<br />

1 = Frame sync pulse is active-high<br />

0 = Frame sync pulse is active-low<br />

bit 12-2 Unimplemented: Read as ‘0’<br />

bit 1 FRMDLY: Frame Sync Pulse Edge Select bit<br />

1 = Frame sync pulse coinci<strong>de</strong>s with first bit clock<br />

0 = Frame sync pulse prece<strong>de</strong>s first bit clock<br />

bit 0 Unimplemented: This bit must not be set to ‘1’ by the user application.<br />

M. <strong>Deloizy</strong> 167 dsPIC30F2023


SPI<br />

♦ SPI1BUF : Transmit and Receive Buffer<br />

M. <strong>Deloizy</strong> 168 dsPIC30F2023


UART<br />

X UART<br />

X.1 Registres<br />

♦ U1MODE: UART1 MODE <strong>REGISTER</strong><br />

R/W-0 U-0 R/W-0 R/W-0 U-0 R/W-0 U-0 U-0<br />

UARTEN — USIDL IREN — ALTIO — —<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

HC<br />

HC<br />

WAKE LPBACK ABAUD RXINV BRGH PDSEL1 PDSEL0 STSEL<br />

b7 b0<br />

bit 15 UARTEN: UART1 Enable bit<br />

1 = UART1 enabled; all UART1 pins are controlled by UART1 as <strong>de</strong>fined by UEN<br />

0 = UART1 disabled; all UART1 pins are controlled by PORT latches; UART1 power consumption minimal<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13 USIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1 = Discontinue module operation when <strong>de</strong>vice enters Idle mo<strong>de</strong><br />

0 = Continue module operation in Idle mo<strong>de</strong><br />

bit 12 IREN: IrDA Enco<strong>de</strong>r and Deco<strong>de</strong>r Enable bit<br />

1 = IrDA enco<strong>de</strong>r and <strong>de</strong>co<strong>de</strong>r enabled<br />

0 = IrDA enco<strong>de</strong>r and <strong>de</strong>co<strong>de</strong>r disabled<br />

Note: This feature is only available for the 16x BRG mo<strong>de</strong> (BRGH = 0).<br />

bit 11 Unimplemented: Read as ‘0’<br />

bit 10<br />

ALTIO: UART Alternate I/O Selection bit<br />

1 = UART communicates using U1ATX and U1ARX I/O pins<br />

0 = UART communicates using U1TX and U1RX I/O pins.<br />

bit 9-8 Unimplemented: Read as ‘0’<br />

bit 7 WAKE: Wake-up on Start bit Detect During Sleep Mo<strong>de</strong> Enable bit<br />

1 = UART1 will continue to sample the U1RX pin; interrupt generated on falling edge, bit cleared in hardware on following rising edge<br />

0 = No wake-up enabled<br />

M. <strong>Deloizy</strong> 169 dsPIC30F2023


UART<br />

bit 6 LPBACK: UART1 Loopback Mo<strong>de</strong> Select bit<br />

1 = Enable Loopback mo<strong>de</strong><br />

0 = Loopback mo<strong>de</strong> is disabled<br />

bit 5 ABAUD: Auto-Baud Enable bit<br />

1 = Enable baud rate measurement on the next character – requires reception of a Sync field (55h); cleared in hardware upon<br />

completion<br />

0 = Baud rate measurement disabled or completed<br />

bit 4 RXINV: Receive Polarity Inversion bit<br />

1 = U1RX Idle state is ‘0’<br />

0 = U1RX Idle state is ‘1’<br />

bit 3 BRGH: High Baud Rate Enable bit<br />

1 = BRG generates 4 clocks per bit period (4x Baud Clock, High-Speed mo<strong>de</strong>)<br />

0 = BRG generates 16 clocks per bit period (16x Baud Clock, Standard mo<strong>de</strong>)<br />

bit 2-1 PDSEL1:PDSEL0: Parity and Data Selection bits<br />

11 = 9-bit data, no parity<br />

10 = 8-bit data, odd parity<br />

01 = 8-bit data, even parity<br />

00 = 8-bit data, no parity<br />

bit 0 STSEL: Stop Bit Selection bit<br />

1 = Two Stop bits<br />

0 = One Stop bit<br />

♦ U1STA: UART1 STATUS AND <strong>CONTROL</strong> <strong>REGISTER</strong><br />

R/W-0 R/W-0 R/W-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

UTXISEL1 UTXINV (1) UTXISEL0 — UTXBRK UTXEN UTXBF TRMT<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

URXISEL1 URXISEL0 ADDEN RIDLE PERR FERR OERR URXDA<br />

b7 b0<br />

bit 15, 13 UTXISEL1:UTXISEL0: Transmission Interrupt Mo<strong>de</strong> Selection bits<br />

11 =Reserved; do not use<br />

10 =Interrupt when a character is transferred to the Transmit Shift Register and as a result, the transmit buffer becomes empty<br />

01 =Interrupt when the last character is shifted out of the Transmit Shift Register; all transmit operations are completed<br />

00 =Interrupt when a character is transferred to the Transmit Shift Register (this implies there is at least one character open in the<br />

transmit buffer)<br />

M. <strong>Deloizy</strong> 170 dsPIC30F2023


UART<br />

bit 14 UTXINV: IrDA Enco<strong>de</strong>r Transmit Polarity Inversion bit (1)<br />

1 = IrDA enco<strong>de</strong>d U1TX idle state is ‘1’<br />

0 = IrDA enco<strong>de</strong>d U1TX idle state is ‘0’<br />

Note 1: Value of bit only affects the transmit properties of the module when the IrDA enco<strong>de</strong>r is enabled (IREN = 1).<br />

bit 12 Unimplemented: Read as ‘0’<br />

bit 11 UTXBRK: Transmit Break bit<br />

1 = Send Sync Break on next transmission – Start bit, followed by twelve ‘0’ bits, followed by Stop bit; cleared by hardware upon<br />

completion<br />

0 = Sync Break transmission disabled or completed<br />

bit 10 UTXEN: Transmit Enable bit<br />

1 = Transmit enabled, U1TX pin controlled by UART1<br />

0 = Transmit disabled, any pending transmission is aborted and buffer is reset. U1TX pin controlled by PORT.<br />

bit 9 UTXBF: Transmit Buffer Full Status bit (Read-Only)<br />

1 = Transmit buffer is full<br />

0 = Transmit buffer is not full, at least one more character can be written<br />

bit 8 TRMT: Transmit Shift Register Empty bit (Read-Only)<br />

1 = Transmit Shift Register is empty and transmit buffer is empty (the last transmission has completed)<br />

0 = Transmit Shift Register is not empty, a transmission is in progress or queued<br />

bit 7-6 URXISEL1:URXISEL0: Receive Interrupt Mo<strong>de</strong> Selection bits<br />

11 =Interrupt is set on RSR transfer, making the receive buffer full (i.e., has 4 data characters)<br />

10 =Interrupt is set on RSR transfer, making the receive buffer 3/4 full (i.e., has 3 data characters)<br />

0x =Interrupt is set when any character is received and transferred from the RSR to the receive buffer. Receive buffer has one or more<br />

characters.<br />

bit 5 ADDEN: Address Character Detect bit (bit 8 of received data = 1)<br />

1 = Address Detect mo<strong>de</strong> enabled. If 9-bit mo<strong>de</strong> is not selected, this does not take effect.<br />

0 = Address Detect mo<strong>de</strong> disabled<br />

bit 4 RIDLE: Receiver Idle bit (Read-Only)<br />

1 = Receiver is Idle<br />

0 = Receiver is active<br />

bit 3 PERR: Parity Error Status bit (Read-Only)<br />

1 = Parity error has been <strong>de</strong>tected for the current character (character at the top of the receive FIFO)<br />

0 = Parity error has not been <strong>de</strong>tected<br />

bit 2 FERR: Framing Error Status bit (Read-Only)<br />

1 = Framing error has been <strong>de</strong>tected for the current character (character at the top of the receive FIFO)<br />

0 = Framing error has not been <strong>de</strong>tected<br />

bit 1 OERR: Receive Buffer Overrun Error Status bit (Read/Clear-Only)<br />

1 = Receive buffer has overflowed<br />

0 = Receive buffer has not overflowed (clearing a previously set OERR bit (1 0transition) will reset the receiver buffer and the RSR to<br />

the empty state)<br />

bit 0 URXDA: Receive Buffer Data Available bit (Read-Only)<br />

1 = Receive buffer has data, at least one more character can be read<br />

0 = Receive buffer is empty<br />

M. <strong>Deloizy</strong> 171 dsPIC30F2023


♦ U1TXREG : UART Transmit Register<br />

UART<br />

♦ U1RXREG : UART Receive Register<br />

♦ U1BRG : Baud Rate Generator Prescaler<br />

M. <strong>Deloizy</strong> 172 dsPIC30F2023


Comparateur<br />

XI Module Comparateur<br />

XI.1 Schéma fonctionnel<br />

XI.2<br />

Registres<br />

♦ CMPCONx : COMPARATOR <strong>CONTROL</strong> <strong>REGISTER</strong>x (x=1,…4)<br />

R/W-0 U-0 R/W-0 U-0 U-0 U-0 U-0 U-0<br />

CMPON — CMPSIDL — — — — —<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 U-0 R/W-0 U-0 R/W-0 R/W-0<br />

INSEL EXTREF — CMPSTAT — CMPPOL RANGE<br />

b7 b0<br />

M. <strong>Deloizy</strong> 173 dsPIC30F2023


Comparateur<br />

bit 15 CMPON: A/D Operating Mo<strong>de</strong> bit<br />

1 = Comparator module is enabled<br />

0 = Comparator module is disabled (reduces power consumption)<br />

bit 14 Unimplemented: Read as ‘0’<br />

bit 13 CMPSIDL: Stop in Idle Mo<strong>de</strong> bit<br />

1 = Discontinue module operation when <strong>de</strong>vice enters Idle mo<strong>de</strong>.<br />

0 = Continue module operation in Idle mo<strong>de</strong>.<br />

If a <strong>de</strong>vice has multiple comparators, any CMPSIDL bit set to ‘1’ disables ALL comparators while in Idle mo<strong>de</strong>.<br />

bit 12-8 Reserved: Read as ‘0’<br />

bit 7-6 INSEL: Input Source Select for Comparator bits<br />

00 = Select CMPxA input pin<br />

01 = Select CMPxB input pin<br />

10 = Select CMPxC input pin<br />

11 = Select CMPxD input pin<br />

bit 5 EXTREF: Enable External Reference bit<br />

1 = External source provi<strong>de</strong>s reference to DAC<br />

0 = Internal reference sources provi<strong>de</strong> source to DAC<br />

bit 4 Reserved: Read as ‘0’<br />

bit 3 CMPSTAT: Current State of Comparator Output Including CMPPOL Selection bit<br />

bit 2 Reserved: Read as ‘0’<br />

bit 1<br />

bit 0<br />

CMPPOL: Comparator Output Polarity Control bit<br />

1 = Output is inverted<br />

0 = Output is non inverted<br />

RANGE: Selects DAC Output Voltage Range bit<br />

1 = High Range: Max DAC value = AVDD / 2, 2.5V @ 5 volt VDD<br />

0 = Low Range: Max DAC value = INTREF, 1.2V ±1%<br />

♦ CMPDACx : COMPARATOR DAC <strong>CONTROL</strong> <strong>REGISTER</strong>x (x=1,…4)<br />

U-0 U-0 U-0 U-0 U-0 U-0 R/W-0 R/W-0<br />

— — — — — — CMREF<br />

b15 b8<br />

R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0<br />

CMREF<br />

b7 b0<br />

bit 15-10 Reserved: Read as ‘0’<br />

M. <strong>Deloizy</strong> 174 dsPIC30F2023


it 9-0<br />

Comparateur<br />

These bits are reserved for possible future expansion of the DAC from 10 bits to more bits.<br />

CMREF: Comparator Reference Voltage Select bits<br />

1111111111 = (CMREF * INTREF/1024) or (CMREF * (AVDD/2)/1024) volts <strong>de</strong>pending on Range bit ·····<br />

0000000000 = 0.0 volts<br />

M. <strong>Deloizy</strong> 175 dsPIC30F2023


Compilateur C<br />

XII Compilateur C<br />

• MPLAB C30<br />

• ANSI x3.159-1989-compliant<br />

• GCC (<strong>Free</strong> Software Foundation)<br />

• Intégré dans MPLAB (version limitée, sans optimisation)<br />

• Extensions du langage pour le dsPIC<br />

• Bibliothèques pour le contrôle <strong>de</strong>s périphériques<br />

• Inclure <br />

XII.1 Types <strong>de</strong> données<br />

Utilisation du format “little endian” (poids faible en adresse basse)<br />

XII.1.a Types entiers<br />

Type Bits Min Max<br />

char, signed char 8 -128 127<br />

unsigned char 8 0 255<br />

short, signed short 16 -32768 32767<br />

unsigned short 16 0 65535<br />

int, signed int 16 -32768 32767<br />

unsigned int 16 0 65535<br />

long, signed long 32 -2 31 2 31 - 1<br />

M. <strong>Deloizy</strong> 176 dsPIC30F2023


Compilateur C<br />

unsigned long 32 0 2 32 - 1<br />

long long**, signed long long** 64 -2 63 2 63 - 1<br />

unsigned long long** 64 0 2 64 - 1<br />

XII.1.b Virgule flottante<br />

Type Bits E Min E Max N Min N Max<br />

float 32 -126 127 2 -126 2 128<br />

double* 32 -126 127 2 -126 2 128<br />

long double 64 -1022 1023 2 -1022 2 1024<br />

* double is equivalent to long double if -fno-short-double is used.<br />

XII.2 Extensions du langage<br />

XII.2.a Constantes binaires<br />

• Préfixe 0b ou 0B<br />

Exemple : x = 0b00001111 ; // x = 0x0F<br />

XII.2.b Fonctions inline<br />

Permet <strong>de</strong> définir une fonction en ligne (évite la transmission <strong>de</strong>s<br />

paramètres et l’appel <strong>de</strong> la fonction)<br />

Nécessite optimisation active ou option -finline<br />

Exemple :<br />

__inline__ int inc(int *a)<br />

{<br />

(*a)++;<br />

}<br />

M. <strong>Deloizy</strong> 177 dsPIC30F2023


Compilateur C<br />

XII.2.c Interruptions<br />

• Écriture <strong>de</strong> la fonction <strong>de</strong> gestion <strong>de</strong> l’interruption<br />

• Écriture du vecteur d’interruption<br />

• Fonctions « void »<br />

• Ne pas les appeler (exécutées automatiquement lors <strong>de</strong>s requêtes<br />

d’interruption)<br />

• Doivent être « rapi<strong>de</strong>s ». Éviter l’appel d’autres fonctions<br />

• Sauvegar<strong>de</strong> automatique <strong>de</strong>s registres utilisés et RCOUNT<br />

o Si appel <strong>de</strong> fonction : sauvegar<strong>de</strong> <strong>de</strong> tous les registres<br />

• Les interruptions sont interruptibles par défaut (voir le bit NSTDIS<br />

dans INTCON1, p 41)<br />

♦ Syntaxe :<br />

__attribute__((__interrupt__ [(<br />

[ __save__(symbol-list)] liste <strong>de</strong> variables à sauvegar<strong>de</strong>r et restituer<br />

[, irq(irqid)] spécification d’un vecteur d’interruption<br />

[, altirq(altirqid)] spécification d’un vecteur d’interruption alterné<br />

[, preprologue(asm)] insertion d’instr. ass. avant prologue routine interruption<br />

)]<br />

))<br />

Exemple :<br />

void __attribute__((__interrupt__(__save__(var1,var2)))) _INT0Interrupt(void);<br />

void __attribute__((__interrupt__(__irq__(52)))) MyIRQ(void);<br />

void __attribute__((__interrupt__(__preprologue__("inc _semaphore")))) isr0(void);<br />

M. <strong>Deloizy</strong> 178 dsPIC30F2023


Compilateur C<br />

♦ Utilisation <strong>de</strong> macros<br />

#<strong>de</strong>fine _ISR __attribute__((interrupt))<br />

#<strong>de</strong>fine _ISRFAST __attribute__((interrupt, shadow)) Utilisation <strong>de</strong> push.s, pop.s<br />

Exemple :<br />

void _ISR _INT0Interrupt(void);<br />

♦ Vecteurs d’interruption<br />

IRQ# Primary Name Alternate Name Vector Function<br />

N/A _ReservedTrap0 _AltReservedTrap0 Reserved<br />

N/A _OscillatorFail _AltOscillatorFail Oscillator fail trap<br />

N/A _AddressError _AltAddressError Address error trap<br />

N/A _StackError _AltStackError Stack error trap<br />

N/A _MathError _AltMathError Math error trap<br />

N/A _ReservedTrap5 _AltReservedTrap5 Reserved<br />

N/A _ReservedTrap6 _AltReservedTrap6 Reserved<br />

N/A _ReservedTrap7 _AltReservedTrap7 Reserved<br />

0 _INT0Interrupt _AltINT0Interrupt INT0 External interrupt 0<br />

1 _IC1Interrupt _AltIC1Interrupt IC1 Input capture 1<br />

2 _OC1Interrupt _AltOC1Interrupt OC1 Output compare 1<br />

3 _T1Interrupt _AltT1Interrupt TMR1 Timer 1 expired<br />

4 _Interrupt4 _AltInterrupt4 Reserved<br />

5 _OC2Interrupt _AltOC2Interrupt OC2 Output compare 2<br />

6 _T2Interrupt _AltT2Interrupt TMR2 Timer 2 expired<br />

7 _T3Interrupt _AltT3Interrupt TMR3 Timer 3 expired<br />

8 _SPI1Interrupt _AltSPI1Interrupt SPI1 Serial peripheral interface<br />

1<br />

9 _U1RXInterrupt _AltU1RXInterrupt UART1RX Uart 1 Receiver<br />

10 _U1TXInterrupt _AltU1TXInterrupt UART1TX Uart 1 Transmitter<br />

M. <strong>Deloizy</strong> 179 dsPIC30F2023


Compilateur C<br />

11 _ADCInterrupt _AltADCInterrupt ADC Convert completed<br />

12 _NVMInterrupt _AltNVMInterrupt NVM write completed<br />

13 _SI2CInterrupt _AltSI2CInterrupt Slave I2C interrupt<br />

14 _MI2CInterrupt _AltMI2CInterrupt Master I2C interrupt<br />

15 _Interrupt15 _AltInterrupt15 Reserved<br />

16 _INT1Interrupt _AltINT1Interrupt INT1 External interrupt 1<br />

17 _INT2Interrupt _AltINT2Interrupt INT2 External interrupt 2<br />

18 _<strong>PWM</strong>SpEventMatchInterrupt _Alt<strong>PWM</strong>SpEventMatchInterrupt <strong>PWM</strong> special event interrupt<br />

19 _<strong>PWM</strong>1Interrupt _Alt<strong>PWM</strong>1Interrupt <strong>PWM</strong> period match 1<br />

20 _<strong>PWM</strong>2Interrupt _Alt<strong>PWM</strong>2Interrupt <strong>PWM</strong> period match 2<br />

21 _<strong>PWM</strong>3Interrupt _Alt<strong>PWM</strong>3Interrupt <strong>PWM</strong> period match 3<br />

22 _<strong>PWM</strong>4Interrupt _Alt<strong>PWM</strong>4Interrupt <strong>PWM</strong> period match 4<br />

23 _Interrupt23 _AltInterrupt23 Reserved<br />

24 _Interrupt24 _AltInterrupt24 Reserved<br />

25 _Interrupt25 _AltInterrupt25 Reserved<br />

26 _Interrupt26 _AltInterrupt26 Reserved<br />

27 _CNInterrupt _AltCNInterrupt Input Change Notification<br />

28 _Interrupt28 _AltInterrupt28 Reserved<br />

29 _CMP1Interrupt _AltCMP1Interrupt Analog comparator interrupt 1<br />

30 _CMP2Interrupt _AltCMP2Interrupt Analog comparator interrupt 2<br />

31 _CMP3Interrupt _AltCMP3Interrupt Analog comparator interrupt 3<br />

32 _CMP4Interrupt _AltCMP4Interrupt Analog comparator interrupt 4<br />

33 _Interrupt33 _AltInterrupt33 Reserved<br />

34 _Interrupt34 _AltInterrupt34 Reserved<br />

35 _Interrupt35 _AltInterrupt35 Reserved<br />

36 _Interrupt36 _AltInterrupt36 Reserved<br />

37 _ADCP0Interrupt _AltADCP0Interrupt ADC Pair 0 conversion complete<br />

38 _ADCP1Interrupt _AltADCP1Interrupt ADC Pair 1 conversion complete<br />

39 _ADCP2Interrupt _AltADCP2Interrupt ADC Pair 2 conversion complete<br />

40 _ADCP3Interrupt _AltADCP3Interrupt ADC Pair 3 conversion complete<br />

M. <strong>Deloizy</strong> 180 dsPIC30F2023


Compilateur C<br />

41 _ADCP4Interrupt _AltADCP4Interrupt ADC Pair 4 conversion complete<br />

42 _ADCP5Interrupt _AltADCP5Interrupt ADC Pair 5 conversion complete<br />

43 _Interrupt43 _AltInterrupt43 Reserved<br />

44 _Interrupt44 _AltInterrupt44 Reserved<br />

45 _Interrupt45 _AltInterrupt45 Reserved<br />

46 _Interrupt46 _AltInterrupt46 Reserved<br />

47 _Interrupt47 _AltInterrupt47 Reserved<br />

48 _Interrupt48 _AltInterrupt48 Reserved<br />

49 _Interrupt49 _AltInterrupt49 Reserved<br />

50 _Interrupt50 _AltInterrupt50 Reserved<br />

51 _Interrupt51 _AltInterrupt51 Reserved<br />

52 _Interrupt52 _AltInterrupt52 Reserved<br />

53 _Interrupt53 _AltInterrupt53 Reserved<br />

♦ Routines par défaut<br />

Par défaut, si aucune routine d’interruption n’est déclarée, le compilateur<br />

installe un vecteur d’interruption sur une instruction RESET.<br />

On peut définir un gestionnaire par défaut en nommant une routine<br />

d’interruption : _DefaultInterrupt<br />

♦ Protection <strong>de</strong> zones<br />

On peut interdire les interruptions momentanément en utilisant les<br />

macros suivantes :<br />

SET_CPU_IPL(ipl)<br />

SET_AND_SAVE_CPU_IPL(save_to, ipl)<br />

RESTORE_CPU_IPL(saved_to)<br />

M. <strong>Deloizy</strong> 181 dsPIC30F2023


Compilateur C<br />

Exemple :<br />

int current_cpu_ipl;<br />

SET_AND_SAVE_CPU_IPL(current_cpu_ipl, 7); /* disable interrupts */<br />

/* protected co<strong>de</strong> here */<br />

RESTORE_CPU_IPL(current_cpu_ipl);<br />

XII.2.d Fonctions intrinsèques<br />

Permettent d’utiliser <strong>de</strong>s instructions assembleur sans recourir à<br />

l’assembleur en ligne.<br />

__builtin_addab __builtin_edac __builtin_mulsu __builtin_subab<br />

__builtin_add __builtin_fbcl __builtin_mulus __builtin_tblpage<br />

__builtin_btg __builtin_lac __builtin_muluu __builtin_tbloffset<br />

__builtin_clr __builtin_mac __builtin_nop __builtin_tblrdh<br />

__builtin_clr_prefetch __builtin_modsd __builtin_psvpage __builtin_tblrdl<br />

__builtin_divmodsd __builtin_modud __builtin_psvoffset __builtin_tblwth<br />

__builtin_divmodud __builtin_movsac __builtin_readsfr __builtin_tblwtl<br />

__builtin_divsd __builtin_mpy __builtin_return_address __builtin_write_NVM<br />

__builtin_divud __builtin_mpyn __builtin_sac __builtin_write_OSCCONL<br />

__builtin_dmaoffset __builtin_msc __builtin_sacr __builtin_write_OSCCON<br />

__builtin_ed __builtin_mulss __builtin_sftac<br />

Exemple :<br />

unsigned MulDiv(unsigned a, unsigned b, unsigned c)<br />

{<br />

unsigned long u;<br />

u=__builtin_muluu(a,b);<br />

return __builtin_divud(u,c);<br />

}<br />

M. <strong>Deloizy</strong> 182 dsPIC30F2023


Compilateur C<br />

XII.3 Exemple d’en-tête :<br />

#inclu<strong>de</strong> <br />

//--------------------------Device Configuration------------------------<br />

_FOSC(CSW_FSCM_OFF&OSC2_IO&FRC_HI_RANGE);<br />

_FOSCSEL(FRC_PLL);<br />

_FWDT(FWDTEN_OFF);<br />

_FPOR(PWRT_OFF);<br />

_FGS(CODE_PROT_OFF);<br />

_FICD( ICS_PGD2 ); //Utilise ICD2 sur EMUC1/EMUD1<br />

#<strong>de</strong>fine PLL 32<br />

#<strong>de</strong>fine FCY ((unsigned long)(14.55E6*PLL/16)) // FRC = 14.55 Mhz; PLLx16 -> 29.1 MIPS<br />

XII.4<br />

Définition <strong>de</strong>s bits<br />

/* SR */<br />

#<strong>de</strong>fine _C SRbits.C<br />

#<strong>de</strong>fine _Z SRbits.Z<br />

#<strong>de</strong>fine _OV SRbits.OV<br />

#<strong>de</strong>fine _N SRbits.N<br />

#<strong>de</strong>fine _RA SRbits.RA<br />

#<strong>de</strong>fine _IPL SRbits.IPL<br />

#<strong>de</strong>fine _DC SRbits.DC<br />

#<strong>de</strong>fine _DA SRbits.DA<br />

#<strong>de</strong>fine _SAB SRbits.SAB<br />

#<strong>de</strong>fine _OAB SRbits.OAB<br />

#<strong>de</strong>fine _SB SRbits.SB<br />

#<strong>de</strong>fine _SA SRbits.SA<br />

#<strong>de</strong>fine _OB SRbits.OB<br />

#<strong>de</strong>fine _OA SRbits.OA<br />

/* CORCON */<br />

#<strong>de</strong>fine _IF CORCONbits.IF<br />

#<strong>de</strong>fine _RND CORCONbits.RND<br />

#<strong>de</strong>fine _PSV CORCONbits.PSV<br />

#<strong>de</strong>fine _IPL3 CORCONbits.IPL3<br />

#<strong>de</strong>fine<br />

_ACCSAT CORCONbits.ACCSAT<br />

#<strong>de</strong>fine<br />

_SATDW CORCONbits.SATDW<br />

#<strong>de</strong>fine _SATB CORCONbits.SATB<br />

#<strong>de</strong>fine _SATA CORCONbits.SATA<br />

#<strong>de</strong>fine _DL CORCONbits.DL<br />

#<strong>de</strong>fine _EDT CORCONbits.EDT<br />

#<strong>de</strong>fine _US CORCONbits.US<br />

/* MODCON */<br />

#<strong>de</strong>fine _YMODEN MODCONbits.YMODEN<br />

#<strong>de</strong>fine _XMODEN MODCONbits.XMODEN<br />

/* XBREV */<br />

#<strong>de</strong>fine _XB XBREVbits.XB<br />

#<strong>de</strong>fine _BREN XBREVbits.BREN<br />

/* CNEN1 */<br />

#<strong>de</strong>fine _CN0IE CNEN1bits.CN0IE<br />

#<strong>de</strong>fine _CN1IE CNEN1bits.CN1IE<br />

#<strong>de</strong>fine _CN2IE CNEN1bits.CN2IE<br />

#<strong>de</strong>fine _CN3IE CNEN1bits.CN3IE<br />

#<strong>de</strong>fine _CN4IE CNEN1bits.CN4IE<br />

#<strong>de</strong>fine _CN5IE CNEN1bits.CN5IE<br />

#<strong>de</strong>fine _CN6IE CNEN1bits.CN6IE<br />

#<strong>de</strong>fine _CN7IE CNEN1bits.CN7IE<br />

/* CNPU1 */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_CN0PUE CNPU1bits.CN0PUE<br />

_CN1PUE CNPU1bits.CN1PUE<br />

_CN2PUE CNPU1bits.CN2PUE<br />

_CN3PUE CNPU1bits.CN3PUE<br />

_CN4PUE CNPU1bits.CN4PUE<br />

_CN5PUE CNPU1bits.CN5PUE<br />

_CN6PUE CNPU1bits.CN6PUE<br />

_CN7PUE CNPU1bits.CN7PUE<br />

/* INTCON1 */<br />

#<strong>de</strong>fine _OSCFAIL INTCON1bits.OSCFAIL<br />

#<strong>de</strong>fine<br />

_STKERR INTCON1bits.STKERR<br />

#<strong>de</strong>fine _ADDRERR INTCON1bits.ADDRERR<br />

#<strong>de</strong>fine _MATHERR INTCON1bits.MATHERR<br />

#<strong>de</strong>fine _DIV0ERR INTCON1bits.DIV0ERR<br />

#<strong>de</strong>fine _SFTACERR INTCON1bits.SFTACERR<br />

#<strong>de</strong>fine<br />

_COVTE INTCON1bits.COVTE<br />

#<strong>de</strong>fine<br />

_OVBTE INTCON1bits.OVBTE<br />

#<strong>de</strong>fine<br />

_OVATE INTCON1bits.OVATE<br />

#<strong>de</strong>fine _COVBERR INTCON1bits.COVBERR<br />

#<strong>de</strong>fine _COVAERR INTCON1bits.COVAERR<br />

#<strong>de</strong>fine _OVBERRINTCON1bits.OVBERR<br />

#<strong>de</strong>fine _OVAERR INTCON1bits.OVAERR<br />

#<strong>de</strong>fine<br />

_NSTDIS INTCON1bits.NSTDIS<br />

/* INTCON2 */<br />

#<strong>de</strong>fine<br />

_INT0EP INTCON2bits.INT0EP<br />

#<strong>de</strong>fine<br />

_INT1EP INTCON2bits.INT1EP<br />

#<strong>de</strong>fine<br />

_INT2EP INTCON2bits.INT2EP<br />

#<strong>de</strong>fine _DISI INTCON2bits.DISI<br />

#<strong>de</strong>fine<br />

_ALTIVT INTCON2bits.ALTIVT<br />

/* IFS0 */<br />

#<strong>de</strong>fine<br />

_INT0IF IFS0bits.INT0IF<br />

#<strong>de</strong>fine _IC1IF IFS0bits.IC1IF<br />

#<strong>de</strong>fine _OC1IF IFS0bits.OC1IF<br />

#<strong>de</strong>fine _T1IF IFS0bits.T1IF<br />

#<strong>de</strong>fine _OC2IF IFS0bits.OC2IF<br />

#<strong>de</strong>fine _T2IF IFS0bits.T2IF<br />

#<strong>de</strong>fine _T3IF IFS0bits.T3IF<br />

#<strong>de</strong>fine _SPI1IF IFS0bits.SPI1IF<br />

#<strong>de</strong>fine<br />

_U1RXIF IFS0bits.U1RXIF<br />

#<strong>de</strong>fine<br />

_U1TXIF IFS0bits.U1TXIF<br />

#<strong>de</strong>fine _ADIF IFS0bits.ADIF<br />

#<strong>de</strong>fine<br />

_NVMIF IFS0bits.NVMIF<br />

#<strong>de</strong>fine _SI2CIF IFS0bits.SI2CIF<br />

#<strong>de</strong>fine<br />

_MI2CIF IFS0bits.MI2CIF<br />

/* IFS1 */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_INT1IF IFS1bits.INT1IF<br />

_INT2IF IFS1bits.INT2IF<br />

_PSEMIF IFS1bits.PSEMIF<br />

_<strong>PWM</strong>1IF IFS1bits.<strong>PWM</strong>1IF<br />

_<strong>PWM</strong>2IF IFS1bits.<strong>PWM</strong>2IF<br />

_<strong>PWM</strong>3IF IFS1bits.<strong>PWM</strong>3IF<br />

M. <strong>Deloizy</strong> 183 dsPIC30F2023


#<strong>de</strong>fine<br />

_<strong>PWM</strong>4IF IFS1bits.<strong>PWM</strong>4IF<br />

#<strong>de</strong>fine _CNIF IFS1bits.CNIF<br />

#<strong>de</strong>fine _AC1IF IFS1bits.AC1IF<br />

#<strong>de</strong>fine _AC2IF IFS1bits.AC2IF<br />

#<strong>de</strong>fine _AC3IF IFS1bits.AC3IF<br />

/* IFS2 */<br />

#<strong>de</strong>fine _AC4IF IFS2bits.AC4IF<br />

#<strong>de</strong>fine _ADCP0IF IFS2bits.ADCP0IF<br />

#<strong>de</strong>fine _ADCP1IF IFS2bits.ADCP1IF<br />

#<strong>de</strong>fine _ADCP2IF IFS2bits.ADCP2IF<br />

#<strong>de</strong>fine _ADCP3IF IFS2bits.ADCP3IF<br />

#<strong>de</strong>fine _ADCP4IF IFS2bits.ADCP4IF<br />

#<strong>de</strong>fine _ADCP5IF IFS2bits.ADCP5IF<br />

/* IEC0 */<br />

#<strong>de</strong>fine<br />

_INT0IE IEC0bits.INT0IE<br />

#<strong>de</strong>fine _IC1IE IEC0bits.IC1IE<br />

#<strong>de</strong>fine _OC1IE IEC0bits.OC1IE<br />

#<strong>de</strong>fine _T1IE IEC0bits.T1IE<br />

#<strong>de</strong>fine _OC2IE IEC0bits.OC2IE<br />

#<strong>de</strong>fine _T2IE IEC0bits.T2IE<br />

#<strong>de</strong>fine _T3IE IEC0bits.T3IE<br />

#<strong>de</strong>fine _SPI1IE IEC0bits.SPI1IE<br />

#<strong>de</strong>fine<br />

_U1RXIE IEC0bits.U1RXIE<br />

#<strong>de</strong>fine<br />

_U1TXIE IEC0bits.U1TXIE<br />

#<strong>de</strong>fine _ADIE IEC0bits.ADIE<br />

#<strong>de</strong>fine<br />

_NVMIE IEC0bits.NVMIE<br />

#<strong>de</strong>fine _SI2CIE IEC0bits.SI2CIE<br />

#<strong>de</strong>fine<br />

_MI2CIE IEC0bits.MI2CIE<br />

/* IEC1 */<br />

#<strong>de</strong>fine<br />

_INT1IE IEC1bits.INT1IE<br />

#<strong>de</strong>fine<br />

_INT2IE IEC1bits.INT2IE<br />

#<strong>de</strong>fine<br />

_PSEMIE IEC1bits.PSEMIE<br />

#<strong>de</strong>fine<br />

_<strong>PWM</strong>1IE IEC1bits.<strong>PWM</strong>1IE<br />

#<strong>de</strong>fine<br />

_<strong>PWM</strong>2IE IEC1bits.<strong>PWM</strong>2IE<br />

#<strong>de</strong>fine<br />

_<strong>PWM</strong>3IE IEC1bits.<strong>PWM</strong>3IE<br />

#<strong>de</strong>fine<br />

_<strong>PWM</strong>4IE IEC1bits.<strong>PWM</strong>4IE<br />

#<strong>de</strong>fine _CNIE IEC1bits.CNIE<br />

#<strong>de</strong>fine _AC1IE IEC1bits.AC1IE<br />

#<strong>de</strong>fine _AC2IE IEC1bits.AC2IE<br />

#<strong>de</strong>fine _AC3IE IEC1bits.AC3IE<br />

/* IEC2 */<br />

#<strong>de</strong>fine _AC4IE IEC2bits.AC4IE<br />

#<strong>de</strong>fine _ADCP0IE IEC2bits.ADCP0IE<br />

#<strong>de</strong>fine _ADCP1IE IEC2bits.ADCP1IE<br />

#<strong>de</strong>fine _ADCP2IE IEC2bits.ADCP2IE<br />

#<strong>de</strong>fine _ADCP3IE IEC2bits.ADCP3IE<br />

#<strong>de</strong>fine _ADCP4IE IEC2bits.ADCP4IE<br />

#<strong>de</strong>fine _ADCP5IE IEC2bits.ADCP5IE<br />

/* IPC0 */<br />

#<strong>de</strong>fine<br />

_INT0IP IPC0bits.INT0IP<br />

#<strong>de</strong>fine _IC1IP IPC0bits.IC1IP<br />

#<strong>de</strong>fine _OC1IP IPC0bits.OC1IP<br />

#<strong>de</strong>fine _T1IP IPC0bits.T1IP<br />

/* IPC1 */<br />

#<strong>de</strong>fine _OC2IP IPC1bits.OC2IP<br />

#<strong>de</strong>fine _T2IP IPC1bits.T2IP<br />

Compilateur C<br />

#<strong>de</strong>fine _T3IP IPC1bits.T3IP<br />

/* IPC2 */<br />

#<strong>de</strong>fine _SPI1IP IPC2bits.SPI1IP<br />

#<strong>de</strong>fine<br />

_U1RXIP IPC2bits.U1RXIP<br />

#<strong>de</strong>fine<br />

_U1TXIP IPC2bits.U1TXIP<br />

#<strong>de</strong>fine _ADIP IPC2bits.ADIP<br />

/* IPC3 */<br />

#<strong>de</strong>fine<br />

_NVMIP IPC3bits.NVMIP<br />

#<strong>de</strong>fine _SI2CIP IPC3bits.SI2CIP<br />

#<strong>de</strong>fine<br />

_MI2CIP IPC3bits.MI2CIP<br />

/* IPC4 */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

/* IPC5 */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_INT1IP IPC4bits.INT1IP<br />

_INT2IP IPC4bits.INT2IP<br />

_PSEMIP IPC4bits.PSEMIP<br />

_<strong>PWM</strong>1IP IPC4bits.<strong>PWM</strong>1IP<br />

_<strong>PWM</strong>2IP IPC5bits.<strong>PWM</strong>2IP<br />

_<strong>PWM</strong>3IP IPC5bits.<strong>PWM</strong>3IP<br />

_<strong>PWM</strong>4IP IPC5bits.<strong>PWM</strong>4IP<br />

/* IPC6 */<br />

#<strong>de</strong>fine _CNIP IPC6bits.CNIP<br />

/* IPC7 */<br />

#<strong>de</strong>fine _AC1IP IPC7bits.AC1IP<br />

#<strong>de</strong>fine _AC2IP IPC7bits.AC2IP<br />

#<strong>de</strong>fine _AC3IP IPC7bits.AC3IP<br />

/* IPC8 */<br />

#<strong>de</strong>fine _AC4IP IPC8bits.AC4IP<br />

/* IPC9 */<br />

#<strong>de</strong>fine _ADCP0IP IPC9bits.ADCP0IP<br />

#<strong>de</strong>fine _ADCP1IP IPC9bits.ADCP1IP<br />

#<strong>de</strong>fine _ADCP2IP IPC9bits.ADCP2IP<br />

/* IPC10 */<br />

#<strong>de</strong>fine _ADCP3IP IPC10bits.ADCP3IP<br />

#<strong>de</strong>fine _ADCP4IP IPC10bits.ADCP4IP<br />

#<strong>de</strong>fine _ADCP5IP IPC10bits.ADCP5IP<br />

/* INTTREG */<br />

#<strong>de</strong>fine _VECNUM INTTREGbits.VECNUM<br />

#<strong>de</strong>fine _ILR INTTREGbits.ILR<br />

/* No unique SFR bit names for Timer Register Map */<br />

/*IC1CON */<br />

#<strong>de</strong>fine _ICBNE IC1CONbits.ICBNE<br />

#<strong>de</strong>fine _ICOV IC1CONbits.ICOV<br />

#<strong>de</strong>fine _ICTMR IC1CONbits.ICTMR<br />

#<strong>de</strong>fine<br />

_ICSIDL IC1CONbits.ICSIDL<br />

/* No unique SFR bit names for Output Compare Register Map */<br />

/* I2CCON: I2C Control Register */<br />

#<strong>de</strong>fine _SEN I2CCONbits.SEN<br />

#<strong>de</strong>fine _RSEN I2CCONbits.RSEN<br />

#<strong>de</strong>fine _PEN I2CCONbits.PEN<br />

#<strong>de</strong>fine _RCEN I2CCONbits.RCEN<br />

#<strong>de</strong>fine<br />

_ACKEN I2CCONbits.ACKEN<br />

#<strong>de</strong>fine<br />

_ACKDT I2CCONbits.ACKDT<br />

#<strong>de</strong>fine<br />

_STREN I2CCONbits.STREN<br />

#<strong>de</strong>fine _GCEN I2CCONbits.GCEN<br />

#<strong>de</strong>fine _SMEN I2CCONbits.SMEN<br />

#<strong>de</strong>fine<br />

_DISSLW I2CCONbits.DISSLW<br />

#<strong>de</strong>fine<br />

_IPMIEN I2CCONbits.IPMIEN<br />

#<strong>de</strong>fine<br />

_SCLREL I2CCONbits.SCLREL<br />

#<strong>de</strong>fine<br />

_I2CSIDL I2CCONbits.I2CSIDL<br />

#<strong>de</strong>fine _I2CEN I2CCONbits.I2CEN<br />

/* I2CSTAT Register*/<br />

#<strong>de</strong>fine _TBF I2CSTATbits.TBF<br />

#<strong>de</strong>fine _RBF I2CSTATbits.RBF<br />

#<strong>de</strong>fine _R_W I2CSTATbits.R_W<br />

#<strong>de</strong>fine _S I2CSTATbits.S<br />

#<strong>de</strong>fine _P I2CSTATbits.P<br />

#<strong>de</strong>fine _D_A I2CSTATbits.D_A<br />

#<strong>de</strong>fine _I2COV I2CSTATbits.I2COV<br />

#<strong>de</strong>fine<br />

_IWCOL I2CSTATbits.IWCOL<br />

#<strong>de</strong>fine<br />

_ADD10 I2CSTATbits.ADD10<br />

#<strong>de</strong>fine<br />

_GCSTAT I2CSTATbits.GCSTAT<br />

#<strong>de</strong>fine<br />

_TRSTAT I2CSTATbits.TRSTAT<br />

#<strong>de</strong>fine _ACKSTAT I2CSTATbits.ACKSTAT<br />

/* No unique SFR bit names for UART1 Register Map */<br />

/* SPI1 Register */<br />

#<strong>de</strong>fine<br />

_SPIRBF SPI1STAT.SPIRBF<br />

#<strong>de</strong>fine<br />

_SPITBF SPISTAT.SPITBF<br />

#<strong>de</strong>fine<br />

_SPIROV SPI1STAT.SPIROV<br />

#<strong>de</strong>fine<br />

_SPISIDL SPI1STAT.SPISIDL<br />

#<strong>de</strong>fine _SPIEN SPI1STAT.SPIEN<br />

/* TRISA */<br />

#<strong>de</strong>fine<br />

_TRISA8 TRISAbits.TRISA8<br />

#<strong>de</strong>fine<br />

_TRISA9 TRISAbits.TRISA9<br />

#<strong>de</strong>fine _TRISA10 TRISAbits.TRISA10<br />

#<strong>de</strong>fine _TRISA11 TRISAbits.TRISA11<br />

/* PORTA */<br />

#<strong>de</strong>fine _RA8 PORTAbits.RA8<br />

#<strong>de</strong>fine _RA9 PORTAbits.RA9<br />

#<strong>de</strong>fine _RA10 PORTAbits.RA10<br />

#<strong>de</strong>fine _RA11 PORTAbits.RA11<br />

/* LATA */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

/* TRISB */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_LATA8 LATAbits.LATA8<br />

_LATA9 LATAbits.LATA9<br />

_LATA10 LATAbits.LATA10<br />

_LATA11 LATAbits.LATA11<br />

_TRISB0 TRISBbits.TRISB0<br />

_TRISB1 TRISBbits.TRISB1<br />

_TRISB2 TRISBbits.TRISB2<br />

_TRISB3 TRISBbits.TRISB3<br />

_TRISB4 TRISBbits.TRISB4<br />

_TRISB5 TRISBbits.TRISB5<br />

_TRISB6 TRISBbits.TRISB6<br />

M. <strong>Deloizy</strong> 184 dsPIC30F2023


#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_TRISB7 TRISBbits.TRISB7<br />

_TRISB8 TRISBbits.TRISB8<br />

_TRISB9 TRISBbits.TRISB9<br />

_TRISB10 TRISBbits.TRISB10<br />

_TRISB11 TRISBbits.TRISB11<br />

/* PORTB */<br />

#<strong>de</strong>fine _RB0 PORTBbits.RB0<br />

#<strong>de</strong>fine _RB1 PORTBbits.RB1<br />

#<strong>de</strong>fine _RB2 PORTBbits.RB2<br />

#<strong>de</strong>fine _RB3 PORTBbits.RB3<br />

#<strong>de</strong>fine _RB4 PORTBbits.RB4<br />

#<strong>de</strong>fine _RB5 PORTBbits.RB5<br />

#<strong>de</strong>fine _RB6 PORTBbits.RB6<br />

#<strong>de</strong>fine _RB7 PORTBbits.RB7<br />

#<strong>de</strong>fine _RB8 PORTBbits.RB8<br />

#<strong>de</strong>fine _RB9 PORTBbits.RB9<br />

#<strong>de</strong>fine _RB10 PORTBbits.RB10<br />

#<strong>de</strong>fine _RB11 PORTBbits.RB11<br />

/* LATB */<br />

#<strong>de</strong>fine _LATB0 LATBbits.LATB0<br />

#<strong>de</strong>fine _LATB1 LATBbits.LATB1<br />

#<strong>de</strong>fine _LATB2 LATBbits.LATB2<br />

#<strong>de</strong>fine _LATB3 LATBbits.LATB3<br />

#<strong>de</strong>fine _LATB4 LATBbits.LATB4<br />

#<strong>de</strong>fine _LATB5 LATBbits.LATB5<br />

#<strong>de</strong>fine _LATB6 LATBbits.LATB6<br />

#<strong>de</strong>fine _LATB7 LATBbits.LATB7<br />

#<strong>de</strong>fine _LATB8 LATBbits.LATB8<br />

#<strong>de</strong>fine _LATB9 LATBbits.LATB9<br />

#<strong>de</strong>fine<br />

_LATB10 LATBbits.LATB10<br />

#<strong>de</strong>fine<br />

_LATB11 LATBbits.LATB11<br />

/* TRISD */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_TRISD0 TRISDbits.TRISD0<br />

_TRISD1 TRISDbits.TRISD1<br />

/* PORTD */<br />

#<strong>de</strong>fine _RD0 PORTDbits.RD0<br />

#<strong>de</strong>fine _RD1 PORTDbits.RD1<br />

/* LATD */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

/* TRISE */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_LATD0 LATDbits.LATD0<br />

_LATD1 LATDbits.LATD1<br />

_TRISE0 TRISEbits.TRISE0<br />

_TRISE1 TRISEbits.TRISE1<br />

_TRISE2 TRISEbits.TRISE2<br />

_TRISE3 TRISEbits.TRISE3<br />

_TRISE4 TRISEbits.TRISE4<br />

_TRISE5 TRISEbits.TRISE5<br />

_TRISE6 TRISEbits.TRISE6<br />

_TRISE7 TRISEbits.TRISE7<br />

/* PORTE */<br />

#<strong>de</strong>fine _RE0 PORTEbits.RE0<br />

#<strong>de</strong>fine _RE1 PORTEbits.RE1<br />

#<strong>de</strong>fine _RE2 PORTEbits.RE2<br />

#<strong>de</strong>fine _RE3 PORTEbits.RE3<br />

#<strong>de</strong>fine _RE4 PORTEbits.RE4<br />

Compilateur C<br />

#<strong>de</strong>fine _RE5 PORTEbits.RE5<br />

#<strong>de</strong>fine _RE6 PORTEbits.RE6<br />

#<strong>de</strong>fine _RE7 PORTEbits.RE7<br />

/* LATE */<br />

#<strong>de</strong>fine _LATE0 LATEbits.LATE0<br />

#<strong>de</strong>fine _LATE1 LATEbits.LATE1<br />

#<strong>de</strong>fine _LATE2 LATEbits.LATE2<br />

#<strong>de</strong>fine _LATE3 LATEbits.LATE3<br />

#<strong>de</strong>fine _LATE4 LATEbits.LATE4<br />

#<strong>de</strong>fine _LATE5 LATEbits.LATE5<br />

#<strong>de</strong>fine _LATE6 LATEbits.LATE6<br />

#<strong>de</strong>fine _LATE7 LATEbits.LATE7<br />

/* TRISF */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_TRISF2 TRISFbits.TRISF2<br />

_TRISF3 TRISFbits.TRISF3<br />

_TRISF6 TRISFbits.TRISF6<br />

_TRISF7 TRISFbits.TRISF7<br />

_TRISF8 TRISFbits.TRISF8<br />

_TRISF14 TRISFbits.TRISF14<br />

_TRISF15 TRISFbits.TRISF15<br />

/* PORTF */<br />

#<strong>de</strong>fine _RF2 PORTFbits.RF2<br />

#<strong>de</strong>fine _RF3 PORTFbits.RF3<br />

#<strong>de</strong>fine _RF6 PORTFbits.RF6<br />

#<strong>de</strong>fine _RF7 PORTFbits.RF7<br />

#<strong>de</strong>fine _RF8 PORTFbits.RF8<br />

#<strong>de</strong>fine _RF14 PORTFbits.RF14<br />

#<strong>de</strong>fine _RF15 PORTFbits.RF15<br />

/* LATF */<br />

#<strong>de</strong>fine _LATF2 LATFbits.LATF2<br />

#<strong>de</strong>fine _LATF3 LATFbits.LATF3<br />

#<strong>de</strong>fine _LATF6 LATFbits.LATF6<br />

#<strong>de</strong>fine _LATF7 LATFbits.LATF7<br />

#<strong>de</strong>fine _LATF8 LATFbits.LATF8<br />

#<strong>de</strong>fine<br />

_LATF14 LATFbits.LATF14<br />

#<strong>de</strong>fine<br />

_LATF15 LATFbits.LATF15<br />

/* TRISG */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_TRISG2 TRISGbits.TRISG2<br />

_TRISG3 TRISGbits.TRISG3<br />

/* PORTG */<br />

#<strong>de</strong>fine _RG2 PORTGbits.RG2<br />

#<strong>de</strong>fine _RG3 PORTGbits.RG3<br />

/* LATG */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_LATG2 LATGbits.LATG2<br />

_LATG3 LATGbits.LATG3<br />

/* ADCON */<br />

#<strong>de</strong>fine _ADCS ADCONbits.ADCS<br />

#<strong>de</strong>fine _SEQSAMP ADCONbits.SEQSAMP<br />

#<strong>de</strong>fine<br />

_ORDER ADCONbits.ORDER<br />

#<strong>de</strong>fine _EIE ADCONbits.EIE<br />

#<strong>de</strong>fine _FORM ADCONbits.FORM<br />

#<strong>de</strong>fine _GSWTRG ADCONbits.GSWTRG<br />

#<strong>de</strong>fine<br />

_ADSIDL ADCONbits.ADSIDL<br />

#<strong>de</strong>fine _ADON ADCONbits.ADON<br />

/* ADPCFG */<br />

#<strong>de</strong>fine _PCFG0 ADPCFGbits.PCFG0<br />

#<strong>de</strong>fine _PCFG1 ADPCFGbits.PCFG1<br />

#<strong>de</strong>fine _PCFG2 ADPCFGbits.PCFG2<br />

#<strong>de</strong>fine _PCFG3 ADPCFGbits.PCFG3<br />

#<strong>de</strong>fine _PCFG4 ADPCFGbits.PCFG4<br />

#<strong>de</strong>fine _PCFG5 ADPCFGbits.PCFG5<br />

#<strong>de</strong>fine _PCFG6 ADPCFGbits.PCFG6<br />

#<strong>de</strong>fine _PCFG7 ADPCFGbits.PCFG7<br />

#<strong>de</strong>fine _PCFG8 ADPCFGbits.PCFG8<br />

#<strong>de</strong>fine _PCFG9 ADPCFGbits.PCFG9<br />

#<strong>de</strong>fine<br />

_PCFG10 ADPCFGbits.PCFG10<br />

#<strong>de</strong>fine<br />

_PCFG11 ADPCFGbits.PCFG11<br />

/* PTCON */<br />

#<strong>de</strong>fine<br />

_SEVTPS PTCONbits.SEVTPS<br />

#<strong>de</strong>fine _SYNCSRC PTCONbits.SYNCSRC<br />

#<strong>de</strong>fine<br />

_SYNCEN PTCONbits.SYNCEN<br />

#<strong>de</strong>fine _SYNCOEN PTCONbits.SYNCOEN<br />

#<strong>de</strong>fine _SEIEN PTCONbits.SEIEN<br />

#<strong>de</strong>fine<br />

_PTSIDL PTCONbits.PTSIDL<br />

#<strong>de</strong>fine _PTEN PTCONbits.PTEN<br />

#<strong>de</strong>fine<br />

_SESTAT PTCONbits.SESTAT<br />

#<strong>de</strong>fine _SYNCPOL PTCONbits.SYNCPOL<br />

#<strong>de</strong>fine _EIPU PTCONbits.EIPU<br />

/* No unique SFR bit names for Analog Comparator Register Map */<br />

/* RCON */<br />

#<strong>de</strong>fine _POR RCONbits.POR<br />

#<strong>de</strong>fine _IDLE RCONbits.IDLE<br />

#<strong>de</strong>fine _SLEEP RCONbits.SLEEP<br />

#<strong>de</strong>fine _WDTO RCONbits.WDTO<br />

#<strong>de</strong>fine _SWDTEN RCONbits.SWDTEN<br />

#<strong>de</strong>fine _SWR RCONbits.SWR<br />

#<strong>de</strong>fine _EXTR RCONbits.EXTR<br />

#<strong>de</strong>fine _BGST RCONbits.BGST<br />

#<strong>de</strong>fine<br />

_IOPUWR RCONbits.IOPUWR<br />

#<strong>de</strong>fine<br />

_TRAPR RCONbits.TRAPR<br />

/* OSCCON */<br />

#<strong>de</strong>fine<br />

_OSWEN OSCCONbits.OSWEN<br />

#<strong>de</strong>fine<br />

_TSEQEN OSCCONbits.TSEQEN<br />

#<strong>de</strong>fine _CF OSCCONbits.CF<br />

#<strong>de</strong>fine<br />

_PRCDEN OSCCONbits.PRCDEN<br />

#<strong>de</strong>fine _LOCK OSCCONbits.LOCK<br />

#<strong>de</strong>fine _CLKLOCK OSCCONbits.CLKLOCK<br />

#<strong>de</strong>fine _NOSC OSCCONbits.NOSC<br />

#<strong>de</strong>fine _COSC OSCCONbits.COSC<br />

/* CLKDIV<br />

#<strong>de</strong>fine<br />

_DOZEN CLKDIV.DOZEN<br />

#<strong>de</strong>fine _DOZE CLKDIV.DOZE<br />

#<strong>de</strong>fine _ROI CLKDIV.ROI */<br />

/* NVMCON */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_SIZSEL NVMCONbits.SIZSEL<br />

_MEMSEL NVMCONbits.MEMSEL<br />

_SEGSEL NVMCONbits.SEGSEL<br />

M. <strong>Deloizy</strong> 185 dsPIC30F2023


#<strong>de</strong>fine<br />

_ERASE NVMCONbits.ERASE<br />

#<strong>de</strong>fine _TWRI NVMCONbits.TWRI<br />

#<strong>de</strong>fine<br />

_WRERR NVMCONbits.WRERR<br />

#<strong>de</strong>fine _WREN NVMCONbits.WREN<br />

#<strong>de</strong>fine _WR NVMCONbits.WR<br />

/* PMD1 */<br />

#<strong>de</strong>fine<br />

#<strong>de</strong>fine<br />

_ADCMD PMD1bits.ADCMD<br />

_SPI1MD PMD1bits.SPI1MD<br />

Compilateur C<br />

#<strong>de</strong>fine _U1MD PMD1bits.U1MD<br />

#<strong>de</strong>fine _I2CMD PMD1bits.I2CMD<br />

#<strong>de</strong>fine<br />

_<strong>PWM</strong>MD PMD1bits.<strong>PWM</strong>MD<br />

#<strong>de</strong>fine _T1MD PMD1bits.T1MD<br />

#<strong>de</strong>fine _T2MD PMD1bits.T2MD<br />

#<strong>de</strong>fine _T3MD PMD1bits.T3MD<br />

/* PMD2 */<br />

#<strong>de</strong>fine<br />

_OC1MD PMD2bits.OC1MD<br />

#<strong>de</strong>fine<br />

_OC2MD PMD2bits.OC2MD<br />

#<strong>de</strong>fine _IC1MD PMD2bits.IC1MD<br />

/* PMD3 */<br />

#<strong>de</strong>fine _CMP_PSMD PMD3bits.CMP_PSMD<br />

XII.5 Co<strong>de</strong> généré<br />

XII.5.a Registres utilisés<br />

• W0 … W13 : données<br />

• W14 : frame pointer<br />

• W15 : SP<br />

XII.5.b Appel <strong>de</strong> fonction<br />

• Registers W0-W7 are caller saved. The calling function must push these<br />

values onto the stack for the register values to be preserved.<br />

• Registers W8-W14 are callee saved. The function being called must save<br />

any of these registers it will modify.<br />

• Registers W0-W4 are used for function return values.<br />

• The first eight working registers (W0-W7) are used for function<br />

parameters.<br />

Data Type Number of Registers Required<br />

char 1<br />

int 1<br />

short 1<br />

M. <strong>Deloizy</strong> 186 dsPIC30F2023


Compilateur C<br />

pointer 1<br />

long 2 (contiguous – aligned to even numbered register)<br />

float 2 (contiguous – aligned to even numbered register)<br />

double* 2 (contiguous – aligned to even numbered register)<br />

long double 4 (contiguous – aligned to quad numbered register)<br />

structure 1 register per 2 bytes in structure<br />

• Return Value<br />

o W0 for 8- or 16-bit scalars<br />

o W1:W0 for 32-bit scalars<br />

o W3:W2:W1:W0 for 64-bit scalars.<br />

o Aggregates are returned indirectly through W0, which is set up by<br />

the function caller to contain the address of the aggregate value.<br />

XII.5.c Données constantes<br />

• Rangées dans section .const mappée dans la fenêtre définie par<br />

PSVPAG (p 23)<br />

• PSVPAG est initialisé par le compilateur<br />

M. <strong>Deloizy</strong> 187 dsPIC30F2023


XII.5.d Exemples<br />

♦ Observation du co<strong>de</strong><br />

int Add(int a, int b)<br />

{<br />

return a+b;<br />

}<br />

volatile int X;<br />

void main(void)<br />

{<br />

X=Add(3,4);<br />

if(X


♦ Constantes (<strong>de</strong>fine)<br />

#<strong>de</strong>fine PLL 32<br />

#<strong>de</strong>fine FCY ((unsigned long)(14.55E6*PLL/16))<br />

#<strong>de</strong>fine Fe 10000<br />

void InitT1(void)<br />

{<br />

PR1=FCY/Fe-1;<br />

mov #2909,w0<br />

mov w0,_PR1<br />

T1CONbits.TON=1;<br />

bset.b _T1CONbits+1,#7<br />

T1CON |= 0x8000;<br />

mov #-32768,w0<br />

ior _T1CON<br />

TMR1=PR1*0.5;<br />

mov _PR1,w8<br />

mul.su w8,#1,w0<br />

rcall ___floatsisf<br />

cp0 w8<br />

bra lt,.L5<br />

mov #0,w2<br />

mov #16128,w3<br />

rcall ___mulsf3<br />

rcall ___fixunssfsi<br />

mov w0,_TMR1<br />

TMR2=PR1/2;<br />

lsr _PR1,WREG<br />

mov w0,_TMR2<br />

PR2=(14.55E6*PLL/16)/1000;<br />

mov #29100,w0<br />

mov w0,_PR2<br />

}<br />

Compilateur C<br />

Notes :<br />

FCY = 29100000<br />

.L5:<br />

mov<br />

mov<br />

rcall<br />

mov<br />

mov<br />

rcall<br />

rcall<br />

mov<br />

#0,w2<br />

#18304,w3<br />

___addsf3<br />

#0,w2<br />

#16128,w3<br />

___mulsf3<br />

___fixunssfsi<br />

w0,_TMR1<br />

void InitT2(void)<br />

{<br />

TMR2=PR1/2;<br />

lsr _PR1,WREG<br />

mov w0,_TMR2<br />

PR2=(14.55E6*PLL/16)/1000;<br />

mov #29100,w0<br />

mov<br />

w0,_PR2<br />

}<br />

• Éviter l’écriture d’expressions en virgule flottante<br />

• On peut utiliser <strong>de</strong>s constantes en virgule flottante si elles ne sont pas<br />

utilisées conjointement avec <strong>de</strong>s variables.<br />

M. <strong>Deloizy</strong> 189 dsPIC30F2023


♦ Tableaux et constantes<br />

void Aff(const char *s);<br />

void aff1(void)<br />

{<br />

static const char<br />

}<br />

Aff(tbc);<br />

void aff2(void)<br />

{<br />

char tb[]="Hello";<br />

Aff(tb);<br />

}<br />

void aff3(void)<br />

{<br />

char *s="Coucou";<br />

Aff(s);<br />

}<br />

tbc[]= "Bonjour";<br />

Compilateur C<br />

_tbc.2480:<br />

.asciz "Bonjour"<br />

_aff1:<br />

mov #_tbc.2480,w0<br />

bra _Aff<br />

.LC0:<br />

.asciz "Hello"<br />

_aff2:<br />

lnk #6<br />

mov #.LC0,w0<br />

sub w15,#6,w1<br />

repeat #6-1<br />

mov.b [w0++],[w1++]<br />

sub #6, w1<br />

sub #6, w0<br />

mov w1,w0<br />

rcall _Aff<br />

ulnk<br />

return<br />

.LC1:<br />

.asciz "Coucou"<br />

_aff3:<br />

mov #.LC1,w0<br />

bra _Aff<br />

Prototype : ne génère pas <strong>de</strong> co<strong>de</strong><br />

static : définit la chaîne en RAM<br />

const ne suffit pas : la chaîne est définie en ROM, mais<br />

recopiée en RAM à chaque entrée dans la fonction (comme<br />

dans Aff2)<br />

L’utilisation d’un pointeur est efficace.<br />

M. <strong>Deloizy</strong> 190 dsPIC30F2023


Compilateur C<br />

♦ Manipulation <strong>de</strong> bits : macros<br />

#<strong>de</strong>fine BSET(b,x) ((x)|=(1


♦ Manipulation <strong>de</strong> bits : unions<br />

type<strong>de</strong>f union<br />

{<br />

unsigned w;<br />

struct { char lsb,msb; } B;<br />

struct {<br />

unsigned b0:1;<br />

unsigned :3;<br />

unsigned b4_7:4;<br />

unsigned b8_9:2;<br />

unsigned b10_15:6;<br />

} b;<br />

}T_B;<br />

Compilateur C<br />

_x.2517: .space 2<br />

void Bits2(void)<br />

{<br />

static volatile T_B x={0};<br />

x.b.b0=1;<br />

bset.b _x.2517,#0<br />

x.b.b4_7=5;<br />

mov.b _x.2517,WREG<br />

and.b w0,#15,w0 15=0x0F<br />

ior.b #80,w0 80=0x50<br />

mov.b WREG,_x.2517<br />

x.B.msb++;<br />

inc.b<br />

x.w--;<br />

<strong>de</strong>c<br />

_x.2517+1<br />

_x.2517<br />

}<br />

• Privilégier l’utilisation d’unions :<br />

o Lisibilité<br />

o Souplesse<br />

o Portabilité<br />

o Génération <strong>de</strong> co<strong>de</strong> efficace.<br />

M. <strong>Deloizy</strong> 192 dsPIC30F2023


♦ Interruptions<br />

static unsigned CTITT1=0;<br />

_CTITT1: .space 2<br />

void __attribute__((interrupt,no_auto_psv)) _T1Interrupt(void)<br />

{ _T1IF =0; //met à zéro le flag d'interruption<br />

bclr.b _IFS0bits,#3<br />

inc<br />

retfie<br />

}<br />

CTITT1++;<br />

_CTITT1<br />

Remarque : si auto_psv est utilisé, le registre PSVPAG est sauvegardé.<br />

static unsigned CTITT2=0;<br />

_CTITT2: .space 2<br />

void __attribute__((interrupt,no_auto_psv)) _T2Interrupt(void)<br />

push _RCOUNT<br />

mov.d w0,[w15++]<br />

mov.d w2,[w15++]<br />

mov.d w4,[w15++]<br />

mov.d w6,[w15++]<br />

lnk #0<br />

{ _T2IF =0; //met à zéro le flag d'interruption<br />

bclr.b _IFS0bits,#6<br />

CTITT2++;<br />

inc _CTITT2<br />

Aff("xxx");<br />

mov #.LC2,w0<br />

rcall _Aff<br />

mov.d [--w15],w6<br />

mov.d [--w15],w4<br />

mov.d [--w15],w2<br />

mov.d [--w15],w0<br />

pop _RCOUNT<br />

retfie<br />

}<br />

Compilateur C<br />

M. <strong>Deloizy</strong> 193 dsPIC30F2023


Travaux pratiques<br />

XIII Travaux Pratiques<br />

Voir le schéma <strong>de</strong> la maquette <strong>de</strong> TP p 197<br />

XIII.1 Séances 1 & 2 :<br />

♦ Étu<strong>de</strong> <strong>de</strong> l’environnement <strong>de</strong> développement du dsPIC (MPLAB et<br />

compilateur C30) :<br />

• Utiliser d’abord le simulateur.<br />

• Mettre <strong>de</strong>s points d’arrêt, observer les données, les temps d’exécution.<br />

• Télécharger et exécuter les programmes via l’ICD2.<br />

Visualiser à l’oscilloscope les durées d’exécution.<br />

♦ Affichage séquentiel <strong>de</strong> chiffres (0 à 9) sur un afficheur 7 segments.<br />

• Utiliser d’abord une temporisation logicielle<br />

• Utiliser ensuite le Timer 1 pour contrôler le temps avec une résolution<br />

d’une millisecon<strong>de</strong>.<br />

• Effectuer le comptage <strong>de</strong> 0 à 9 sur l’afficheur entièrement piloté par<br />

l’interruption. La pério<strong>de</strong> <strong>de</strong> comptage sera <strong>de</strong> ½ secon<strong>de</strong>.<br />

M. <strong>Deloizy</strong> 194 dsPIC30F2023


Travaux pratiques<br />

♦ Utilisation <strong>de</strong>s 3 afficheurs<br />

• Gérer le multiplexage <strong>de</strong>s 3 afficheurs dans la routine d’interruption.<br />

On affiche la valeur numérique contenue dans un tableau (global) <strong>de</strong> 3<br />

caractères.<br />

• Afficher un compteur <strong>de</strong> 000 à 999 qui s’incrémente tous les 1/10<br />

secon<strong>de</strong>s.<br />

XIII.2 Séances 3 & 4:<br />

♦ Conversion analogique<br />

• Mesurer la tension analogique présente sur le capteur <strong>de</strong> température<br />

LM335 (10mV/°K).<br />

Afficher la valeur <strong>de</strong> la température avec une décimale :<br />

o Sur les afficheurs 7 segments<br />

o Sur l’afficheur LCD<br />

Quelle est la précision <strong>de</strong> cette mesure (liée au convertisseur<br />

analogique numérique) <br />

♦ Capture-Compare<br />

• Afficher la distance mesurée avec le capteur à ultrasons située sur la<br />

maquette <strong>de</strong> TP.<br />

M. <strong>Deloizy</strong> 195 dsPIC30F2023


Travaux pratiques<br />

♦ <strong>PWM</strong><br />

• Générer les signaux <strong>PWM</strong> suivants :<br />

o Fréquence 5 KHz – Rapports cycliques 10%, 50% et 80%.<br />

o Fréquence 100 KHz – Rapports cycliques 10%, 50% et 80%.<br />

Les visualiser à l’oscilloscope<br />

• Réaliser la comman<strong>de</strong> <strong>PWM</strong> <strong>de</strong> 2 moteurs pour le pilotage <strong>de</strong> robots<br />

avec les consignes vitesse et direction.<br />

La fréquence <strong>de</strong> hachage sera choisie entre 8kHz et 15kHz.<br />

• Intégrer une limitation <strong>de</strong> la dynamique <strong>de</strong> comman<strong>de</strong> par la création<br />

<strong>de</strong> rampes d’accélération (voir p 216).<br />

XIII.3 Séance 5 : I²C<br />

Voir les documentations p 229<br />

• Générer un signal périodique sur le convertisseur numérique<br />

analogique<br />

o Observer les signaux du bus à l’oscilloscope.<br />

• Programmer l’horloge temps réel.<br />

o Afficher l’heure en continu avec le format HH :mm :ss<br />

M. <strong>Deloizy</strong> 196 dsPIC30F2023


XIII.4 Maquette <strong>de</strong> TP<br />

XIII.4.a Schéma électronique<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 197 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong><br />

198<br />

dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 199 dsPIC30F2023


XIII.4.b Implantation <strong>de</strong>s composants<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 200 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong><br />

201<br />

dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 202 dsPIC30F2023


XIII.4.c Interface<br />

♦ Face avant<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 203 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 204 dsPIC30F2023


♦ Implantation <strong>de</strong>s composants<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 205 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 206 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 207 dsPIC30F2023


♦ Schéma électronique (1)<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 208 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong><br />

209<br />

dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 210 dsPIC30F2023


♦ Schéma électronique (2) – I²C<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 211 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong><br />

212<br />

dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong> 213 dsPIC30F2023


XIII.4.d Hacheur (comman<strong>de</strong> <strong>de</strong>s moteurs)<br />

Travaux pratiques<br />

M. <strong>Deloizy</strong> 214 dsPIC30F2023


Travaux pratiques<br />

M. <strong>Deloizy</strong><br />

215<br />

dsPIC30F2023


Travaux pratiques<br />

XIV<br />

XIV.1<br />

ANNEXE : Rampes d’accélération<br />

Limiteur d'accélération pour la comman<strong>de</strong> <strong>de</strong> moteur<br />

→ limitation du couple d'accélération<br />

→ limitation <strong>de</strong>s courants<br />

v k : vitesse souhaitée<br />

v<br />

v' k : vitesse obtenue<br />

k<br />

DT : pério<strong>de</strong> d'échantillonnage<br />

Accéléra<br />

v' k<br />

v k<br />

v k 1<br />

DT<br />

dv M<br />

M. <strong>Deloizy</strong> 216 dsPIC30F2023


ANNEXES<br />

Exemple :<br />

Fréquence <strong>de</strong> hachage = 10kHz<br />

v max = 254<br />

accélération arrêt / pleine vitesse en 1mn (dv=127 en 60s)<br />

⇒ DT = 0,1 ms et dv MAX = 212.10 -6<br />

v codé sur 1 octet (0 à 255)<br />

v 00<br />

→ peut être codé sur 32 bits en multipliant H 00 H 00 H<br />

par 2 24 :<br />

On note V = v.2 24<br />

V<br />

⇒ DV MAX = dv MAX .2 24 = 212.10 -6 .16777216 ≈ 3551<br />

Dans le bloc limiteur d'accélération, on travaille avec V et DV :<br />

M. <strong>Deloizy</strong> 217 dsPIC30F2023


ANNEXES<br />

(exemple pour la limitation en vitesse croissante)<br />

consigne v k ⇒ V k<br />

si V k > V k-1 + DV max<br />

V k = V k-1 + DV max<br />

extraction <strong>de</strong> v' k à partir <strong>de</strong> V k ⇒ application <strong>de</strong> la nouvelle comman<strong>de</strong><br />

Rem. : V k-1 : valeur précé<strong>de</strong>nte <strong>de</strong> V k → utilisation d'une variable statique.<br />

M. <strong>Deloizy</strong> 218 dsPIC30F2023


XV ANNEXE : BUS I²C<br />

XV.1<br />

Description<br />

ANNEXES<br />

• Développé initialement par Philips<br />

• Bus <strong>de</strong> type série synchrone<br />

o Bidirectionnel<br />

o Multi maîtres<br />

o Multi points<br />

o Chaque point a une adresse<br />

• 2 fils (+ GND) :<br />

o SDA : données<br />

o SCL : horloge<br />

• Lignes bidirectionnelles<br />

o Collecteur ouvert (nécessite une résistance <strong>de</strong> tirage)<br />

o Au repos : état haut<br />

M. <strong>Deloizy</strong> 219 dsPIC30F2023


• Vitesse :<br />

ANNEXES<br />

o standard : 100 kbits/s<br />

o rapi<strong>de</strong> (fast) : 400 kbits/s<br />

o très rapi<strong>de</strong> (high speed) : 3,4 Mbits/s<br />

• Versions :<br />

o 1.0 (1992) :<br />

• suppression <strong>de</strong> la possibilité <strong>de</strong> programmer l’adresse d’un<br />

point<br />

• mo<strong>de</strong> fast ajouté<br />

• format d’adresse sur 10 bits ajouté<br />

o 2.0 (1998) :<br />

• mo<strong>de</strong> high speed (Hs-mo<strong>de</strong>) ajouté<br />

• adaptation pour dispositifs alimentés en 2 volts<br />

o 2.1 (2000) :<br />

• modification <strong>de</strong>s timings du mo<strong>de</strong> Hs<br />

M. <strong>Deloizy</strong> 220 dsPIC30F2023


XV.2 Spécifications<br />

• SDA doit être stable quand SCL=1<br />

SDA peut changer quand SCL=0<br />

ANNEXES<br />

M. <strong>Deloizy</strong> 221 dsPIC30F2023


ANNEXES<br />

• Début <strong>de</strong> message : START (S)<br />

o Front <strong>de</strong>scendant sur SDA quand SCL=1<br />

• Fin <strong>de</strong> message : STOP (P)<br />

o Front montant <strong>de</strong> SDA quand SCL=1<br />

• START et STOP sont générés par le maître<br />

o START ⇒ bus occupé<br />

o STOP ⇒ bus <strong>de</strong>vient libre (après un délai)<br />

XV.3 Transfert <strong>de</strong>s données<br />

• Par octet<br />

• 8 bits transmis (b7 en tête), puis bit acknowledge (ACK)<br />

• ACK :<br />

o L’émetteur met la ligne SDA à 1<br />

o Le récepteur met la ligne SDA à 0<br />

o Le maître génère l’impulsion d’horloge<br />

o Si un esclave souhaite marquer une pause (gestion interne), il peut<br />

forcer SCL à 0 pour forcer le maître à attendre<br />

M. <strong>Deloizy</strong> 222 dsPIC30F2023


ANNEXES<br />

o Si un esclave ne génère pas ACK sur son adresse (par ex. s’il est<br />

occupé), ACK doit rester à 1.<br />

Le maître peut alors générer :<br />

• Un STOP (fin du transfert)<br />

• Un START (nouveau transfert)<br />

o Si un esclave génère un ACK sur son adresse, puis sur les données<br />

suivantes et qu’à un instant donné il cesse <strong>de</strong> générer ACK : le<br />

maître doit cesser le transfert<br />

• possibilité transmission plusieurs octets (bit ACK toujours présent)<br />

Transfert <strong>de</strong> données sur le bus<br />

ACK sur le bus<br />

M. <strong>Deloizy</strong> 223 dsPIC30F2023


ANNEXES<br />

Transfert <strong>de</strong> données complet<br />

XV.4 Format avec adresse sur 7 bits<br />

• Chaque point a une adresse propre sur 7 bits<br />

• Le maître envoie :<br />

o START<br />

o L’adresse <strong>de</strong> l’esclave sur 7 bits (b6 en tête)<br />

o Le sens du transfert sur 1 bit (R/W)<br />

• L’esclave doit générer ACK<br />

M. <strong>Deloizy</strong> 224 dsPIC30F2023


ANNEXES<br />

• Les données sont transférées (terminées par ACK, sauf éventuellement<br />

la <strong>de</strong>rnière)<br />

• Le maître envoie STOP<br />

Émission <strong>de</strong> données du maître vers un esclave<br />

Réception <strong>de</strong> données <strong>de</strong> l’esclave vers le maître<br />

Format combiné<br />

(Lectures / écritures successives)<br />

M. <strong>Deloizy</strong> 225 dsPIC30F2023


XV.5<br />

Chronogrammes<br />

ANNEXES<br />

PARAMETER SYMBOL STANDARD-MODE FAST-MODE UNIT<br />

MIN. MAX. MIN. MAX.<br />

SCL clock frequency fSCL 0 100 0 400 kHz<br />

Hold time (repeated) START condition. After this period, the first clock pulse is generated tHD;STA 4.0 – 0.6 - ms<br />

LOW period of the SCL clock tLOW 4.7 – 1.3 – ms<br />

HIGH period of the SCL clock tHIGH 4.0 – 0.6 – ms<br />

Set-up time for a repeated START condition<br />

tSU;STA 4.7 – 0.6 – ms<br />

Data hold time:<br />

tHD;DAT<br />

for CBUS compatible masters<br />

for I2C-bus <strong>de</strong>vices<br />

5.0<br />

0(2)<br />

–<br />

3.45(3)<br />

–<br />

0(2)<br />

–<br />

0.9(3)<br />

ms<br />

ms<br />

Data set-up time tSU;DAT 250 - 100(4) – ns<br />

Rise time of both SDA and SCL signals tr – 1000 20 + 0.1Cb(5) 300 ns<br />

Fall time of both SDA and SCL signals tf – 300 20 + 0.1Cb(5) 300 ns<br />

Set-up time for STOP condition tSU;STO 4.0 – 0.6 – ms<br />

Bus free time between a STOP and START condition<br />

tBUF 4.7 – 1.3 – ms<br />

Capacitive load for each bus line Cb – 400 – 400 pF<br />

Noise margin at the LOW level for each connected <strong>de</strong>vice (including hysteresis)<br />

VnL 0.1VDD – 0.1VDD – V<br />

M. <strong>Deloizy</strong> 226 dsPIC30F2023


Noise margin at the HIGH level for each connected <strong>de</strong>vice (including hysteresis)<br />

ANNEXES<br />

VnH 0.2VDD – 0.2VDD – V<br />

1. All values referred to VIHmin and VILmax levels (see Table 4).<br />

2. A <strong>de</strong>vice must internally provi<strong>de</strong> a hold time of at least 300 ns for the<br />

SDA signal (referred to the VIHmin of the SCL signal) to bridge the<br />

un<strong>de</strong>fined region of the falling edge of SCL.<br />

3. The maximum tHD;DAT has only to be met if the <strong>de</strong>vice does not stretch<br />

the LOW period (tLOW) of the SCL signal.<br />

4. A Fast-mo<strong>de</strong> I2C-bus <strong>de</strong>vice can be used in a Standard-mo<strong>de</strong> I2C-bus<br />

system, but the requirement tSU;DAT ³ 250 ns must then be met. This will<br />

automatically be the case if the <strong>de</strong>vice does not stretch the LOW period of<br />

the SCL signal.<br />

If such a <strong>de</strong>vice does stretch the LOW period of the SCL signal, it must<br />

output the next data bit to the SDA line tr max + tSU;DAT = 1000 + 250 =<br />

1250 ns (according to the Standard-mo<strong>de</strong> I2C-bus specification) before the<br />

SCL line is released.<br />

5. Cb = total capacitance of one bus line in pF. If mixed with Hs-mo<strong>de</strong><br />

<strong>de</strong>vices, faster fall-times according to Table 6 are allowed.<br />

M. <strong>Deloizy</strong> 227 dsPIC30F2023


XV.6<br />

Mise en œuvre<br />

ANNEXES<br />

unsigned char I2cInit(void);<br />

• Initialisation du bus I²C<br />

void I2cStart(void);<br />

• Génère START sur le bus I²C<br />

unsigned char I2cMasterWrite(unsigned char x);<br />

• Émission <strong>de</strong> x sur le bus I²C<br />

• Renvoie 1 si ACK reçu, 0 sinon<br />

unsigned char I2cMasterRead(unsigned char ack) ;<br />

• Réception d’un octet sur le bus I²C<br />

• ack : état <strong>de</strong> ACK à générer après la réception <strong>de</strong> l’octet (0 : ACK, 1 :<br />

NOACK)<br />

• Renvoie l’octet reçu<br />

M. <strong>Deloizy</strong> 228 dsPIC30F2023


ANNEXES<br />

unsigned char I2cStop(void);<br />

• Génère STOP sur le bus I²C<br />

• Renvoie 0 si Ok, 1 sinon (SCL maintenue à 0 par )<br />

XV.7 Documentations<br />

XV.7.a RTC PCF8563<br />

The PCF8563 contains sixteen 8-bit registers with an auto-incrementing<br />

address register, an on-chip 32.768 kHz oscillator with one integrated<br />

capacitor, a frequency divi<strong>de</strong>r which provi<strong>de</strong>s the source clock for the<br />

M. <strong>Deloizy</strong> 229 dsPIC30F2023


ANNEXES<br />

Real Time Clock/calen<strong>de</strong>r (RTC), a programmable clock output, a timer,<br />

an alarm, a voltage-low <strong>de</strong>tector and a 400 kHz I2C-bus interface.<br />

All 16 registers are <strong>de</strong>signed as addressable 8-bit parallel registers<br />

although not all bits are implemented. The first two registers (memory<br />

address 00H and 01H) are used as control and/or status registers. The<br />

memory addresses 02H through 08H are used as counters for the clock<br />

function (seconds up to years counters). Address locations 09H through<br />

0CH contain alarm registers which <strong>de</strong>fine the conditions for an alarm.<br />

Address 0DH controls the CLKOUT output frequency. 0EH and 0FH are<br />

the timer control and timer registers, respectively.<br />

The seconds, minutes, hours, days, weekdays, months, years as well as the<br />

minute alarm, hour alarm, day alarm and weekday alarm registers are all<br />

co<strong>de</strong>d in BCD format.<br />

When one of the RTC registers is read the contents of all counters are<br />

frozen. Therefore, faulty reading of the clock/calendar during a carry<br />

condition is prevented.<br />

M. <strong>Deloizy</strong> 230 dsPIC30F2023


ANNEXES<br />

M. <strong>Deloizy</strong> 231 dsPIC30F2023


ANNEXES<br />

M. <strong>Deloizy</strong> 232 dsPIC30F2023


ANNEXES<br />

M. <strong>Deloizy</strong> 233 dsPIC30F2023


ANNEXES<br />

M. <strong>Deloizy</strong> 234 dsPIC30F2023


ANNEXES<br />

♦ Master transmits to slave receiver (write mo<strong>de</strong>) :<br />

M. <strong>Deloizy</strong> 235 dsPIC30F2023


ANNEXES<br />

♦ Master reads after setting word address (write word address; read data).<br />

XV.7.b 24C65 64K 5.0V I2CSmart Serial EEPROM<br />

♦ Device Addressing<br />

A control byte is the<br />

following the start<br />

master <strong>de</strong>vice. The<br />

a four bit control co<strong>de</strong>,<br />

as 1010 binary for read<br />

The next three bits of<br />

the <strong>de</strong>vice select bits<br />

used by the master<br />

first byte received<br />

condition from the<br />

control byte consists of<br />

for the 24C65 this is set<br />

and write operations.<br />

the control byte are<br />

(A2, A1, A0). They are<br />

<strong>de</strong>vice to select which<br />

M. <strong>Deloizy</strong> 236 dsPIC30F2023


ANNEXES<br />

of the eight <strong>de</strong>vices are to be accessed.<br />

These bits are in effect the three most significant bits of the word address.<br />

The last bit of the control byte (R/W) <strong>de</strong>fines the operation to be<br />

performed. When set to a one a read operation is selected, when set to a<br />

zero a write operation is selected. The next two bytes received <strong>de</strong>fine the<br />

address of the first data byte (Figure 4-1).<br />

Because only A12..A0 are used, the upper three address bits must be zeros.<br />

The most significant bit of the most significant byte is transferred first.<br />

Following the start condition, the 24C65 monitors the SDA bus checking<br />

the <strong>de</strong>vice type i<strong>de</strong>ntifier being transmitted.<br />

Upon receiving a 1010 co<strong>de</strong> and appropriate <strong>de</strong>vice select bits, the slave<br />

<strong>de</strong>vice (24C65) outputs an acknowledge signal on the SDA line. Depending<br />

upon the state of the R/W bit, the 24C65 will select a read or write<br />

operation.<br />

♦ Byte Write<br />

Following the start condition from the master, the control co<strong>de</strong> (four<br />

bits), the <strong>de</strong>vice select (three bits), and the R/W bit which is a logic low is<br />

placed onto the bus by the master transmitter. This indicates to the<br />

addressed slave receiver (24C65) that a byte with a word address will<br />

follow after it has generated an acknowledge bit during the ninth clock<br />

cycle. Therefore the next byte transmitted by the master is the high-or<strong>de</strong>r<br />

M. <strong>Deloizy</strong> 237 dsPIC30F2023


ANNEXES<br />

byte of the word address and will be written into the address pointer of<br />

the 24C65.<br />

The next byte is the least significant address byte. After receiving another<br />

acknowledge signal from the 24C65 the master <strong>de</strong>vice will transmit the<br />

data word to be written into the addressed memory location. The 24C65<br />

acknowledges again and the master generates a stop condition. This<br />

initiates the internal write cycle, and during this time the 24C65 will not<br />

generate acknowledge signals.<br />

BYTE WRITE :<br />

♦ Random Read<br />

Random read operations allow the master to access any memory location<br />

in a random manner. To perform this type of read operation, first the<br />

word address must be set. This is done by sending the word address to the<br />

24C65 as part of a write operation (R/W bit set to 0).<br />

After the word address is sent, the master generates a start condition<br />

following the acknowledge. This terminates the write operation, but not<br />

before the internal address pointer is set. Then the master issues the<br />

M. <strong>Deloizy</strong> 238 dsPIC30F2023


ANNEXES<br />

control byte again but with the R/W bit set to a one. The 24C65 will then<br />

issue an acknowledge and transmit the eight bit data word. The master<br />

will not acknowledge the transfer but does generate a stop condition<br />

which causes the 24C65 to discontinue transmission.<br />

RANDOM READ<br />

XV.7.c DAC5571 8-BIT DIGITAL-TO-ANALOG CONVERTER<br />

The DAC5571 contains<br />

four separate mo<strong>de</strong>s of<br />

operation. These<br />

mo<strong>de</strong>s are<br />

programmable via<br />

two bits (PD1 and<br />

PD0). When both bits<br />

are set to zero, the<br />

<strong>de</strong>vice works<br />

normally with normal<br />

power consumption of 150 μA at 5 V.<br />

However, for the<br />

three power-down<br />

mo<strong>de</strong>s, the supply<br />

current falls to 200 nA<br />

at 5 V (50 nA at 3 V). Not only does the supply current fall but the output<br />

stage is also internally switched from the output of the amplifier to a<br />

resistor network of known values. This has the advantage that the output<br />

M. <strong>Deloizy</strong> 239 dsPIC30F2023


ANNEXES<br />

impedance of the <strong>de</strong>vice is known while in power-down mo<strong>de</strong>. There are<br />

three different options: The output is connected internally to AGND<br />

through a 1-kΩ resistor, a 100-kΩ resistor, or it is left open-circuited (high<br />

impedance).<br />

M. <strong>Deloizy</strong> 240 dsPIC30F2023


Table <strong>de</strong>s matières<br />

M. <strong>Deloizy</strong> 241 dsPIC30F2023

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!