David Giles
/
CM-MBED_RSEDP_Test_Suite_LPC1768_V3
This is a complete listing of the RS-EDP software for the mbed module to support the RS-EDP platform.
SourceFiles/RSEDP_AM_ADC5263_Digital_Pot.cpp@0:5b7639d1f2c4, 2010-11-19 (annotated)
- Committer:
- DavidGilesHitex
- Date:
- Fri Nov 19 09:49:16 2010 +0000
- Revision:
- 0:5b7639d1f2c4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidGilesHitex | 0:5b7639d1f2c4 | 1 | /* Source Driver File for the AD5263 Digital Potentiometer */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 2 | /* ******************************************************* */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 3 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 4 | /* Version 1.00 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 5 | /* Last Ammend Date: 23/6/09 */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 6 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 7 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 8 | #define _AD5263_ |
DavidGilesHitex | 0:5b7639d1f2c4 | 9 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 10 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 11 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 12 | /* Include Files Here */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 13 | #include "mbed.h" /* mbed header file */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 14 | #include "misra_types.h" /* MISRA Types header file */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 15 | #include "defines.h" |
DavidGilesHitex | 0:5b7639d1f2c4 | 16 | #include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 17 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 18 | #include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 19 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 20 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 21 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 22 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 23 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 24 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 25 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 26 | /* Function Prototypes */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 27 | sint32_t RSEDP_AM_Init_AD5263(uint8_t I2C_addr) ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 28 | sint32_t RSEDP_AM_Set_AD5263_resistance(uint8_t I2C_addr, uint8_t uiChannel, uint16_t uiResistance_Ohms) ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 29 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 30 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 31 | /* Global Variables */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 32 | uint16_t AD5263_default_resistances[AD5263_No_Of_Channels] = { AD5263_RDAC1_Default_Resistance, AD5263_RDAC2_Default_Resistance, AD5263_RDAC3_Default_Resistance, AD5263_RDAC4_Default_Resistance } ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 33 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 34 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 35 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 36 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 37 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 38 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 39 | /* Reset and initialise AD5623 RDAC */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 40 | sint32_t RSEDP_AM_Init_AD5263(uint8_t I2C_addr) |
DavidGilesHitex | 0:5b7639d1f2c4 | 41 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 42 | sint8_t uiSetup_byte = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 43 | uint8_t uiChannel_no = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 44 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 45 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 46 | for(uiChannel_no = 0; uiChannel_no < AD5263_No_Of_Channels ; uiChannel_no++) |
DavidGilesHitex | 0:5b7639d1f2c4 | 47 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 48 | /* Create Setup Byte */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 49 | /* Set channel 0 to midscale */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 50 | uiSetup_byte = AD5263_RDAC_Midscale_Reset | (uiChannel_no << 5) ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 51 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 52 | /* Send Command */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 53 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiSetup_byte, 1) ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 54 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 55 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 56 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 57 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 58 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 59 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 60 | /* Convert a raw value in Ohms to a resistance */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 61 | sint32_t RSEDP_AM_Set_AD5263_resistance(uint8_t I2C_addr, uint8_t uiChannel, uint16_t uiResistance_Ohms) |
DavidGilesHitex | 0:5b7639d1f2c4 | 62 | { |
DavidGilesHitex | 0:5b7639d1f2c4 | 63 | sint32_t Ack_Status = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 64 | uint16_t uiScaled_resistance = 0; |
DavidGilesHitex | 0:5b7639d1f2c4 | 65 | sint8_t uiMessage[3] = {0,0,0}; |
DavidGilesHitex | 0:5b7639d1f2c4 | 66 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 67 | /* Set channel */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 68 | uiMessage[0] = ((uiChannel-1) << 5) ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 69 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 70 | /* Convert resistance in Ohms to a number of steps */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 71 | uiScaled_resistance = ((uint32_t)uiResistance_Ohms * AD5263_Resolution)/AD5263_Max_Resistance ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 72 | uiMessage[1] = uiScaled_resistance ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 73 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 74 | /* Send command */ |
DavidGilesHitex | 0:5b7639d1f2c4 | 75 | Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, uiMessage, 2) ; |
DavidGilesHitex | 0:5b7639d1f2c4 | 76 | return Ack_Status; |
DavidGilesHitex | 0:5b7639d1f2c4 | 77 | } |
DavidGilesHitex | 0:5b7639d1f2c4 | 78 | |
DavidGilesHitex | 0:5b7639d1f2c4 | 79 |