[Numérique] Problème lecture AD5271
Répondre à la discussion
Affichage des résultats 1 à 3 sur 3

Problème lecture AD5271



  1. #1
    invited14ca340

    Problème lecture AD5271


    ------

    Bonjour,
    J'essaie de communiquer avec un AD5271 (20 kOhm) mais j'ai un décalage entre l'écriture et la relecture du registre RDAC, le problème n'est pas présent lorsque je fais la même chose avec le registre de configuration.

    Je m'explique :

    J'aimerais que ma routine d'écriture du registre RDAC fasse une relecture pour s'assurer que la valeur écrite est conforme (commandes 0x01 et 0x02 p.19). Le formate de la trame est donnée p.7.
    Lorsque j'écris dans le registre de configuration et que je relis la valeur, j'obtiens bien la même chose (commandes 0x07 et 0x08). Par contre si je fais la même chose avec RDAC, la valeur correcte n'apparaît qu'après 3 cycles :
    Code:
    Terminal de debug :
    
    writeValue: 0
    readValue: 0
    writeValue: 78
    readValue: 0
    writeValue: 156
    readValue: 78
    Le problème c'est que j'aimerais qu'il y ait un retour d'erreur si la valeur lue ne correspond pas à la valeur envoyée, donc l'idéal ce serait de pouvoir recevoir la donnée juste après la première écriture, sans avoir à écrire sur 3 cycles... J'ai essayé avec un délai d'1 seconde entre l'écriture et la lecture, pas de changement, c'est bien un problème de cycle d'écriture.

    voici une partie du code qui gère l'accès à l'AD5271 :
    Code:
    /* AD5271_transferData - Simultaneously send and receive data word from AD5271 through SPI.
     * parameter wData : Data to send.
     * parameter rData : Data to read.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_transferData(unsigned short int wData,unsigned short int *rData)
    {
    	int status=0;
    	unsigned char wByte[2];
    	unsigned char rByte[2];
    	wByte[0]=(unsigned char)((wData>>8)&0xFF);
    	wByte[1]=(unsigned char)(wData&0xFF);
    	SPI3_configure(MASTER,NO_BUFFER,MODE_8_BIT,AD5271_CKE,AD5271_CKP,AD5271_SMP);
    	status=SPI3_transferByteFrame(wByte,rByte,2);
    	*rData=((unsigned short int)rByte[0]<<8)|(unsigned short int)rByte[1];
    	return status;
    }
    
    /* AD5271_writeData - Send data to AD5271 through SPI.
     * parameter command : Command address.
     * parameter wData : Data to send.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_writeData(unsigned char command,unsigned short int wData)
    {
    	int status=0;
    	unsigned short int value=0;
    	value=((unsigned short int)((command<<10)&0x3C00)|(wData&0x03FF));
    	AD5271_CS_low();
    	status=AD5271_transferData(value,NULL);
    	AD5271_CS_high();
    	return status;
    }
    
    /* AD5271_readData - Read data from AD5271 through SPI.
     * parameter command : Command address.
     * parameter wData : Data to write.
     * parameter rData : Data to read.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readData(unsigned char command,unsigned short int wData,unsigned short int *rData)
    {
    	int status=0;
    	unsigned short int wValue=0;
    	wValue=((unsigned short int)((command<<10)&0x3C00)|(wData&0x03FF));
    	AD5271_CS_low();
    	status=AD5271_transferData(wValue,rData);
    	AD5271_CS_high();
    	return status;
    }
    
    /* AD5271_setResistor - Write value to RDAC to set resistor value.
     * parameter resistorValue : Resistor value to set.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_setResistor(unsigned long int resistorValue)
    {
    	unsigned char wValue=0;
    	if(resistorValue>AD5271_RESISTOR)
    		return -1;
    	wValue=(unsigned char)(((unsigned long int)resistorValue*255)/(unsigned long int)AD5271_RESISTOR);
    	return (AD5271_writeData(AD5271_WRITE_RDAC,(unsigned short int)((wValue<<2)&0x03FC)));
    }
    
    /* AD5271_getResistor - Read resistor value from RDAC.
     * parameter resistorValue : Resistor value to get.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_getResistor(unsigned long int *resistorValue)
    {
    	int status=0;
    	unsigned short int rValue=0;
    	status=AD5271_readData(AD5271_READ_RDAC,NULL,&rValue);
    	*resistorValue=(unsigned long int)(AD5271_RESISTOR/255)*((unsigned long int)((rValue>>2)&0xFF));
    	return status;
    }
    Quelqu'un a une idée du problème, ou rencontré le même problème?

    -----

  2. #2
    jiherve

    Re : Problème lecture AD5271

    Bonsoir,
    les temps d'ecriture et de lecture du RDAC ne sont pas petits 2µs et 6µS et il y a çà aussi:
    Data from the RDAC register is clocked out of the SDO pin during the last 10 clocks of the next SPI operation
    .
    Donc tu devrais placer un scope sur tes fils et regarder ce qui se passe réellement.
    JR
    l'électronique c'est pas du vaudou!

  3. #3
    invited14ca340

    Re : Problème lecture AD5271

    Bonjour,
    Du coup j'ai résolu le problème. Effectivement les données arrivent sur la transaction suivante, mais le problème ne venait pas de là. J'avais une mauvaise configuration du périphérique SPI (la configuration correcte est CKP=0, CKE=0 et SMP=1). Concernant les temps de réponse ce n'est pas un problème car le périphérique SPI est lent (prescaler et postscaler aux valeurs max).

    Code:
    #ifndef AD5271_H
    #define	AD5271_H
    
    /*** Defines ***/
    
    // SPI polarity
    #define AD5271_SMP                  1
    #define AD5271_CKE                  0
    #define AD5271_CKP                  0
    
    // AD5271 Resistor Value
    #define AD5271_RESISTOR				20000
    
    // AD5271 Command Table
    #define AD5271_NOP					0x00
    #define AD5271_WRITE_RDAC			0x01
    #define AD5271_READ_RDAC			0x02
    #define AD5271_WRITE_50TP			0x03
    #define AD5271_LOAD_50TP			0x04
    #define AD5271_READ_50TP_VALUE		0x05
    #define AD5271_READ_50TP_ADDRESS	0x06
    #define AD5271_WRITE_CTRL_REGISTER	0x07
    #define AD5271_READ_CTRL_REGISTER	0x08
    #define AD5271_SHUTDOWN_CTRL		0x09
    
    // AD5271 Control Register
    #define AD5271_50TP_EN				0x01	// Enable 50-TP programmation
    #define AD5271_RDAC_EN				0x02	// Allow RDAC wiper update
    #define AD5271_RDAC_CAL_DIS			0x04	// Disable RDAC tolerence calibration
    #define AD5271_50TP_SUCCESS			0x08	// 50-TP fuse programmation successful - Read Only
    
    /*** AD5271 hardware abstraction layer (HAL) function prototypes ***/
    
    /* AD5271_CS_low - Set Chip Select (CS) low.
     * parameter : void.
     * return : void.
     */
    void AD5271_CS_low(void);
    
    /* AD5271_CS_high - Set Chip Select (CS) high.
     * parameter : void.
     * return : void.
     */
    void AD5271_CS_high(void);
    
    /* AD5271_transferData - Simultaneously send and receive data word from AD5271 through SPI.
     * parameter wData : Data to send.
     * parameter rData : Data to read.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_transferData(unsigned short int wData,unsigned short int *rData);
    
    /* AD5271_configureHardware - Configure CS pin and SPI peripheral.
     * parameter : void.
     * return : void.
     */
    void AD5271_configureHardware(void);
    
    /*** AD5271 generic function prototypes ***/
    
    /* AD5271_writeData - Send data to AD5271 through SPI.
     * parameter command : Command address.
     * parameter wData : Data to send.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_writeData(unsigned char command,unsigned short int wData);
    
    /* AD5271_readData - Read data from AD5271 through SPI.
     * parameter command : Command address.
     * parameter wData : Data to write.
     * parameter rData : Data to read.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readData(unsigned char command,unsigned short int wData,unsigned short int *rData);
    
    /* AD5271_enterShutdown - Enter shutdown state.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_enterShutdown(void);
    
    /* AD5271_exitShutdown - Exit shutdown state.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_exitShutdown(void);
    
    /* AD5271_writeControlRegister - Write value to control register.
     * parameter registerValue : Value to write to control register.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_writeControlRegister(unsigned char registerValue);
    
    /* AD5271_readControlRegister - Read value from control register.
     * parameter registerValue : Value to read from control register.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readControlRegister(unsigned char *registerValue);
    
    /* AD5271_setResistor - Write value to RDAC to set resistor value.
     * parameter resistorValue : Resistor value to set.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_setResistor(unsigned long int resistorValue);
    
    /* AD5271_getResistor - Read resistor value from RDAC.
     * parameter resistorValue : Resistor value to get.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_getResistor(unsigned long int *resistorValue);
    
    /* AD5271_readStoredValue - Read stored resistor value from 50-TP pointed memory address.
     * parameter memoryAddress : 50-TP memory address to read stored value from.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readStoredValue(unsigned char memoryAddress);
    
    /* AD5271_getLastAddress - Read last saved 50-TP memory address.
     * parameter memoryAddress : Value of the last saved 50-TP memory address.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_getLastAddress(unsigned char *memoryAddress);
    
    /* AD5271_saveResistorValue - Write RDAC value to 50-TP memory.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_saveResistorValue(void);
    
    /* AD5271_loadResistorValue - Load RDAC value with last 50-TP memory value.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_loadResistorValue(void);
    
    /* AD5271_init - Initialize AD5271 with full range resistor value
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_init(void);
    
    /* AD5271_accessTest - Proceed a AD5271 access test.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_accessTest(void);
    
    #endif	/* AD5271_H */
    Code:
    /*** Includes ***/
    
    #include "HardwareProfile.h"
    #include "AD5271.h"
    #include "spi3.h"
    
    /*** AD5271 hardware abstraction layer (HAL) function declarations ***/
    
    /* AD5271_CS_low - Set Chip Select (CS) low.
     * parameter : void.
     * return : void.
     */
    void AD5271_CS_low(void)
    {
    	AD5271_CS=0;
    }
    
    /* AD5271_CS_high - Set Chip Select (CS) high.
     * parameter : void.
     * return : void.
     */
    void AD5271_CS_high(void)
    {
    	AD5271_CS=1;
    }
    
    /* AD5271_transferData - Simultaneously send and receive data word from AD5271 through SPI.
     * parameter wData : Data to send.
     * parameter rData : Data to read.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_transferData(unsigned short int wData,unsigned short int *rData)
    {
    	int status=0;
    	unsigned char wByte[2];
    	unsigned char rByte[2];
    	wByte[0]=(unsigned char)((wData>>8)&0xFF);
    	wByte[1]=(unsigned char)(wData&0xFF);
    	SPI3_configure(MASTER,NO_BUFFER,MODE_8_BIT,AD5271_CKE,AD5271_CKP,AD5271_SMP);
    	status=SPI3_transferByteFrame(wByte,rByte,2);
    	*rData=((unsigned short int)rByte[0]<<8)|(unsigned short int)rByte[1];
    	return status;
    }
    
    /* AD5271_configureHardware - Configure CS pin and SPI peripheral.
     * parameter : void.
     * return : void.
     */
    void AD5271_configureHardware(void)
    {
    	AD5271_CS_TRIS=OUTPUT;	// Configure Chip Select pin as output
    	AD5271_CS_high();		// Initialize Chip Select at '1' : un-select device
    	SPI3_configure(MASTER,NO_BUFFER,MODE_8_BIT,AD5271_CKE,AD5271_CKP,AD5271_SMP);
    }
    
    /*** AD5271 generic function declarations ***/
    
    /* AD5271_writeData - Send data to AD5271 through SPI.
     * parameter command : Command address.
     * parameter wData : Data to send.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_writeData(unsigned char command,unsigned short int wData)
    {
    	int status=0;
    	unsigned short int value=0;
    	value=((unsigned short int)((command<<10)&0x3C00)|(wData&0x03FF));
    	AD5271_CS_low();
    	status=AD5271_transferData(value,NULL);
    	AD5271_CS_high();
    	return status;
    }
    
    /* AD5271_readData - Read data from AD5271 through SPI.
     * parameter command : Command address.
     * parameter wData : Data to write.
     * parameter rData : Data to read.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readData(unsigned char command,unsigned short int wData,unsigned short int *rData)
    {
    	int status=0;
    	unsigned short int wValue=0;
    	wValue=((unsigned short int)((command<<10)&0x3C00)|(wData&0x03FF));
    	AD5271_CS_low();
    	status=AD5271_transferData(wValue,rData);
    	AD5271_CS_high();
    	return status;
    }
    
    /* AD5271_enterShutdown - Enter shutdown state.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_enterShutdown(void)
    {
    	return(AD5271_writeData(AD5271_SHUTDOWN_CTRL,1));
    }
    
    /* AD5271_exitShutdown - Exit shutdown state.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_exitShutdown(void)
    {
    	return(AD5271_writeData(AD5271_SHUTDOWN_CTRL,0));
    }
    
    /* AD5271_writeControlRegister - Write value to control register.
     * parameter registerValue : Value to write to control register.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_writeControlRegister(unsigned char registerValue)
    {
    	int status=0;
    	unsigned short int rValue=0;
    	status|=AD5271_writeData(AD5271_WRITE_CTRL_REGISTER,(unsigned short int)(registerValue&0x07));
    	status|=AD5271_readData(AD5271_READ_CTRL_REGISTER,NULL,&rValue);
    	if((rValue&0x07)!=(registerValue&0x07))
    		return -1;
    	else
    		return status;
    }
    
    /* AD5271_readControlRegister - Read value from control register.
     * parameter registerValue : Value to read from control register.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readControlRegister(unsigned char *registerValue)
    {
    	int status=0;
    	unsigned short int rValue=0;
    	status=AD5271_readData(AD5271_READ_CTRL_REGISTER,NULL,&rValue);
    	*registerValue=(unsigned char)(rValue&0x0F);
    	return status;
    }
    
    /* AD5271_setResistor - Write value to RDAC to set resistor value.
     * parameter resistorValue : Resistor value to set.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_setResistor(unsigned long int resistorValue)
    {
    	int status=0;
    	unsigned short int wValue=0;
    	unsigned short int rValue=0;
    	if(resistorValue>AD5271_RESISTOR)
    		return -1;
    	wValue=(unsigned short int)(((((unsigned long int)(resistorValue+1)*255)/(unsigned long int)AD5271_RESISTOR)<<2)&0x03FC);
    	status|=AD5271_writeData(AD5271_WRITE_RDAC,wValue);
    	status|=AD5271_readData(AD5271_READ_RDAC, NULL,&rValue);
    	if((rValue&0x03FC)!=(wValue&0x03FC))
    		return -1;
    	else
    		return status;
    }
    
    /* AD5271_getResistor - Read resistor value from RDAC.
     * parameter resistorValue : Resistor value to get.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_getResistor(unsigned long int *resistorValue)
    {
    	int status=0;
    	unsigned short int rValue=0;
    	status|=AD5271_readData(AD5271_READ_RDAC,NULL,&rValue);
    	*resistorValue=(unsigned long int)(((unsigned long int)((rValue&0x3FC)>>2)*(unsigned long int)AD5271_RESISTOR)/(unsigned long int)255);
    	return status;
    }
    
    /* AD5271_readStoredValue - Read stored resistor value from 50-TP pointed memory address.
     * parameter memoryAddress : 50-TP memory address to read stored value from.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_readStoredValue(unsigned char memoryAddress)
    {
    	int status=0;
        // Not implemented yet. Complete function to use it
    	return status;
    }
    
    /* AD5271_getLastAddress - Read last saved 50-TP memory address.
     * parameter memoryAddress : Value of the last saved 50-TP memory address.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_getLastAddress(unsigned char *memoryAddress)
    {
    	int status=0;
        // Not implemented yet. Complete function to use it
    	return status;
    }
    
    /* AD5271_saveResistorValue - Write RDAC value to 50-TP memory.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_saveResistorValue(void)
    {
    	int status=0;
        // Not implemented yet. Complete function to use it
    	return status;
    }
    
    /* AD5271_loadResistorValue - Load RDAC value with last 50-TP memory value.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_loadResistorValue(void)
    {
    	int status=0;
        // Not implemented yet. Complete function to use it
    	return status;
    }
    
    /* AD5271_init - Initialize AD5271 with full range resistor value
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_init(void)
    {
        int status=0;
        AD5271_configureHardware();
        status|=AD5271_exitShutdown();
        status|=AD5271_writeControlRegister(AD5271_RDAC_EN);
        status|=AD5271_setResistor(0);
        return status;
    }
    
    /* AD5271_accessTest - Proceed a AD5271 access test.
     * parameter : void.
     * return status : 0 = success; negative = fail.
     */
    int AD5271_accessTest(void)
    {
    	int status=0;
    	unsigned char rValue=0;
    	status|=AD5271_exitShutdown();
    	status|=AD5271_writeControlRegister(0);
    	status|=AD5271_readControlRegister(&rValue);
    	if(rValue!=0)
    		return -1;
    	status|=AD5271_writeControlRegister(AD5271_RDAC_EN);
    	status|=AD5271_readControlRegister(&rValue);
    	if(rValue!=AD5271_RDAC_EN)
    		return -1;
    	return status;
    }

Discussions similaires

  1. Problème de lecture de DVD
    Par invite73b933a9 dans le forum Matériel - Hardware
    Réponses: 0
    Dernier message: 11/06/2010, 07h39
  2. Problème de lecture de DVD
    Par priest28 dans le forum Matériel - Hardware
    Réponses: 5
    Dernier message: 22/11/2006, 20h40
  3. probleme de lecture
    Par invitee5921a80 dans le forum Matériel - Hardware
    Réponses: 6
    Dernier message: 19/11/2005, 08h50
  4. Réponses: 2
    Dernier message: 27/07/2005, 10h44
  5. Problème de lecture de DVD...
    Par invitef0eaf559 dans le forum Matériel - Hardware
    Réponses: 4
    Dernier message: 17/01/2004, 20h56
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...