.
j'essaie de réaliser une conversion ADC, qui dans un programme tout seul fonctionne très bien, mais qui avec mon prog pricncipal n'a pas le meme comportement
MP SIM me dit :ADC-W0010: A Minimum of 2 TADs are required before another conversion should be started.
pourtant dans l'initialisation de l'adc je règle l'acquisition time à 20TAD
Meme en rajoutant un délai avant et un délai apres, cela revient au même
voici mon code
Merci a ceux qui pourront m'aiderCode:/********************************************************************* * quartz a 40Mhz => 1 instruct= Fosc/4 = 0.1µs *********************************************************************/ #include <p18f4550.h> #include <delays.h> #include <timers.h> #include <pwm.h> #pragma config PLLDIV = 1 #pragma config FOSC = XT_XT #pragma config FCMEN = OFF #pragma config PWRT = OFF #pragma config BOR = OFF #pragma config WDT = OFF #pragma config MCLRE = ON #pragma config LPT1OSC = OFF //#pragma config PBADEN = OFF #pragma config CCP2MX = OFF #pragma config STVREN = OFF #define synchro PORTDbits.RD0 // signal synchro sur RD0, permet interruption sur flancs #define synchro_TRIS TRISDbits.TRISD0 #define relay_enable PORTDbits.RD1 // sortie relai sur RD1 #define relay_enable_TRIS TRISDbits.TRISD1 /*function prototypes */ void initialisation(void); void interrupt_haute(void); void interrupt_basse(void); volatile char demarrage=1,synchro_previous=0,cpt_adc=0; volatile int chan0,chan1,chan2; // fonction interruption #pragma code highVector=0x008 // on déclare une interruption haute void high_interrupt(void) { _asm GOTO interrupt_haute _endasm // on doit éxecuter le code de la fonction traite_interrupt } #pragma code // retour à la zone de code #pragma code lowVector=0x018 // on déclare une interruption basse void low_interrupt(void) { _asm GOTO interrupt_basse _endasm // on doit éxecuter le code de la fonction interrupt_basse } #pragma code // retour à la zone de code /********************************************************************* * routine interruption du passage par zero (signal synchro) *passage ds 1 table de linéarisation *calcule le nouvel angle d allumage et qd Timer3 = la valeur de alpha ==> PWM=ON *********************************************************************/ #pragma interrupt interrupt_haute void interrupt_haute(void) { if(INTCONbits.RBIF) //interrup du a un changement sur RB { SetDCPWM1(105); // PWM ARRETE 77 ==>DC=75% 105 ==> 100% PIE2bits.CCP2IE=1; // active IT sur mode comparaison CCP2 synchro_previous=synchro;//lecture obligatoire sur PORTB T3CONbits.TMR3ON=1; // TMR3 Activé CCPR2=49700;// valeur de alpha enregistrer ici// égalité entre timer3 et alpha INTCONbits.RBIF=0; } // delai ecouler entre passage par zero et debut impulsions if(PIR2bits.CCP2IF) // l'IT provient d'une comparaison, { SetDCPWM1(77); // PWM EN MARCHE 77 ==>DC=75% 105 ==> 100% T3CONbits.TMR3ON=0; // TMR3 désactivé WriteTimer3(0); PIR2bits.CCP2IF=0; //efface le drapeau d'IT } } /********************************************************************* * routine interruption basse priorite ********************************************************************/ #pragma interruptlow interrupt_basse void interrupt_basse(void) { if(INTCONbits.TMR0IF) // TMR0 overflow { ADCON0bits.CHS2=0; // Channel 0 ADCON0bits.CHS1=0; ADCON0bits.CHS0=0; ADCON0bits.GO_DONE=1; // Run ADC INTCONbits.TMR0IF=0; //efface le drapeau d'IT } if(PIR1bits.ADIF) // l'IT provient de la fin d ADC { if(cpt_adc==0) //ADC ch0 termine { ADCON0bits.CHS2=0; // Channel 1 ADCON0bits.CHS1=0; ADCON0bits.CHS0=1; chan0=ADRES; ADCON0bits.GO_DONE=1; // Run ADC } if(cpt_adc==1) { ADCON0bits.CHS2=0; // Channel 2 ADCON0bits.CHS1=1; ADCON0bits.CHS0=0; chan1=ADRES; ADCON0bits.GO_DONE=1; // Run ADC } if(cpt_adc==2) { chan2=ADRES; cpt_adc=-1; } cpt_adc++; PIR1bits.ADIF=0; WriteTimer0(104); } } /********************************************************************* * initialisation des peripheriques *********************************************************************/ void initialisation(void){ synchro_TRIS=1; // synchro en entree relay_enable_TRIS=0; // relay_enable en sortie //test_TRIS=0; //configure port sortie/entree relay_enable=0; INTCONbits.RBIE = 1; // Enables the RB port change interrupt INTCON2bits.RBIP = 1; // RB Port Change Interrupt = High Priority INTCON2bits.RBPU = 0; // Pull Up activé sur RB //config TMR0 base de temps pour ADC toutes les ms T0CONbits.T08BIT=1; // TMR0 8bits counter T0CONbits.T0CS=0; // Internal instruction cycle clock T0CONbits.PSA=0; // prescaler ON T0CONbits.T0PS2=1; // prescaler 1/64 T0CONbits.T0PS1=0; T0CONbits.T0PS0=1; INTCONbits.TMR0IE=1; // enalbe TMR0 overflow interrupt INTCON2bits.TMR0IP=0; // interrupt low priority WriteTimer0(103); // configure le TIMER3, GERE delai etre passage par 0 et impulsions T3CONbits.RD16=0; // TMR3 mode simple (pas de RW) T3CONbits.TMR3CS=0; // compte les impulsions sur internal clock T3CONbits.T3CKPS0=1; // 1/2 Prescale value T3CONbits.T3SYNC=1; T3CONbits.T3CCP2=0; // Timer3 is the capture/compare clock source for CCP2 T3CONbits.T3CCP1=1; // Timer1 is the capture/compare clock source for CCP1 CCP2CON=0x0B; // Trigger special event sur comparaison (RAZ TIMER3 lors de l'égalité) IPR2bits.CCP2IP=1; // CCPR2 priorite haute T3CONbits.TMR3ON=0; // TMR3 désactivé OpenTimer2( TIMER_INT_OFF & T2_PS_1_16 & T2_POST_1_1 ); // Timer 2 pour PWM prescaler 1/16, postscaler 1 OpenPWM1(25); // PWM 24,038kHz si timer 2 pres=1/16 SetDCPWM1(105); // 77 ==>DC=75% 105 ==> 100% //config ADC //OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,ADC_CH0 & ADC_REF_VDD_VSS & ADC_INT_ON, ADC_14ANA ); //OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,ADC_CH1 & ADC_REF_VDD_VSS & ADC_INT_ON, ADC_14ANA ); //OpenADC( ADC_FOSC_32 & ADC_RIGHT_JUST & ADC_12_TAD,ADC_CH2 & ADC_REF_VDD_VSS & ADC_INT_ON, ADC_14ANA ); ADCON0bits.ADON=1; // Converter module enabled ADCON2bits.ADFM=1; // Right justified ADCON2bits.ACQT2=1; // Acquisition time ADCON2bits.ACQT1=1; // 12TAD ADCON2bits.ACQT0=1; ADCON2bits.ADCS2=0; // Conversion Clock ADCON2bits.ADCS1=0; // FOSC/8 ADCON2bits.ADCS0=1; PIE1bits.ADIE=1; //enalbes AD interrupt IPR1bits.ADIP=0; //ADC interrup basse } /********************************************************************* * programme principal *********************************************************************/ void main (void){ initialisation(); // appel du sous-prog d'initialisation relay_enable=1; // ferme le relai Delay1KTCYx(1); // Delay in multiples of 1,000 instruction cycles. 1 instru= 0.1us T0CONbits.TMR0ON=1; // lance le timer0 RCONbits.IPEN=1; // Enable priority levels on interrupts PIR1 = 0; INTCONbits.GIEH = 1; // On autorise les interruptions haute priorité INTCONbits.GIEL = 1; // On autorise les interruptions basse priorité while(1){ } }
-----