IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Programme pour PIC32


Sujet :

C

  1. #1
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut Programme pour PIC32
    Bonjour,

    n'étant pas très aguéri dans ce domaine pour le moment, j'essai d’approfondir mes connaissances à ce sujet et je m'exerce sur un starter kit de microchip sur un pic32MX795.

    Jusqu'à présent j'ai toujours programmé du PIC lorsque celui-ci était déjà fonctionnel et je n'avais plus qu'à modifier ou faire évoluer les soft.

    Actuellement, je n'arrive pas à comprendre le problème :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
     
    /*********************************************************************
     *
     *      PIC32MX 
     *
     *********************************************************************
     *
     * FileName:        main.c
     *
     * Dependencies:    plib.h
     *
     * Processor:       PIC32MX
     *
     * Complier:        MPLAB C32
     *                  MPLAB IDE
     *
     * Company:        
     *
     * auteur:              
     *
     *********************************************************************/
    #include <plib.h>
     
     
    #if defined (__32MX360F512L__) || (__32MX460F512L__) || (__32MX795F512L__) || (__32MX430F064L__)
    // Configuration Bit settings
    // SYSCLK = 80 MHz (8MHz Crystal / FPLLIDIV * FPLLMUL / FPLLODIV)
    // PBCLK = 80 MHz (SYSCLK / FPBDIV)
    // Primary Osc w/PLL (XT+,HS+,EC+PLL)
    // WDT OFF
    // Other options are don't care
     
     
     
    void clignotement(void);
     
     
    int i,j;
     
     
     
    #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
    #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
    //#define SYS_FREQ (80000000L)
    #endif
     
    // Let compile time pre-processor calculate the CORE_TICK_PERIOD
    #define SYS_FREQ 				(80000000)
    #define TOGGLES_PER_SEC			1
    #define CORE_TICK_RATE	        (SYS_FREQ/5/TOGGLES_PER_SEC)
    #define LED						0x00000007
     
     
     
     
     
     
    void __ISR(_CORE_TIMER_VECTOR, ipl2) CoreTimerHandler(void)
    {
        // .. things to do
     
    	// .. Toggle the LED
        mPORTDToggleBits(BIT_0);
    	mPORTDToggleBits(BIT_1);
    	mPORTDToggleBits(BIT_2);
    	i++;
    	//if (i==10) i=0;
        // update the period
        UpdateCoreTimer(CORE_TICK_RATE);
     
        // clear the interrupt flag
        mCTClearIntFlag();
    }
     
     
    void clignotement(void)
    {
     
    j=i;
    //mPORTDToggleBits(BIT_0);
    //mPORTDToggleBits(BIT_1);
    //mPORTDToggleBits(BIT_2);
    //UpdateCoreTimer(CORE_TICK_RATE);
    //if (i<5) PORTD=0x00000007; else if(i>5) PORTD=0x00000000;
    }
     
     
     
     
    int main(void)
    {
     
        // Configure the device for maximum performance but do not change the PBDIV
        // Given the options, this function will change the flash wait states, RAM
        // wait state and enable prefetch cache but will not change the PBDIV.
        // The PBDIV value is already set via the pragma FPBDIV option above.
        SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
     
        // Explorer-16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
        mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
     
        //Initialize the DB_UTILS IO channel
        DBINIT();
     
            // configure the core timer roll-over rate (100msec)
        OpenCoreTimer(CORE_TICK_RATE);
     
        // set up the core timer interrupt with a prioirty of 2 and zero sub-priority
        mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0));
     
        // Clear PORTA bits so there are no unexpected flashes when setting
        // them to output in the next step
        //mPORTDClearBits(BIT_2 |BIT_1 | BIT_0);
     
            // enable device multi-vector interrupts
        INTEnableSystemMultiVectoredInt();
     
        // Make lower four bits of PORTD as output
        mPORTDSetPinsDigitalOut(BIT_2 |BIT_1 | BIT_0);
     
        	//Now blink LEDs ON/OFF forever.
     		while (1)
    		{
    		clignotement();
     
    		}
     
     
     
    }
    ce soft ce compile sans problème seulement j'ai fais une simple fonction :

    clignotement();

    et j'ai l'impression qu'il ne passe pas par ma fonction car j'ai juste une variable à l’intérieur et celle-ci ne bouge pas pendant l'execution alors que la variable i bouge.

    Merci pour vos éclaircissements qui pourrons me faire avancer dans mon apprentissage.

  2. #2
    Membre expérimenté Avatar de edgarjacobs
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2011
    Messages
    625
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 625
    Points : 1 562
    Points
    1 562
    Par défaut
    Hello,

    Je n'y connais rien en programmation PIC, mais i (et j si nécessaire) ne sont pas initialisés....
    On écrit "J'ai tort" ; "tord" est la conjugaison du verbre "tordre" à la 3ème personne de l'indicatif présent

  3. #3
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut
    Effectivement, c'est variable ne sont Pas initialisé, seulement en debugue je remarque que i s'incrémente correctement quand même et que j ne bouge toujours pas au fure et à mesure de l'execution, donc ça ne rentre pas dans la fonction qui contient cette variable

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    107
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2006
    Messages : 107
    Points : 124
    Points
    124
    Par défaut
    Bonjour,

    i étant modifié sous interruption, je mettrais le mot clef volatile pour indiquer au compilo de ne pas faire d'optimisations...
    Il est possible qu'il ai optimisé ta fonction "clignotement" en faisant j=constante avec constante =la valeur de i au lancement, et ainsi tu as l'impression de ne pas rentrer dans la fonction.

  5. #5
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut
    merci apesle, effectivement tu as raison en déclarant mes variable en volatile ça fonctionne, bon maintenant il me reste plus qu'à comprendre pourquoi ? ne maîtrisant pas trop les interruption pour l'instant.

    En faite j'ai fait une autre fonction dans laquelle je change uniquement la valeur d'une autre variable qui n'est appriori pas conditionné par i et cette autre variable ne change non plus tant qu'elle n'est pas déclaré comme volatile, pour l'instant je ne comprend pas très bien ce qui ce passe, par le passé, j'ai déjà dû déclaré des variables sans que ce soit du volatile ?

    En fait, la question pour résumer est :
    Est-ce que je dois déclarer toutes mes variables en volatile ?

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    107
    Détails du profil
    Informations personnelles :
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2006
    Messages : 107
    Points : 124
    Points
    124
    Par défaut
    Re -bonjour,

    Non, toutes tes var ne doivent pas être déclarées comme volatile. C'est à faire au cas par cas.
    Il te faut comprendre à quoi sert le mot clef (faq) pour que tu sache quand le mettre.

    Pour tes autres soucis de variables, je ne peux rien te dire sans voir le code.

  7. #7
    Membre du Club
    Homme Profil pro
    Electronicien
    Inscrit en
    Août 2008
    Messages
    360
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Electronicien
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Août 2008
    Messages : 360
    Points : 53
    Points
    53
    Par défaut
    Par exemple là j'ai fais une nouvelle fonction uniquement pour changer la valeur d'une "autre variable" qui n'a rien a voir avec l'interruption, et elle prend la valeur demandé dans la fonction que ci seulement elle est déclarée en volatile sinon elle reste a sa valeur d'initialisation ?


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
     
    #include <plib.h>
     
     
    #if defined (__32MX360F512L__) || (__32MX460F512L__) || (__32MX795F512L__) || (__32MX430F064L__)
    // Configuration Bit settings
    // SYSCLK = 80 MHz (8MHz Crystal / FPLLIDIV * FPLLMUL / FPLLODIV)
    // PBCLK = 80 MHz (SYSCLK / FPBDIV)
    // Primary Osc w/PLL (XT+,HS+,EC+PLL)
    // WDT OFF
    // Other options are don't care
     
     
     
    void clignotement(void);
    void init_variable(void);
    void autre_fonction(void);
     
     
    volatile int autre_variable;
    volatile int i, j;
    //int j;
     
     
    #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
    #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
    //#define SYS_FREQ (80000000L)
    #endif
     
    // Let compile time pre-processor calculate the CORE_TICK_PERIOD
    #define SYS_FREQ 				(80000000)
    #define TOGGLES_PER_SEC			1
    #define CORE_TICK_RATE	        (SYS_FREQ/5/TOGGLES_PER_SEC)
    #define LED						0x00000007
     
     
     
    void init_variable(void)
    {
    i=1;
    j=1;
     
    autre_variable=10;
     
    }
     
     
     
    void __ISR(_CORE_TIMER_VECTOR, ipl2) CoreTimerHandler(void)
    {
        // .. things to do
     
    	// .. Toggle the LED
        mPORTDToggleBits(BIT_0);
    	mPORTDToggleBits(BIT_1);
    	mPORTDToggleBits(BIT_2);
    	i++;
    	//if (i==10) i=0;
        // update the period
        UpdateCoreTimer(CORE_TICK_RATE);
     
        // clear the interrupt flag
        mCTClearIntFlag();
    }
     
     
    void clignotement(void)
    {
    //ClrWdt();
    j=i;
     
     
     
    //mPORTDToggleBits(BIT_0);
    //mPORTDToggleBits(BIT_1);
    //mPORTDToggleBits(BIT_2);
    //UpdateCoreTimer(CORE_TICK_RATE);
    //if (i<5) PORTD=0x00000007; else if(i>5) PORTD=0x00000000;
    }
     
    void autre_fonction(void)
    {
    autre_variable=150;
     
    }
     
     
     
     
    int main(void)
    {
     
        // Configure the device for maximum performance but do not change the PBDIV
        // Given the options, this function will change the flash wait states, RAM
        // wait state and enable prefetch cache but will not change the PBDIV.
        // The PBDIV value is already set via the pragma FPBDIV option above.
        SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
     
        // Explorer-16 LEDs are on lower 8-bits of PORTA and to use all LEDs, JTAG port must be disabled.
        //mJTAGPortEnable(DEBUG_JTAGPORT_OFF);
     
        //Initialize the DB_UTILS IO channel
        DBINIT();//ClrWdt();
     
     
     
            // configure the core timer roll-over rate (100msec)
        OpenCoreTimer(CORE_TICK_RATE);
     
    	init_variable();//ClrWdt();
     
     
        // set up the core timer interrupt with a prioirty of 2 and zero sub-priority
        mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_2 | CT_INT_SUB_PRIOR_0));
     
    j=2;
     
        // Clear PORTA bits so there are no unexpected flashes when setting
        // them to output in the next step
        mPORTDClearBits(BIT_2 |BIT_1 | BIT_0);
     
    j=3;
     
     
        // Make lower four bits of PORTD as output
        mPORTDSetPinsDigitalOut(BIT_2 |BIT_1 | BIT_0);
     
    j=4;	
     
            // enable device multi-vector interrupts
        INTEnableSystemMultiVectoredInt();//ClrWdt();
     
    j=5;
     
     
     
    	//ClrWdt();
     
        	//Now blink LEDs ON/OFF forever.
     		while (1)
    		{
    		clignotement();
    		autre_fonction();
     
    		}
     
     
    return 0;
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 27/08/2007, 15h40
  2. [Info] programme pour J2ME
    Par ehmppowa dans le forum Java ME
    Réponses: 4
    Dernier message: 12/08/2005, 19h37
  3. existe t 'il des programme pour transformer les bases
    Par creazone dans le forum Décisions SGBD
    Réponses: 1
    Dernier message: 05/10/2004, 14h11
  4. [TP]Programme pour piloter port série et parallèle...
    Par DDR dans le forum Turbo Pascal
    Réponses: 10
    Dernier message: 15/04/2004, 21h52
  5. Créer de programme pour WIndows avec Turbo Pascal
    Par kaygee dans le forum Turbo Pascal
    Réponses: 16
    Dernier message: 20/08/2003, 23h22

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo