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.
Revision 0:5b7639d1f2c4, committed 2010-11-19
- Comitter:
- DavidGilesHitex
- Date:
- Fri Nov 19 09:49:16 2010 +0000
- Commit message:
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/MC2_Motor_Driver_I2C_Master.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,31 @@ +/* Header File For the dsPIC Master */ + + +/* Write Functions */ +extern uint8_t I2C0_dsPIC_Reset(uint8_t slave_address); +extern uint8_t I2C0_dsPIC_Emergency_Stop(uint8_t slave_address); +extern uint8_t I2C0_dsPIC_Normal_Stop(uint8_t slave_address); +extern uint8_t I2C0_dsPIC_Ping(uint8_t slave_address); +extern uint8_t I2C0_dsPIC_Set_Motor_Speed_Demand_Forward(uint8_t slave_address, uint16_t motor_speed_Demand); +extern uint8_t I2C0_dsPIC_Set_Motor_Speed_Demand_Reverse(uint8_t slave_address, uint16_t motor_speed_Demand); +extern uint8_t I2C0_dsPIC_Set_Ramp_Up_Speed(uint8_t slave_address, uint16_t ramp_up_speed); +extern uint8_t I2C0_dsPIC_Set_Ramp_Down_Speed(uint8_t slave_address, uint16_t ramp_down_speed); +extern uint8_t I2C0_dsPIC_Set_Motor_Direction(uint8_t slave_address, uint8_t direction); +extern uint8_t I2C0_dsPIC_Start_Motor_Rotation(uint8_t slave_address); +extern uint8_t I2C0_dsPIC_Set_Rotation_Counts(uint8_t slave_address, uint32_t motor_rotation_counts); +extern uint8_t I2C0_dsPIC_Goto_Home(uint8_t slave_address, uint8_t home_direction, uint8_t home_speed); + + +/* Read Functions */ +extern uint8_t I2C0_dsPIC_Read_Tacho_Speed_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Tacho_Speed_Average(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Motor_Current_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Motor_Current_Average(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Vbus_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Vbus_Average(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Demand_Pot_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Demand_Pot_Average(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Hall_Sensor_Positions(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Motor_Status(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Maximum_RPM(uint8_t slave_address, uint8_t *rx_array); +extern uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter(uint8_t slave_address, uint8_t *rx_array);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RS-EDP_AM_MC2_Globals.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,47 @@ +/* Global External Registers */ +/* ************************* */ + +extern struct MotorFlags + { + unsigned RunMotor :1u; + unsigned Direction :1u; + unsigned SystemTest :1u; + unsigned Delay_Ramps_Flag :1u; + unsigned Motor_Fault_RPM_Flag :1u; + unsigned Motor_Fault_Current_Flag :1u; + unsigned Motor_Fault_Av_Current_Flag :1u; + unsigned Motor_Fault_Ext_Comparator_Flag : 1u; + unsigned unused :8u; + } Flags; + +extern volatile uint16_t FlagsShort; + +extern volatile uint16_t instantaneous_rpm; /* RPM Value without filtering */ +extern volatile uint16_t average_rpm; /* RPM Value with filtering */ +extern volatile uint16_t RPM_target; /* Target RPM from demand pot or I2C */ +extern volatile uint16_t instantaneous_motor_current; /* Motor current without filtering, 0 - 1023*/ +extern volatile uint16_t average_motor_current; /* Motor current with filtering, 0 - 1023 */ +extern volatile uint16_t instantaneous_vbus; /* Vbus voltage without filering, 0 - 1023 */ +extern volatile uint16_t average_vbus; /* Vbus value with filtering, 0 - 1023 */ +extern volatile uint16_t instantaneous_demand_pot; /* Demand pot without filtering, 0 - 1023 */ +extern volatile uint16_t average_demand_pot; /* Demand pot with filtering, 0 - 1023 */ + +extern volatile uint16_t motor_ramp_up_speed; /* Parameter comes from I2C packet */ +extern volatile uint16_t motor_ramp_down_speed; /* Parameter comes from I2C packet */ +extern volatile uint16_t motor_demand_forward_speed; /* Parameter comes from I2C packet */ +extern volatile uint16_t motor_demand_reverse_speed; /* Parameter comes from I2C packet */ +extern volatile uint16_t actual_speed; /* Motor speed controlled via I2C packet */ + + +extern volatile uint16_t HallValue; /* Latest value of hall sensors input */ +extern volatile uint32_t timer3value; /* Last value of period of revolution */ +extern volatile uint32_t timer3avg; /* Average period of rotation */ +extern volatile uint8_t polecount; /* Current pole count as shaft rotates */ +extern volatile uint16_t TMR3_Additional_High; /* Additional word for timer 3 - makes it a 32 bit counter/timer */ + +/* Sequence Table For Hall Effects */ +extern uint16_t StateTableFwd[]; /* Output state table of PWM outputs - Forward direction */ +extern uint16_t StateTableRev[]; /* Output state table of PWM outputs - Forward direction */ + + +extern volatile uint8_t current_state;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_AM_ADC5263_Digital_Pot.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,14 @@ +/* Header File for Digital Potentiometer */ +/* ************************************* */ + + +/* Function Prototypes */ +extern sint32_t RSEDP_AM_Init_AD5263(uint8_t I2C_addr) ; +extern sint32_t RSEDP_AM_Set_AD5263_resistance(uint8_t I2C_addr, uint8_t uiChannel, uint16_t uiResistance_Ohms) ; + + +/* Global Variables */ +extern uint16_t AD5263_default_resistances[AD5263_No_Of_Channels]; + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_AM_MAX1X3X_ADC.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,8 @@ +/* Header file for MAX1x3x Serial ADC */ +/* ********************************** */ + +extern sint32_t RSEDP_AM_Init_MAX1x3x(uint8_t I2C_addr) ; + +extern sint32_t RSEDP_AM_MAX103x_ReadChannel(uint8_t I2C_addr, uint8_t *uiResult, uint8_t uiChannel) ; + +extern sint32_t RSEDP_AM_MAX113x_ReadChannel(uint8_t I2C_addr, uint16_t *uiResult, uint8_t uiChannel) ;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_ASC0_UART0.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,11 @@ +/* UART0 Header files */ +/* ****************** */ + + +extern void setup_UART0(void); +/* Setup and configure the serial port for UART0 */ + + +extern uint16_t UART0_Receieve_Byte(void); +/* Receive a byte from UART0 */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_ASC1_UART1.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,11 @@ +/* UART1 Header files */ +/* ****************** */ + + +extern void setup_UART1(void); +/* Setup and configure the serial port for UART1 */ + + +extern uint16_t UART1_Receieve_Byte(void); +/* Receive a byte from UART1 */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Analogue_Module.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,7 @@ +/* Colective Header File for all Analogue Module Drivers */ +/* ***************************************************** */ + + +#include "RSEDP_AM_ADC5263_Digital_Pot.h" +#include "RSEDP_AM_MAX1X3X_ADC.h" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_BB_24LC32_Serial_EEPROM.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,20 @@ + +/* Function Prototypes Here */ +extern sint32_t RSEDP_BB_setup_24LC32(uint8_t Slave_Address); +/* Configure the I2C EEPROM */ + + +extern sint32_t RSEDP_BB_eeprom_store_byte(uint8_t Slave_Address, sint8_t payload, uint16_t eeaddress); +/* Write one byte to one memory location */ + + +extern sint32_t RSEDP_BB_eeprom_store_bytes(uint8_t Slave_Address, sint8_t *payload, uint8_t qty, uint16_t eeaddress); +/* Called by main to write multiple bytes to the serial EEPROM */ + + +extern sint32_t RSEDP_BB_eeprom_read_byte(uint8_t Slave_Address, sint8_t *read_value, uint16_t eeaddress); +/* Read one byte from one location */ + + +extern sint32_t RSEDP_BB_eeprom_read_bytes(uint8_t Slave_Address, sint8_t *payload, uint16_t qty, uint16_t eeaddress); +/* Read several bytes from one location */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_BB_PCA9675_Serial_Input_Latch.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,29 @@ +/* Header File for the Serial Input Latch PCA9675 Device on the RS-EDP Base Board */ +/* ****************************************************************************** */ + + +extern sint32_t RSEDP_BB_setup_PCA9675(uint8_t Slave_Address); +/* Setup and configure the serial I/O latch for input reading mode */ +/* This function is called to reset the device to configure the I/O to input mode */ +/* The only parameter to be passed is the Slave Address of the device on the board. */ + + +extern sint32_t RSEDP_BB_PCA9675_reset(uint8_t Slave_Address); +/* Reset the device using a general call */ +/* This function uses the general call address feature to reset the device to power on status */ + + + +extern sint32_t RSEDP_BB_PCA9675_write_data(uint8_t Slave_Address, uint8_t port0_payload, uint8_t port1_payload); +/* Write two bytes to the device */ +/* This function writes two bytes, the first to the Port0 and second to Port1 */ + + +extern sint32_t RSEDP_BB_PCA9675_read_data(uint8_t Slave_Address, uint8_t *read_port0, uint8_t *read_port1); +/* Read two bytes from the device */ + +extern sint32_t RS_EDP_BB_Read_DIP_Switch(uint8_t Switch_Number, uint8_t *Switch_Status); +/* Read the switch position - either on or off */ +/* Call this function with a value 1 to 8 for the actual on/off status of the switch */ +/* the retrun status is 'DIP_SWITCH_ON' or 'DIP_SWITCH_OFF' */ +/* you can call this function with 'ALL_DIP_SWITCHES' and the value return is the 8 bit number read by the latch */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Base_Board.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,17 @@ +/* Base Board Hardware Device Drivers */ +/* ********************************** */ + + + +/* Collective file for inclusion of Base Board Device Drivers */ +/* On the base board we have: */ +/* 24LC32 Serial EEPROM */ +/* PCA9675 I/O Expander configures as serial input latch for DIP Switches */ + + +#include "RSEDP_BB_24LC32_Serial_EEPROM.h" +#include "RSEDP_BB_PCA9675_Serial_Input_Latch.h" + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_CNTRL_I2C.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,18 @@ +/* Header File for I2C Routines */ +/* **************************** */ + + +/* Function Prototypes Here */ +extern void setup_CNTRL_I2C_Master_Mode(void); +/* Configuration & setup */ + + + +extern sint32_t CNTRL_I2C_Master_Mode_Transmit(uint8_t targ_address, sint8_t *Tx_Array, uint16_t num_bytes); +/* Send a data packet from this master to a slave device */ + + + +extern sint32_t CNTRL_I2C_Master_Mode_Receive(uint8_t targ_address, sint8_t *Rx_Array, uint16_t num_bytes); +/* Receive a data packet from a slave */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_CNTRL_SPI.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,13 @@ +/* Header file for SPI functions */ +/* ***************************** */ + + +extern void setup_CNTRL_SPI_Master_Mode(void); + + +extern uint8_t CNTRL_SPI_Write_Byte(uint8_t data_byte); + + +extern uint8_t CNTRL_SPI_Read_Byte(void); + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_COM_PCF8583_Real_Time_Clock.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,30 @@ +/* Header File For Real time clock IC */ +/* ********************************** */ + + + +/* Function Prototypes Here */ +extern sint32_t RSEDP_COM_setup_PCF8583(uint8_t Slave_Address, uint8_t mode); /* Setup the device */ +extern sint32_t RSEDP_COM_PCF8583_Read_Status_Register(uint8_t Slave_Address, uint8_t *status_register); /* Read the status register of the device */ +extern sint32_t RSEDP_COM_PCF8583_Write_Status_Register(uint8_t Slave_Address, uint8_t payload); /* Status register write */ + +/* RTC Function */ +extern sint32_t RSEDP_COM_PCF8583_Write_RTC(uint8_t Slave_Address, uint8_t *RTC_Array); /* Write raw data to the RTC device */ +extern sint32_t RSEDP_COM_PCF8583_Read_RTC(uint8_t Slave_Address, uint8_t *RTC_Array); /* Read raw data from the real time clock */ +extern sint32_t RSEDP_COM_PCF8583_Set_Clock(uint8_t Slave_Address, uint8_t hours, uint8_t minutes, uint8_t seconds,uint8_t F24hour_flag, uint8_t AMPM_flag); /* Set the clock only */ +extern sint32_t RSEDP_COM_PCF8583_Set_Date(uint8_t Slave_Address, uint8_t dow, uint8_t day,uint8_t month, uint16_t year); /* Set the date only */ +extern sint32_t RSEDP_COM_PCF8583_Read_Clock(uint8_t Slave_Address, uint8_t *Time_Array); /* Read the time component only */ +extern sint32_t RSEDP_COM_PCF8583_Read_Date(uint8_t Slave_Address, uint8_t *Date_Array); /* Read the date component only */ +extern sint32_t RSEDP_COM_PCF8583_Read_Clock_And_Date(uint8_t Slave_Address, uint8_t *Time_Array,uint8_t *Date_Array); /* Read time and date */ +extern sint32_t RSEDP_COM_PCF8583_Start_Clock(uint8_t Slave_Address); /* Start the clock counting */ +extern sint32_t RSEDP_COM_PCF8583_Stop_Clock(uint8_t Slave_Address); /* Stop the clock */ + +/* Battery Maintained SRAM functions */ +extern sint32_t RSEDP_COM_PCF8583_Read_SRAM(uint8_t Slave_Address, uint8_t *read_data,uint8_t address); /* Read data from the battery maintained SRAM */ +extern sint32_t RSEDP_COM_PCF8583_Write_SRAM(uint8_t Slave_Address, uint8_t payload,uint8_t address); /* Write data to the battery maintained SRAM */ + +/* Print functions for time and date */ +extern void RSEDP_COM_Print_Time(uint8_t *Time_Array); +extern void RSEDP_COM_Print_Date(uint8_t *Date_Array); +extern void RSEDP_COM_Print_Time_Date_Year(uint8_t *RTC_Array); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Comms_Module.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,7 @@ +/* Header File containing all the header files for the devices on the communications module */ +/* **************************************************************************************** */ + + + +#include "RSEDP_COM_PCF8583_Real_Time_Clock.h" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_DIO_PCA9555_Serial_Digital_IO.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,14 @@ +/* Header files for Digital I/O Serial Latches */ +/* ******************************************* */ + + +/* Function Prototypes Here */ +sint32_t RSEDP_DIO_setup_PCA9555(uint8_t Slave_Address, uint8_t Port0_IO_Direction,uint8_t Port1_IO_Direction); +/* Setup the device I/O Direction */ + +sint32_t RSEDP_DIO_PCA9555_Write_Word(uint8_t Slave_Address, uint8_t Port0_Payload, uint8_t Port1_Payload); +/* Write to the I/O pins */ + +sint32_t RSEDP_DIO_PCA9555_Read_Data(uint8_t Slave_Address, uint8_t *Port0_Data, uint8_t*Port1_Data); +/* Read data on the input pins */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Digital_IO_Module.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,5 @@ +/* Colective Header File for alll Digital I/O Module Drivers */ +/* ********************************************************* */ + + +#include "RSEDP_DIO_PCA9555_Serial_Digital_IO.h"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_MC1.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,24 @@ +/* Header file for MC1 Motor Drive module */ +/* ************************************** */ + + +/* Setup the MC1 Board */ +extern void RSEDP_MC1_Setup(void); + + +/* Analogue Levels */ +extern uint16_t RSEDP_MC1_Read_VDCLINK(uint8_t channel); /* Read the filtered 12V DC voltage on the MC1 board via pot down resistors */ +extern uint16_t RSEDP_MC1_Read_VSENSE(uint8_t channel); /* Read the filtered current sense output from the MC1 board */ + + +/* Digital level inputs */ +extern uint8_t RSEDP_MC1_Read_Encoder0_Input(uint8_t pin_option); /* Read the physical level on the Encoder0 input pin on P301 pin 8 on the MC1 board*/ +extern uint8_t RSEDP_MC1_Read_Encoder1_Input(uint8_t pin_option); /* Read the physical level on the Encoder1 input pin on P301 pin 10 on the MC1 board*/ +extern uint8_t RSEDP_MC1_Read_Tacho_Input(uint8_t pin_option); /* Read the physical level on the Tacho Pulses Input pin on P301 pin 6 on the MC1 board */ + + +/* Outputs */ +extern void RSEDP_MC1_Set_Motor_Direction(uint8_t motor_direction, uint8_t pin_option); /* Set the motor direction */ +extern void RSEDP_MC1_Brake(uint8_t brake_onoff, uint8_t pin_option); /* turn the brake on or off */ +extern void RSEDP_MC1_Set_Motor_Speed_Duty(float motor_speed_duty, uint8_t pin_option); /* Power control of motor speed controller using PWM */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Mbed_Complete.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,18 @@ +/* All the header files are called by this one header */ +/* ************************************************** */ + +/* This is the top most parent header file which includes all the other header files associated with the RS-EDP platform */ + +#include "misra_types.h" /* Standard MISRA type defines */ +#include "defines.h" /* General Defines used by the modules */ +#include "RSEDP_Slave_Address_Defines.h" /* If you change the hardware I2C address of any of the devices on the modules then you must reflect the new I2C address in this header file */ + + +#include "RSEDP_Mbed_Module.h" /* all the low level peripheral drivers on te mbed module - IO ports, UART, SPI, I2C etc */ +#include "RSEDP_Base_Board.h" /* All the base board functions - EEPROM and erial latch */ +#include "RSEDP_Comms_Module.h" /* Functions to control the real time clock */ +#include "RSEDP_Digital_IO_Module.h" /* All the functions to control the serial input and output latches */ +#include "RSEDP_Analogue_Module.h" /* Functions to control digital pot and serial ADC */ +#include "RSEDP_MC1.h" /* Function relating to the Brushed DC Motor Drive module MC1 */ + +#include "RSEDP_Test.h" /* Test function to exercise all of the above */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Mbed_Module.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,11 @@ +/* This is a parent header file for the peripherals on the mbed module */ +/* ******************************************************************* */ + +/* This one header file will encompass all of the low level drivers for the mbed peripherals */ + +#include "mbed_Port_Structure.h" +#include "RSEDP_CNTRL_I2C.h" +#include "RSEDP_CNTRL_SPI.h" +#include "RSEDP_ASC0_UART0.h" +#include "RSEDP_ASC1_UART1.h" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Slave_Address_Defines.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,58 @@ +/* Slave Address Header File */ + + + +#define MICROCHIP_MOTOR_DRIVER_BASE 0x40 + /* Microchip Twin Motor Drive Module RD-EDP-AM-MC2 */ + /* 0x40 - 7 bit */ + /* Range is 0x40 - 0x47 as there may be 4 modules per base board */ + /* This device is used to define the Microchip dsPIC33FJ128MC804 I2C Slave Address */ + /* Upto 6 dsPIC devices can be populated (3 modules) on the motor drive board */ + /* Therefore the 7 bit address range is 0x40 - 0x45 */ + /* The link options on the module provide additional Slave address information */ + +/* Defines the range of the dsPIC Slave Address's. The base address is configured above */ +/* As we can have up to 8 dsPICs in the system, we need to specify the range of address's */ +#define DSPIC_SLAVE_ADDRESS_MIN (MICROCHIP_MOTOR_DRIVER_BASE) /* min is 7 bit base of 112 */ +#define DSPIC_SLAVE_ADDRESS_MAX ((MICROCHIP_MOTOR_DRIVER_BASE) +7) /* max is 7 bit base of 112 plus the DIP switch/solder bridge settings on the PCB 0 - 7 */ + + +#define PCA9675_BASE_BOARD 0x20 // 0x20 - 7 bit + /* This device is on the base board and is a serial I/O latch connected to the DIP Switch */ + + +#define M24C32_BASE_BOARD 0x51 // 0x51 - 7 bit + /* This device is a serial EEPROM device which is connected to the base board */ + /* The actual slave address also has three low order bits to be added */ + /* These bits are b1,b2,b3 within the byte */ + /* These bits are derived from the external A0,A1 and A2 pins on the device */ + /* Therefore the slave address's are 0xa0, 0xa2, 0xa4,0xa6,0xa8,0xaa, 0xac,0xae */ + + +#define PCF8583_COMMS_MODULE 0x50 // 0x50 - 7 bit +/* The actual slave address also has three low order bits to be added */ +/* These bits are b1,b2,b3 within the byte*/ +/* These bits are derived from the external A0,A1 and A2 pins on the device */ +/* Therefore the slave address's are 0xa0, 0xa2, 0xa4,0xa6,0xa8,0xaa, 0xac,0xae */ + + + +#define PCA9555_DIGITAL_IO_OUT 0x23 // 0x23 - 7 bit + /* The actual slave address also has three low order bits to be added */ + /* These bits are a0,a1,a2 within the byte*/ + /* These bits are derived from the external A0,A1 and A2 pins on the device */ + /* Therefore the 7 bit slave address range is 0x20 to 0x27 */ + + +#define PCA9555_DIGITAL_IO_IN 0x22 // 0x22 - 7 bit + /* This is the hardware configured 0x22 7 bit Slave Address of this perihperal */ + + +#define MAX1X3X_ANALOGUE_ADC 0x65 // 0x65 - 7 bit + /* This is the slave address of the MAX1038 on the Analogue Module PCB */ + + +#define AD5263_ANALOGUE_DIGITAL_POT 0x2c // 0x2c - 7 bit + /* This is the slave address of the digtial Potentiometer, AD5263 on the anlogue module */ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Test.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,6 @@ + + +extern void RSEDP_test_all(void); + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/RSEDP_Test_MC2.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,8 @@ +/* Header File For Master Mode System Controller Test Suite */ +/* ******************************************************** */ + + + +extern void I2C_MMSC_Test_Suite(void); +/* This is a suites of test to allow a dsPIC to set itself up as an I2C Master Controller */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/defines.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,185 @@ +/* Defines */ + + +/* Software Revision Number */ +#define FIRMWARE_VERSION 3 + +/* Module Inclusion */ +#define YES 1 +#define NO 0 +#define ANALOGUE_MODULE_FITTED YES +#define DIGITAL_IO_MODULE_FITTED YES +#define COMMS_MODULE_FITTED YES +#define MOTOR_MC1_MODULE_FITTED YES +#define MOTOR_MC2_MODULE_FITTED YES + + + +/* LED On/OFF Defines */ +#define LED_ON 1 +#define LED_OFF 0 + + +/* DIP SWITCH on the base board defines */ +#define DIP_SWITCH_CLOSED 1 /* This is the value you return when the DIP switch is in the closed position */ +#define DIP_SWITCH_OPEN 0 /* This is the value you return when the DIP switch is in the open position */ +#define SWITCH_ON 0 /* This is the logic level you see when the DIP switch is closed (a short to ground produces a logic zero on the pin) */ +#define SWITCH_OFF 1 /* This is the logic level you see when the DIP switch is open (a pull up to Vcc produces a logic one on the pin) */ +#define ALL_DIP_SWITCHES 10 /* This is the value used when you need to read all of the switches */ + +/* I2C Defines */ +#define ACK 0 + + +/* Motor Drive MC2 Module Defines */ +/* This block of 3 pairs of defines relates to the FLAGS used in the Flags structure */ +#define CLOCKWISE 1u +#define COUNTER_CLOCKWISE 0u + +#define FAULT_PRESENT 0u +#define NO_FAULT_PRESENT 1u + +/* Machine States for I2C Control of the Motor Drive module MC2 */ +#define STOPPED 0u /* Motor is STOPPED */ +#define STOPPING 1u /* Motor is decelerating towards the stop */ +#define NEW_MOTOR_DEMAND_FORWARD 2u /* New demand speed receieved for the forward direction */ +#define NEW_MOTOR_DEMAND_REVERSE 3u /* New demand speed receieved for the reverse direction */ +#define NORMAL_RUNNING 4u /* Motor is running normally and has achieved target speed */ +#define ROTATE_X_QUAD_COUNTS 5u /* The PMSM has receieved a rotate quad counts command and is running through this count sequence */ +#define LAST_REVOLUTION 6u /* The motor is going through its final approach sequence, and is usually in its last revolution before stopping */ +#define GOTO_HOME 7u /* the motor is trying to find its home sensor, so it can reference itself */ + +#define MOTOR_RUNNING 1u +#define MOTOR_STOPPED 0u + + + +/* Analogue module */ +#define ADC_8BIT 8 +#define ADC_10BIT 10 +#define ADC_BITSIZE ADC_8BIT /* change this line to accomodate ADC size - two settings either ADC_8BIT or ADC_10BIT */ + +/* AD5623 Digital Potentiometer Commands */ +/* These are used in the instruction byte */ +#define AD5263_RDAC_A1 0x40 +#define AD5263_RDAC_A0 0x20 +#define AD5263_RDAC_Ch1 0x00 +#define AD5263_RDAC_Ch2 0x20 +#define AD5263_RDAC_Ch3 0x40 +#define AD5263_RDAC_Ch4 0x60 + +#define AD5263_RDAC_Midscale_Reset 0x10 +#define AD5263_RDAC_Shutdown 0x08 + +#define AD5263_RDAC_O2_UserBit 0x04 +#define AD5263_RDAC_O1_UserBit 0x02 + +#define AD5263_No_Of_Channels 4 + +/* Potentiometer Characteristics */ +#define AD5263_Max_Resistance 50000 /* 50kOhms */ +#define AD5263_Resolution 256 + +#define AD5263_RDAC1_Default_Resistance 6800 +#define AD5263_RDAC2_Default_Resistance 12000 + +#define AD5263_RDAC3_Default_Resistance 6800 +#define AD5263_RDAC4_Default_Resistance 12000 + + + + + +/* MAX1038 ADC Register Bit Definitions */ +/* Definitions For SETUP Byte */ +#define MAX1x3x_SETUP_NO_RST 0x02 +#define MAX1x3x_SETUP_RST 0x00 +#define MAX1x3x_SETUP_BiPol 0x04 +#define MAX1x3x_SETUP_UniPol 0x00 +#define MAX1x3x_SETUP_ExtCLK 0x08 +#define MAX1x3x_SETUP_IntCLK 0x00 +#define MAX1x3x_SETUP_SEL0 0x10 +#define MAX1x3x_SETUP_SEL1 0x20 +#define MAX1x3x_SETUP_SEL2 0x40 +#define MAX1x3x_SETUP_REG 0x80 /* 0x80 MSB =1 means this is a Setup byte */ + +#define MAX1x3x_SETUP_SEL_EXT_Ref_AN11_AlwaysOff (0x2<<4) +#define MAX1x3x_SETUP_SEL_INT_Ref_AN11RefIn_AutoSHD (0x4<<4) +#define MAX1x3x_SETUP_SEL_INT_Ref_AN11_AlwaysOn (0x5<<4) +#define MAX1x3x_SETUP_SEL_INT_Ref_AN11RefOut_AlwaysOn (0x6<<4) + +/* Definition For CONFIG Byte */ +#define MAX1x3x_CONFIG_SingleEnded 0x01 +#define MAX1x3x_CONFIG_CS0 0x02 +#define MAX1x3x_CONFIG_CS1 0x04 +#define MAX1x3x_CONFIG_CS2 0x08 +#define MAX1x3x_CONFIG_CS3 0x10 +#define MAX1x3x_CONFIG_SCAN0 0x20 +#define MAX1x3x_CONFIG_SCAN1 0x40 +#define MAX1x3x_CONFIG_REG 0x00 /* 0x00 MSB = 0 means this is a Config byte */ + +#define MAX1x3x_CONFIG_SingleChannel_x8 (0x01<<5) +#define MAX1x3x_CONFIG_SingleChannel (0x03<<5) + +#define MAX1x3x_CONFIG_ConvCh0 0x00 +#define MAX1x3x_CONFIG_ConvCh1 (0x01<<1) +#define MAX1x3x_CONFIG_ConvCh2 (0x02<<1) +#define MAX1x3x_CONFIG_ConvCh3 (0x03<<1) +#define MAX1x3x_CONFIG_ConvCh4 (0x04<<1) +#define MAX1x3x_CONFIG_ConvCh5 (0x05<<1) +#define MAX1x3x_CONFIG_ConvCh6 (0x06<<1) +#define MAX1x3x_CONFIG_ConvCh7 (0x07<<1) +#define MAX1x3x_CONFIG_ConvCh8 (0x08<<1) +#define MAX1x3x_CONFIG_ConvCh9 (0x09<<1) +#define MAX1x3x_CONFIG_ConvCh10 (0x0A<<1) +#define MAX1x3x_CONFIG_ConvCh11 (0x0B<<1) + +#define MAX1x3x_No_Of_Channels 12 + + + + +/* MC1 motor Control I/O Module Defines */ +#define AN0 0 +#define AN2 2 +#define AN4 4 +#define AN10 10 +#define AN12 12 +#define AN14 14 + +#define EVM5_GPIO47 0 /* used for Encoder0 and Tacho Pulse inputs */ +#define EVG6_GPIO52 1 + +#define EVM6_GPIO49 0 /* used for Encoder1 input */ +#define EVG7_GPIO54 1 + +#define EVM4_GPIO45 0 /* Used for reading motor direction */ +#define EVG16_GPIO64 1 + +#define EVG1_GPIO42 0 /* Used for writing motor direction */ +#define EVG5_GPIO50 1 + +#define EVG0_GPIO40 0 /* Used for PWM speed duty cycle */ +#define EVG4_GPIO48 1 + +#define GPIO0 0 /* Used for motor brake signal */ +#define GPIO1 1 + +#define FORWARD 0 +#define REVERSE 1 + +#define BRAKE_ON 1 +#define BRAKE_OFF 0 + +#define CURRENT_TRANSFER_RATIO 6.0E-04f /* The LMD18200 has a 400uA per ampere CTR .ie 1A of motor current produces 400uA of current sense */ +#define MOTOR_CURRENT_SENSE_RESISTOR 2.2e03f /* Value in ohms */ + +#define VSENSE_DIVISOR 0.248f /* R207 / (R207+R205) */ + + + + +/* Test Module */ +#define EEPROM_TEST_BYTE 0x3c + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/mbed_Port_Structure.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,49 @@ +/* Header Files for Port Structure */ +/* ******************************* */ + + + +extern void setup_mbed_ports(void); + + +/* Configure the I/O Port Structure */ +extern DigitalOut User_Led1; +extern DigitalOut User_Led2; +extern DigitalOut User_Led3; +extern DigitalOut User_Led4; + +extern DigitalIn DigitalIn_Pin8; +extern DigitalIn DigitalIn_Pin11; +extern DigitalIn DigitalIn_Pin26; +extern DigitalIn DigitalIn_Pin30; + +extern DigitalOut DigitalOut_Pin14; +extern DigitalOut DigitalOut_Pin19; +extern DigitalOut DigitalOut_Pin24; + + +/* Serial interface via USB */ +extern Serial pc; + + +/* SPI Interface to CNTRL SPI and MCI Pins on RS-EDP */ +extern SPI CNTRL_spi; +extern SPI MCI_spi; + + +/* I2C Interface to CNTRL I2C on RS-EDP */ +extern I2C CNTRL_i2c; + +/* Serial interface to ASC0/UART0 on RS-EDP */ +extern Serial UART0; +extern Serial UART1; + + +/* ADC functions */ +extern AnalogIn AD0; +extern AnalogIn AD1; +extern AnalogIn AD2; +extern AnalogIn AD3; + +extern PwmOut PwmOut_Pin21; +extern PwmOut PwmOut_Pin23;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HeaderFiles/misra_types.h Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,32 @@ +/* Hitex Standard Header File */ +/* Types As Recommended By MISRA */ + + + +/* Bytes (8bit length) */ +typedef unsigned char uint8_t; +typedef char sint8_t; + +/* Half Words (16bit lengths) */ +typedef unsigned short uint16_t; +typedef short sint16_t; + +/* Words (32bit lengths) */ +/* Also int */ +typedef unsigned int uint32_t; +typedef long sint32_t; + +/* Double Words */ +/* Also long long and long double */ +typedef unsigned long long uint64_t; +typedef long long sint64_t; + + +/* + Constants should use the following suffixes also + +u - Unsigned +f - floating +L - Long double (64bit) + +*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/MC2_Motor_Driver_I2C_Master.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,632 @@ +/* Motor Drive Master Functions */ +/* **************************** */ + + +/* This module allows the MCU to act as a Master Controller in the system */ +/* It transmitts data down to the other Slave Modules and can also read parameters from the other dsPIC Slave Modules */ + + + + + +/* Includes Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */ + +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ +#include "RS-EDP_AM_MC2_Globals.h" /* Global variables referenced here for MC2 Motor Drive Module */ + + + +/* Function Prototypes */ +/* Write Functions */ +uint8_t I2C0_dsPIC_Reset(uint8_t slave_address); +uint8_t I2C0_dsPIC_Emergency_Stop(uint8_t slave_address); +uint8_t I2C0_dsPIC_Normal_Stop(uint8_t slave_address); +uint8_t I2C0_dsPIC_Ping(uint8_t slave_address); +uint8_t I2C0_dsPIC_Set_Motor_Speed_Demand_Forward(uint8_t slave_address, uint16_t motor_speed_Demand); +uint8_t I2C0_dsPIC_Set_Motor_Speed_Demand_Reverse(uint8_t slave_address, uint16_t motor_speed_Demand); +uint8_t I2C0_dsPIC_Set_Ramp_Up_Speed(uint8_t slave_address, uint16_t ramp_up_speed); +uint8_t I2C0_dsPIC_Set_Ramp_Down_Speed(uint8_t slave_address, uint16_t ramp_down_speed); +uint8_t I2C0_dsPIC_Set_Motor_Direction(uint8_t slave_address, uint8_t direction); +uint8_t I2C0_dsPIC_Start_Motor_Rotation(uint8_t slave_address); + +uint8_t I2C0_dsPIC_Set_Rotation_Counts(uint8_t slave_address, uint32_t motor_rotation_counts); +static uint8_t I2C0_dsPIC_Set_Rotation_Counts_High_Word(uint8_t slave_address, uint16_t motor_rotation_counts_high); +static uint8_t I2C0_dsPIC_Set_Rotation_Counts_Low_Word(uint8_t slave_address, uint16_t motor_rotation_counts_low); +uint8_t I2C0_dsPIC_Goto_Home(uint8_t slave_address, uint8_t home_direction, uint8_t home_speed); + + +/* Read Functions */ +uint8_t I2C0_dsPIC_Read_Tacho_Speed_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Tacho_Speed_Average(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Motor_Current_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Motor_Current_Average(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Vbus_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Vbus_Average(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Demand_Pot_Instantaneous(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Demand_Pot_Average(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Hall_Sensor_Positions(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Motor_Status(uint8_t slave_address, uint8_t *rx_array); +uint8_t I2C0_dsPIC_Read_Maximum_RPM(uint8_t slave_address, uint8_t *rx_array); + +uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter(uint8_t slave_address, uint8_t *rx_array); +static uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter_High(uint8_t slave_address, uint8_t *rx_array); +static uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter_Low(uint8_t slave_address, uint8_t *rx_array); + + + +/* Reset A Slave Unit */ +uint8_t I2C0_dsPIC_Reset(uint8_t slave_address) + { + /* 00 - Reset The Processor */ + /* data bytes to follow will be */ + /* databyte0 - 0x55 */ + /* databyte1 - 0xaa */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {0x00u, 0x55u, 0xaau}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Generate an emergency Stop */ +uint8_t I2C0_dsPIC_Emergency_Stop(uint8_t slave_address) + { + /* 01 - Emergency Stop */ + /* data bytes to follow will be */ + /* databyte0 - 0x00 */ + /* databyte1 - 0x00 */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {0x01u, 0x00u, 0x00u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Generate a normal stop condition */ +uint8_t I2C0_dsPIC_Normal_Stop(uint8_t slave_address) + { + /* 02 - Normal Stop */ + /* data bytes to follow will be */ + /* databyte0 - 0x00 */ + /* databyte1 - 0x00 */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {0x02u, 0x00u, 0x00u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + +/* Ping the Processor to see if it is attached to the bus */ +uint8_t I2C0_dsPIC_Ping(uint8_t slave_address) + { + /* 03 - Ping Stop */ + /* data bytes to follow will be */ + /* databyte0 - don't care */ + /* databyte1 - don't care */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {0x03u, 0x00u, 0x00u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Set the motor speed demand Forward */ +uint8_t I2C0_dsPIC_Set_Motor_Speed_Demand_Forward(uint8_t slave_address, uint16_t motor_speed_demand) + { + /* 10 - Set motor Speed Demand Forward */ + /* data bytes to follow will be a 16bit value in the range 0 - 1023 */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {10u, 0x00u, 0x00u}; + Tx_Array[1] = (uint8_t)(motor_speed_demand / 256u); + Tx_Array[2] = (uint8_t)(motor_speed_demand % 256u); + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Set the motor speed demand Reverse */ +uint8_t I2C0_dsPIC_Set_Motor_Speed_Demand_Reverse(uint8_t slave_address, uint16_t motor_speed_demand) + { + /* 11 - Set motor Speed Demand Forward */ + /* data bytes to follow will be a 16bit value in the range 0 - 1023 */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {11u, 0x00u, 0x00u}; + Tx_Array[1] = (uint8_t)(motor_speed_demand / 256u); + Tx_Array[2] = (uint8_t)(motor_speed_demand % 256u); + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Set the ramp up speed */ +uint8_t I2C0_dsPIC_Set_Ramp_Up_Speed(uint8_t slave_address, uint16_t ramp_up_speed) + { + /* 12 - Set Ramp Up Speed */ + /* data bytes to follow will be a 16bit value in the range 0 - 1023 */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {12u, 0x00u, 0x00u}; + Tx_Array[1] = (uint8_t)(ramp_up_speed / 256u); + Tx_Array[2] = (uint8_t)(ramp_up_speed % 256u); + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Set the ramp down speed */ +uint8_t I2C0_dsPIC_Set_Ramp_Down_Speed(uint8_t slave_address, uint16_t ramp_down_speed) + { + /* 13 - Set Ramp Up Speed */ + /* data bytes to follow will be a 16bit value in the range 0 - 1023 */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {13u, 0x00u, 0x00u}; + Tx_Array[1] = (uint8_t)(ramp_down_speed / 256u); + Tx_Array[2] = (uint8_t)(ramp_down_speed % 256u); + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Set the motor Direction */ +uint8_t I2C0_dsPIC_Set_Motor_Direction(uint8_t slave_address, uint8_t direction) + { + /* 14 - Set Motor Direction */ + /* data bytes to follow will be */ + /* databyte0 - don't care */ + /* databyte1 - direction */ + /* where direction = 0 - forward */ + /* where direction = 1 - reverse */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {14u, 0x00u, 0x00u}; + + Tx_Array[2] = direction; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Motor Start */ +uint8_t I2C0_dsPIC_Start_Motor_Rotation(uint8_t slave_address) + { + /* 20 - Start Rotation */ + /* data bytes to follow will be */ + /* databyte0 - 0 */ + /* databyte1 - 0 */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {20u, 0x00u, 0x00u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + + +/* Send a 32byte Counts number to the slave peripheral */ +uint8_t I2C0_dsPIC_Set_Rotation_Counts(uint8_t slave_address, uint32_t motor_rotation_counts) + { + /* Set Rotation Counts */ + /* data bytes to follow will be a 32bit value - sent as two packets */ + + uint8_t Ack_Error = 0u; + + Ack_Error = I2C0_dsPIC_Set_Rotation_Counts_High_Word(slave_address, (uint16_t)(motor_rotation_counts >> 16u)); + + if (Ack_Error == 0u) + { + Ack_Error = I2C0_dsPIC_Set_Rotation_Counts_Low_Word(slave_address, (uint16_t)(motor_rotation_counts)); + } + + return Ack_Error; + } + +/* Send the first 16 bits count data across the I2C bus to the slave device */ +static uint8_t I2C0_dsPIC_Set_Rotation_Counts_High_Word(uint8_t slave_address, uint16_t motor_rotation_counts_high) + { + /* 21 - Set Rotation Counts High word */ + /* data bytes to follow will be a 16bit value- High word of the 32bit variables */ + /* databyte0 - highbyte (msb byte of the 32 bit word) */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {21u, 0x00u, 0x00u}; + Tx_Array[1] = (uint8_t)(motor_rotation_counts_high / 256u); + Tx_Array[2] = (uint8_t)(motor_rotation_counts_high % 256u); + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + +/* Send the lower order 16 bit count data across the I2C network to the slave.*/ +static uint8_t I2C0_dsPIC_Set_Rotation_Counts_Low_Word(uint8_t slave_address, uint16_t motor_rotation_counts_low) + { + /* 22 - Set Rotation Counts Low word */ + /* data bytes to follow will be a 16bit value- Low word of the 32bit variables */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {22u, 0x00u, 0x00u}; + Tx_Array[1] = (uint8_t)(motor_rotation_counts_low / 256u); + Tx_Array[2] = (uint8_t)(motor_rotation_counts_low % 256u); + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + } + + + +/* Goto home position */ +uint8_t I2C0_dsPIC_Goto_Home(uint8_t slave_address, uint8_t home_direction, uint8_t home_speed) + { + /* 24 - Goto Home Position */ + /* data bytes to follow will be */ + /* databyte0 - direction */ + /* databyte1 - home_speed (8 bit limited 1-255) */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[3] = {24u, 0u, 0u}; + Tx_Array[1] = home_direction; + Tx_Array[2] = home_speed; + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 3u); + return Ack_Error; + + } + + + + + + +/* Read Functions Below Here */ + +/* Read The Instantaneous RPM figure */ +uint8_t I2C0_dsPIC_Read_Tacho_Speed_Instantaneous(uint8_t slave_address, uint8_t *rx_array) + { + /* 50 - Read tacho speed instantaneous RPM */ + /* data bytes to follow will be the instantaneous RPM data */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {50u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + + } + return Ack_Error; + } + + + +/* Read The Average RPM figure */ +uint8_t I2C0_dsPIC_Read_Tacho_Speed_Average(uint8_t slave_address, uint8_t *rx_array) + { + /* 51 - Read tacho speed average RPM */ + /* data bytes to follow will be the average RPM data */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {51u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + + + +/* Read The Instantaneous Motor Current */ +uint8_t I2C0_dsPIC_Read_Motor_Current_Instantaneous(uint8_t slave_address, uint8_t *rx_array) + { + /* 52 - Read Motor Current Instantaneous in mA */ + /* data bytes to follow will be the instantaneous motor current in mA */ + /* databyte0 - highbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {52u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + } + return Ack_Error; + } + + + +/* Read The Average Motor Current */ +uint8_t I2C0_dsPIC_Read_Motor_Current_Average(uint8_t slave_address, uint8_t *rx_array) + { + /* 53 - Read Motor Current Average */ + /* data bytes to follow will be the computed average motor current in mA */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {53u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + + + } + + +/* Measure the Vbus Bridge voltage */ +uint8_t I2C0_dsPIC_Read_Vbus_Instantaneous(uint8_t slave_address, uint8_t *rx_array) + { + /* 54 - Read Vbus Voltage Instantaneous */ + /* data bytes to follow will be the instantaneous Vbus Power Supply Voltage to the bridge in mV */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {54u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + + +/* Measure the Vbus Bridge Voltage Average */ +uint8_t I2C0_dsPIC_Read_Vbus_Average(uint8_t slave_address, uint8_t *rx_array) + { + /* 55 - Read Vbus Voltage Instantaneous */ + /* data bytes to follow will be the computed average Vbus Power Supply Voltage to the bridge in mV */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {55u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + +/* Measure The Demand Pot Instantaneous */ +uint8_t I2C0_dsPIC_Read_Demand_Pot_Instantaneous(uint8_t slave_address, uint8_t *rx_array) + { + /* 56 - Read Demand Pot instantaneous */ + /* data bytes to follow will be the instanteneous Pot Demand setting in the range 0 - 1023 */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {56u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + +uint8_t I2C0_dsPIC_Read_Demand_Pot_Average(uint8_t slave_address, uint8_t *rx_array) + { + /* 57 - Read Demand Pot average */ + /* data bytes to follow will be the average Pot Demand setting in the range 0 - 1023 */ + /* databyte0 - highbyte */ + /* databyte1 - lowbyte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {57u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + + +/* Read The Hall Effect Sensors */ +uint8_t I2C0_dsPIC_Read_Hall_Sensor_Positions(uint8_t slave_address, uint8_t *rx_array) + { + /* 58 - Read Hall Sensors Positions */ + /* data bytes to follow will be the hall sensor reading */ + /* databyte0 - 0 */ + /* databyte1 - hall effect sensors */ + /* where halleffect reading in bit form is 0b 0000 0ABC, where A is the logic level on the Hall Input A ('1' or '0') etc */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {58u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + + +/* Read The Fault Status Register */ +uint8_t I2C0_dsPIC_Read_Motor_Status(uint8_t slave_address, uint8_t *rx_array) + { + /* 59 - Read Motor Status - run/stop/direction/Faults etc */ + /* data bytes to follow will be the Fault Status Register */ + /* databyte0 - Flags Status Register - high */ + /* databyte1 - Flags Status Register - low */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {59u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + + +/* Read the Maximum RPM Information */ +uint8_t I2C0_dsPIC_Read_Maximum_RPM(uint8_t slave_address, uint8_t *rx_array) + { + /* 60 - Read The Maxium RPM information */ + /* data bytes to follow will be the Maximum RPM of the motor */ + /* databyte0 - Max RPM - high byte */ + /* databyte1 - Max RPM - low byte */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1] = {60u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + +/* Read The 32bit Quadrature Encoder Counter */ +uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter(uint8_t slave_address, uint8_t *rx_array) + { + uint8_t Ack_Error = 0u; + + Ack_Error = I2C0_dsPIC_Read_Quad_Encoder_Counter_High(slave_address, rx_array); + if (Ack_Error == 0u) + { + Ack_Error = I2C0_dsPIC_Read_Quad_Encoder_Counter_Low(slave_address, (rx_array + 2u)); + } + return Ack_Error; + } + + +/* Read The High Word of the 32ibt Quadrature Encoder */ +static uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter_High(uint8_t slave_address, uint8_t *rx_array) + { + /* 61 - Read Quadrature Counter (high byte) */ + /* data bytes to follow will be the Quadrature Encoder high bytes */ + /* databyte0 - Quadrature Encoder Counter - High Byte (byte3 MSB) */ + /* databyte1 - Quadrature Encoder Counterr - Low byte (byte2) */ + /* Reading this byte will freeze the low byte, allwoing glitchless reading of the 32 bit counter */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1u] = {61u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + +/* Read The Low Word of the 32bit Quadrature Encoder */ +static uint8_t I2C0_dsPIC_Read_Quad_Encoder_Counter_Low(uint8_t slave_address, uint8_t *rx_array) + { + /* 62 - Read Quadrature Counter (low bytes) */ + /* data bytes to follow will be the Quadrature Encoder low bytes */ + /* databyte0 - Quadrature Encoder Counter - High Byte (byte3 MSB) */ + /* databyte1 - Quadrature Encoder Counterr - Low byte (byte2) */ + /* Reading this byte will unlock the 32 bit counter. Read the high byte first. */ + /* Note: It is important to read the high byte first */ + uint8_t Ack_Error = 0u; + sint8_t Tx_Array[1u] = {62u}; + sint8_t Rx_Temp[2] = {0u, 0u}; + + Ack_Error = CNTRL_I2C_Master_Mode_Transmit(slave_address, Tx_Array, 1u); /* Send the command Byte */ + + if (Ack_Error == 0u) + { + Ack_Error = CNTRL_I2C_Master_Mode_Receive(slave_address, Rx_Temp, 2u); /* Read the return data */ + rx_array[0] = (uint8_t) Rx_Temp[0]; + rx_array[1] = (uint8_t) Rx_Temp[1]; + } + return Ack_Error; + } + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_AM_ADC5263_Digital_Pot.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,79 @@ +/* Source Driver File for the AD5263 Digital Potentiometer */ +/* ******************************************************* */ + +/* Version 1.00 */ +/* Last Ammend Date: 23/6/09 */ + + +#define _AD5263_ + + + +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */ + +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ + + + + + + + +/* Function Prototypes */ +sint32_t RSEDP_AM_Init_AD5263(uint8_t I2C_addr) ; +sint32_t RSEDP_AM_Set_AD5263_resistance(uint8_t I2C_addr, uint8_t uiChannel, uint16_t uiResistance_Ohms) ; + + +/* Global Variables */ +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 } ; + + + + + + +/* Reset and initialise AD5623 RDAC */ +sint32_t RSEDP_AM_Init_AD5263(uint8_t I2C_addr) + { + sint8_t uiSetup_byte = 0; + uint8_t uiChannel_no = 0; + sint32_t Ack_Status = 0; + + for(uiChannel_no = 0; uiChannel_no < AD5263_No_Of_Channels ; uiChannel_no++) + { + /* Create Setup Byte */ + /* Set channel 0 to midscale */ + uiSetup_byte = AD5263_RDAC_Midscale_Reset | (uiChannel_no << 5) ; + + /* Send Command */ + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiSetup_byte, 1) ; + } + return Ack_Status; + } + + + +/* Convert a raw value in Ohms to a resistance */ +sint32_t RSEDP_AM_Set_AD5263_resistance(uint8_t I2C_addr, uint8_t uiChannel, uint16_t uiResistance_Ohms) + { + sint32_t Ack_Status = 0; + uint16_t uiScaled_resistance = 0; + sint8_t uiMessage[3] = {0,0,0}; + + /* Set channel */ + uiMessage[0] = ((uiChannel-1) << 5) ; + + /* Convert resistance in Ohms to a number of steps */ + uiScaled_resistance = ((uint32_t)uiResistance_Ohms * AD5263_Resolution)/AD5263_Max_Resistance ; + uiMessage[1] = uiScaled_resistance ; + + /* Send command */ + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, uiMessage, 2) ; + return Ack_Status; + } + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_AM_MAX1X3X_ADC.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,131 @@ +/* Driver for the MAX1x3x Serial ADC */ +/* ********************************* */ + +/* Version 2.00 */ +/* Last Ammend Date: 23/6/09 */ + + +#define _MAX1038_ + + + +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */ + +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ + + + + +/* Function Prototypes */ +sint32_t RSEDP_AM_Init_MAX1x3x(uint8_t I2C_addr) ; +sint32_t RSEDP_AM_MAX103x_ReadChannel(uint8_t I2C_addr, uint8_t *uiResult, uint8_t uiChannel) ; +sint32_t RSEDP_AM_MAX113x_ReadChannel(uint8_t I2C_addr, uint16_t *uiResult, uint8_t uiChannel) ; + + + + + + +/* Reset and initialise MAX1x3x ADC */ +sint32_t RSEDP_AM_Init_MAX1x3x(uint8_t I2C_addr) + { + sint32_t Ack_Status = 0; + sint8_t uiSetup_byte = 0; + sint8_t uiConfig_byte = 0; + sint8_t uiMessage[3] = {0,0,0}; + + + /* Create Setup Byte for REST */ + uiSetup_byte = MAX1x3x_SETUP_RST | MAX1x3x_SETUP_REG; + + /* Send Reset Command */ + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiSetup_byte, 1) ; + + /* Create Setup Byte */ + /* Internal reference always on and ADC11=analogue input and not Vref, Internal Clock */ + uiSetup_byte = MAX1x3x_SETUP_REG | MAX1x3x_SETUP_SEL_INT_Ref_AN11_AlwaysOn | MAX1x3x_SETUP_IntCLK | MAX1x3x_SETUP_UniPol | MAX1x3x_SETUP_NO_RST; + + /* Create CONFIG Byte */ + /* Convert single ended unipolar, channel 0 initially */ + uiConfig_byte = MAX1x3x_CONFIG_REG | MAX1x3x_CONFIG_SingleEnded | MAX1x3x_CONFIG_ConvCh0 ; + + uiMessage[0] = uiSetup_byte ; + uiMessage[1] = uiConfig_byte ; + + /* Send */ + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, uiMessage, 2) ; + } + return Ack_Status; + } + + + + +/* Reads a single channel MAX103x I2C ADC passed as a parameter */ +/* returns a pointer to the 8-bit result */ +sint32_t RSEDP_AM_MAX103x_ReadChannel(uint8_t I2C_addr, uint8_t *uiResult, uint8_t uiChannel) + { + sint32_t Ack_Status = 0; + sint8_t uiConfig_byte = 0; + sint8_t uiResult_value = 0; + uint8_t uiCorrected_Channel = 0; + + + /* Set which channel to convert */ + /* The pin out for MAX1038 is different from MAX1138 */ + /* The channel numbers 0-7 are reversed on the MAX1038. The PCB has been laid out for the MAX1138 */ + uiCorrected_Channel = uiChannel; + if (uiChannel < 8) + { + uiCorrected_Channel = (7 - uiChannel); + } + uiConfig_byte = MAX1x3x_CONFIG_REG | MAX1x3x_CONFIG_SingleEnded | (uint8_t)(uiCorrected_Channel << 1) | MAX1x3x_CONFIG_SingleChannel ; + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiConfig_byte, 1) ; + + /* Read Result */ + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(I2C_addr, &uiResult_value , 1) ; + } + + + /* Return result to caller */ + *uiResult = uiResult_value ; + return Ack_Status; + } + + + + +/* Reads a single channel MAX113x I2C ADC passed as a parameter */ +/* returns a pointer to the 16-bit result */ +sint32_t RSEDP_AM_MAX113x_ReadChannel(uint8_t I2C_addr, uint16_t *uiResult, uint8_t uiChannel) + { + sint32_t Ack_Status = 0; + sint8_t uiConfig_byte = 0; + + union BWL { sint8_t uiBytes[4] ; uint16_t uiWords[2] ; uint32_t uiLong ; } ; + union BWL sResult ; + + + /* Set which channel to convert */ + uiConfig_byte = MAX1x3x_CONFIG_REG | MAX1x3x_CONFIG_SingleEnded | (uint8_t)(uiChannel << 1) | MAX1x3x_CONFIG_SingleChannel ; + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(I2C_addr, &uiConfig_byte, 1) ; + + /* Read Result */ + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(I2C_addr, &sResult.uiBytes[0] , 2) ; + } + + /* Return result to caller */ + *uiResult = sResult.uiWords[0] ; + return Ack_Status; + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_ASC0_UART0.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,48 @@ +/* ASC0/UART0 Configuration for RS-EDP Board */ +/* ***************************************** */ + +/* Configure ASC0/UART0 for General Purpose UART, using mbed libraries */ + + +/* Includes Here */ +#include "mbed.h" +#include "misra_types.h" /* Standard Misra Types For ARM */ +#include "mbed_Port_Structure.h" /* mbed module port structure and port functions */ + + + +/* function Prototypes Defined Here */ +void setup_UART0(void); +uint16_t UART0_Receieve_Byte(void); + + + + +/* Setup UART0 */ +void setup_UART0(void) /* Configure UART0 */ + { + + /* + UART0 configured as follow: + - Word Length = 8 Bits + - One Stop Bit + - No parity + - BaudRate = 115200 baud + - Hardware flow control disabled (no RTS nor CTS signals) + - Receive and transmit enabled + */ + + UART0.baud(115000); + UART0.format(8,Serial::None,1); + + } + + + +/* UART0 Receieve Routine */ +uint16_t UART0_Receieve_Byte(void) + { + return 0; + } + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_ASC1_UART1.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,48 @@ +/* ASC1/UART1 Configuration for RS-EDP Board */ +/* ***************************************** */ + +/* Configure ASC1/UART1 for General Purpose UART, using mbed libraries */ + + +/* Includes Here */ +#include "mbed.h" +#include "misra_types.h" /* Standard Misra Types For ARM */ +#include "mbed_Port_Structure.h" /* mbed module port structure and port functions */ + + + +/* function Prototypes Defined Here */ +void setup_UART1(void); +uint16_t UART1_Receieve_Byte(void); + + + + +/* Setup UART1 */ +void setup_UART1(void) /* Configure UART1 */ + { + + /* + UART1 configured as follow: + - Word Length = 8 Bits + - One Stop Bit + - No parity + - BaudRate = 115200 baud + - Hardware flow control disabled (no RTS nor CTS signals) + - Receive and transmit enabled + */ + + UART1.baud(115000); + UART1.format(8,Serial::None,1); + + } + + + +/* UART0 Receieve Routine */ +uint16_t UART1_Receieve_Byte(void) + { + return 0; + } + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_BB_24LC32_Serial_EEPROM.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,159 @@ +/* Serial EEPROM I2C Type 24LC32 C Source Code Driver File */ +/* ******************************************************* */ + +/* Version 1.00 */ +/* Start Date: 25/2/2008 */ + + + +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "mbed_Port_Structure.h" /* Port structure for MBED Module */ + +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ + + + +/* Function Prototypes Here */ +sint32_t RSEDP_BB_setup_24LC32(uint8_t Slave_Address); /* Configure the I2C EEPROM */ +sint32_t RSEDP_BB_eeprom_store_byte(uint8_t Slave_Address, sint8_t payload, uint16_t eeaddress); /* Write one byte to one memory location */ +sint32_t RSEDP_BB_eeprom_store_bytes(uint8_t Slave_Address, sint8_t *payload, uint8_t qty, uint16_t eeaddress); /* Called by main to write multiple bytes to the serial EEPROM */ +sint32_t RSEDP_BB_eeprom_read_byte(uint8_t Slave_Address, sint8_t *read_value, uint16_t eeaddress); /* Read one byte from one location */ +sint32_t RSEDP_BB_eeprom_read_bytes(uint8_t Slave_Address, sint8_t *payload, uint16_t qty, uint16_t eeaddress); /* Read several byte from one location */ + +static void delay_small(void); /* Local static 1us delay routine */ + + + + +/* Setup the serial interface to the EEPROM */ +sint32_t RSEDP_BB_setup_24LC32(uint8_t Slave_Address) /* Configure the 24LC32 */ + { + sint32_t Ack_Status = 0; + /* Assume the I2C bus is already configured. This is normally done on mbed_Port_Structure.c */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, 0, 1); /* Ping the device */ + return Ack_Status; + } + + + + + + + +/* Store one byte at one address location */ +sint32_t RSEDP_BB_eeprom_store_byte(uint8_t Slave_Address, sint8_t payload, uint16_t eeaddress) /* Write one byte to one memory location */ + { + sint32_t Ack_Status = 0; + sint8_t tx_array[3]; /* two byte array used to hold transmission packet */ + + eeaddress = (eeaddress & 0x0fff); /* Ensure address is not more than 12 bit */ + + tx_array[0] = (uint8_t) (eeaddress >> 8); /* Extract high part */ + tx_array[1] = (uint8_t) eeaddress; /* Extract Low address */ + tx_array[2] = payload; /* second member of array is the value to be stored */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 3); /* Send a data packet to a slave, record acknowledge bit */ + delay_small(); + return Ack_Status; + + } + + + +/* Write upto 32 bytes into the EEPROM all at once */ +sint32_t RSEDP_BB_eeprom_store_bytes(uint8_t Slave_Address, sint8_t *payload, uint8_t qty, uint16_t eeaddress) /* Called by main to write multiple bytes to the serial EEPROM */ + { + sint32_t Ack_Status = 0; + uint8_t n=0; /* Scratch pad variable */ + sint8_t tx_array[34]; /* transmission array */ + + eeaddress = (eeaddress & 0x0fff); /* Cap range to 12 bit address */ + + tx_array[0]=(uint8_t) (eeaddress >> 8); /* Extract high address byte */ + tx_array[1]=(uint8_t) eeaddress; /* Extract Low address */ + + for (n = 2; n < (qty + 2); n++) /* Copy the transmission data into a local array */ + { + tx_array[n] = *payload; + payload++; + } + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, (qty+2)); /* Send data out on I2C bus */ + delay_small(); /* EEPROM Busy period - self timed */ + return Ack_Status; + } + + + + +/* Read One Byte From An Address */ +sint32_t RSEDP_BB_eeprom_read_byte(uint8_t Slave_Address, sint8_t *payload, uint16_t eeaddress) /* Read one byte from one location */ + { + sint32_t Ack_Status = 0; + sint8_t tx_array[3]; + sint8_t rx_array = 0; /* Variable used to receive data from slave */ + + eeaddress = (eeaddress & 0x0fff); /* Cap address to 12 bit */ + + tx_array[0] = (uint8_t) (eeaddress >> 8); /* Extract high order byte */ + tx_array[1] = (uint8_t) eeaddress; /* Extract low address */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 2); /* Set the EEPROM address */ + +// delay_small(); /* EEPROM is busy writing */ + + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, &rx_array,1); /* Read single byte address */ + } + + *payload = rx_array; /* Load value from EEPROM into receive pointer */ + return Ack_Status; + + } + + +/* Read several byte from the memory location */ +sint32_t RSEDP_BB_eeprom_read_bytes(uint8_t Slave_Address, sint8_t *payload, uint16_t qty, uint16_t eeaddress) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[3]; + uint8_t address_low = 0; /* EEPROM high address byte */ + uint8_t address_high = 0; /* EEPROM low address byte */ + + eeaddress = (eeaddress & 0x0fff); /* Cap to 12 bit address */ + address_high = (uint8_t) (eeaddress >> 8); /* Extract high order address byte */ + address_low = (uint8_t) eeaddress; /* Extract Low address byte */ + + tx_array[0] = address_high; /* first member of array is the EEPROM high address */ + tx_array[1] = address_low; /* Low byte next */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 2); /* Set the EEPROM address */ + + delay_small(); /* Write time delay busy period */ + + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, payload, qty); /* Read address */ + } + return Ack_Status; + } + + + +/* Small 5ms delay approx */ +/* Note: Change this delay to suite the write time/busy period of the EEPROM */ +static void delay_small(void) +{ + uint32_t nnnn = 0; + + for(nnnn = 0; nnnn < 0x6000; nnnn++) + { + ; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_BB_PCA9675_Serial_Input_Latch.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,187 @@ +/* Software Driver for Serial Input Latch PCA9675 on the RS-EDP Base Board */ +/* *********************************************************************** */ + + + +/* Version 1.00 */ + + + +/* Include Files */ +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Peripherals */ + +#include "mbed_Port_Structure.h" /* Port structure for MBED Module */ +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ + + + +/* Function Prototypes Defines Here */ +sint32_t RSEDP_BB_setup_PCA9675(uint8_t Slave_Address); /* Setup and configure the I/O latch */ +sint32_t RSEDP_BB_PCA9675_reset(uint8_t Slave_Address); /* Reset the device using a general call */ +sint32_t RSEDP_BB_PCA9675_write_data(uint8_t Slave_Address, uint8_t port0_payload,uint8_t port1_payload); /* Write two bytes of data to the device */ +sint32_t RSEDP_BB_PCA9675_read_data(uint8_t Slave_Address, uint8_t *read_port0, uint8_t *read_port1); /* Read two bytes from the device */ +sint32_t RS_EDP_BB_Read_DIP_Switch(uint8_t Switch_Number); /* Read the switch position - either on or off */ + + + + + +/* Configure the Serial I/O Expander IC */ +sint32_t RSEDP_BB_setup_PCA9675(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + /* Assume the I2C peripheral and MCU I/O is already configured */ + + Ack_Status = RSEDP_BB_PCA9675_reset(Slave_Address); /* Reset the device */ + if (Ack_Status == ACK) + { + Ack_Status = RSEDP_BB_PCA9675_write_data(Slave_Address, 0xff,0xff); /* This configures all I/O as input */ + } + return Ack_Status; + } + + + +/* Reset the device */ +sint32_t RSEDP_BB_PCA9675_reset(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + sint8_t reset_command = 0x06; /* Reset command following a general call, address 0 will reset the device */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(0x0, &reset_command, 2); /* Send a general call command, (Slave address 0), plus one byte of value 0x06 */ + /* The PCA9675 does not generate an ACK on a general call */ + return Ack_Status; + } + + +/* Write two byte of data to the device */ +sint32_t RSEDP_BB_PCA9675_write_data(uint8_t Slave_Address, uint8_t port0_payload, uint8_t port1_payload) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[2]; /* Local array of data to be transmitted */ + + tx_array[0] = port0_payload; /* First is for Port 0 */ + tx_array[1] = port1_payload; /* Second is for Port 1 */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 2); /* Send two bytes plus the slave address to the slave */ + return Ack_Status; + } + + +/* Read two bytes from the device */ +sint32_t RSEDP_BB_PCA9675_read_data(uint8_t Slave_Address, uint8_t *read_port0, uint8_t *read_port1) + { + sint32_t Ack_Status = 0; + sint8_t rx_array[2]; /* Local reception array */ + + Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, rx_array, 2); /* Receive two bytes */ + *read_port0=rx_array[0]; /* transfer data back to pointer */ + *read_port1=rx_array[1]; /* transfer data back to pointer */ + return Ack_Status; + } + + +/* Read the switch position - either on or off */ +sint32_t RS_EDP_BB_Read_DIP_Switch(uint8_t Switch_Number, uint8_t *Switch_Status) + { + sint32_t Ack_Status = 0; + uint8_t port0 = 0; + uint8_t port1 = 0; + + Ack_Status = RSEDP_BB_PCA9675_read_data(PCA9675_BASE_BOARD, &port0, &port1); + + switch (Switch_Number) + { + + case 1: + if ((port0 & 0x01) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 2: + if ((port0 & 0x02) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 3: + if ((port0 & 0x04) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 4: + if ((port0 & 0x08) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 5: + if ((port0 & 0x10) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 6: + if ((port0 & 0x20) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 7: + if ((port0 & 0x40) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + case 8: + if ((port0 & 0x80) == SWITCH_ON) + { + *Switch_Status = DIP_SWITCH_CLOSED; + } + else{ + *Switch_Status = DIP_SWITCH_OPEN; + } + break; + + default: + { + *Switch_Status = port0; + } + } + return Ack_Status; + } + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_CNTRL_I2C.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,63 @@ +/* I2C Handler Functions for MBED Module */ +/* ************************************* */ + + +/* Includes Here */ +#include "mbed.h" +#include "misra_types.h" /* Standard Misra Types For ARM */ + +#include "mbed_Port_Structure.h" /* mbed module port structure and port functions */ + + + +/* Defines Here */ + + + + +/* Variables Defined Here */ + + + +/* Function Prototypes Here */ +void setup_CNTRL_I2C_Master_Mode(void); /* Configuration & setup */ +sint32_t CNTRL_I2C_Master_Mode_Transmit(uint8_t targ_address, sint8_t *Tx_Array, uint16_t num_bytes); /* Send a data packet from this master to a slave device */ +sint32_t CNTRL_I2C_Master_Mode_Receive(uint8_t targ_address, sint8_t *Rx_Array, uint16_t num_bytes); /* Receive a data packet from a slave */ + + + + +/* I2C0 Setup and configuration routine */ +void setup_CNTRL_I2C_Master_Mode(void) + { + /* already setup the peripheral pins for SCL and SDA */ + CNTRL_i2c.frequency(400000); + } + + + + +/* Send an I2C Write Packet to an I2C Slave Peripheral */ +sint32_t CNTRL_I2C_Master_Mode_Transmit(uint8_t targ_address, sint8_t *Tx_Array, uint16_t num_bytes) + { + sint32_t Ack_Status = 0; + targ_address = (targ_address << 1); + Ack_Status = CNTRL_i2c.write(targ_address, Tx_Array, num_bytes); /* Send an I2C packet */ + return Ack_Status; + } + + + +/* Receive an I2C Packet in Master Mode from the slave to the bus */ +sint32_t CNTRL_I2C_Master_Mode_Receive(uint8_t targ_address, sint8_t *Rx_Array, uint16_t num_bytes) + { + sint32_t Ack_Status = 0; + + targ_address = ((targ_address << 1) | 0x01); + Ack_Status = CNTRL_i2c.read(targ_address, Rx_Array, num_bytes); + return Ack_Status; + } + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_CNTRL_SPI.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,50 @@ +/* RS-EDP CNTRL SPI Functions */ +/* ************************** */ + + +/* Includes Here */ +#include "mbed.h" +#include "misra_types.h" /* Standard Misra Types For ARM */ + +#include "mbed_Port_Structure.h" /* mbed module port structure and port functions */ + + + +/* Function Prototpyes */ +void setup_CNTRL_SPI_Master_Mode(void); +uint8_t CNTRL_SPI_Write_Byte(uint8_t data_byte); +uint8_t CNTRL_SPI_Read_Byte(void); + + +/* setup and configure the SPI Peripheral */ +void setup_CNTRL_SPI_Master_Mode(void) + { + /* IO Structure already configures in mbed_Port_Structure.c */ + CNTRL_spi.format(8,3); /* 8 bit, Clock Polarity, Clock Phase */ + CNTRL_spi.frequency(1000000); /* Clock frequency in Hertz */ + } + + + + + +/* Send one byte of data out to the SPI */ +uint8_t CNTRL_SPI_Write_Byte(uint8_t data_byte) + { + uint8_t return_value = 0; + return_value = CNTRL_spi.write(data_byte); + return return_value; + } + + + + +/* Read one byte of data from the SPI */ +uint8_t CNTRL_SPI_Read_Byte(void) + { + uint8_t return_value = 0; + + return_value = CNTRL_spi.write(0x00) ; /* transmit a dummy byte */ + return return_value; /* Return with read in value */ + } + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_COM_PCF8583_Real_Time_Clock.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,662 @@ +/* Driver For PCF8583T Real Time Clock IC */ +/* ************************************** */ + + +/* Version 1.00 */ +/* Start Date: 23/6/2009 */ +/* The RTC Clock IC is part of the communications module */ + + + + + +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "RSEDP_Slave_Address_Defines.h" /* Slave Address of CNTRL I2C devices */ + +#include "mbed_Port_Structure.h" /* Port structure for MBED Module */ +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ + + + +#define START_YEAR (uint16_t) 2009 /* Value used for real time clock */ + + + + +/* Function Prototypes Here */ +sint32_t RSEDP_COM_setup_PCF8583(uint8_t Slave_Address, uint8_t mode); /* Setup the device */ +sint32_t RSEDP_COM_PCF8583_Read_Status_Register(uint8_t Slave_Address, uint8_t *status_register); /* Read the status register of the device */ +sint32_t RSEDP_COM_PCF8583_Write_Status_Register(uint8_t Slave_Address, uint8_t payload); /* Status register write */ + +/* RTC Function */ +sint32_t RSEDP_COM_PCF8583_Write_RTC(uint8_t Slave_Address, uint8_t *RTC_Array); /* Write raw data to the RTC device */ +sint32_t RSEDP_COM_PCF8583_Read_RTC(uint8_t Slave_Address, uint8_t *RTC_Array); /* Read raw data from the real time clock */ +sint32_t RSEDP_COM_PCF8583_Set_Clock(uint8_t Slave_Address, uint8_t hours, uint8_t minutes, uint8_t seconds,uint8_t F24hour_flag, uint8_t AMPM_flag); /* Set the clock only */ +sint32_t RSEDP_COM_PCF8583_Set_Date(uint8_t Slave_Address, uint8_t dow, uint8_t day,uint8_t month, uint16_t year); /* Set the date only */ +sint32_t RSEDP_COM_PCF8583_Read_Clock(uint8_t Slave_Address, uint8_t *Time_Array); /* Read the time component only */ +sint32_t RSEDP_COM_PCF8583_Read_Date(uint8_t Slave_Address, uint8_t *Date_Array); /* Read the date component only */ +sint32_t RSEDP_COM_PCF8583_Read_Clock_And_Date(uint8_t Slave_Address, uint8_t *Time_Array,uint8_t *Date_Array); /* Read time and date */ +sint32_t RSEDP_COM_PCF8583_Start_Clock(uint8_t Slave_Address); /* Start the clock counting */ +sint32_t RSEDP_COM_PCF8583_Stop_Clock(uint8_t Slave_Address); /* Stop the clock */ + +/* Battery Maintained SRAM functions */ +sint32_t RSEDP_COM_PCF8583_Read_SRAM(uint8_t Slave_Address, uint8_t *read_data,uint8_t address); /* Read data from the battery maintained SRAM */ +sint32_t RSEDP_COM_PCF8583_Write_SRAM(uint8_t Slave_Address, uint8_t payload,uint8_t address); /* Write data to the battery maintained SRAM */ + + +/* Print Functions */ +void RSEDP_COM_Print_Time(uint8_t *Time_Array); +void RSEDP_COM_Print_Date(uint8_t *Date_Array); +void RSEDP_COM_Print_Time_Date_Year(uint8_t *RTC_Array); + + + +/* Static local functions */ +static void delay_small(void); + + + + + +/* Setup the device */ +sint32_t RSEDP_COM_setup_PCF8583(uint8_t Slave_Address, uint8_t mode) + { + sint32_t Ack_Status = 0; + /* Assume the I2C Peripheral is already configured */ + + if ((mode=='c') | (mode== 'C')) + { + /* Configure for Clock mode */ + Ack_Status = RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, 0x00); + + } + + if ((mode=='e') | (mode== 'E')) + { + /* configure for Event Counter Mode */ + Ack_Status = RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, 0x20); + } + return Ack_Status; + } + + + + +/* Read the status register of the device */ +sint32_t RSEDP_COM_PCF8583_Read_Status_Register(uint8_t Slave_Address, uint8_t *status_register) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[2]; + sint8_t rx_array=0; /* Variable used to receive data from slave */ + + tx_array[0] = 0x00; /* Memory address 0x00 */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); /* Set the RTC address */ + + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, &rx_array,1); /* Read single byte address */ + } + *status_register = rx_array; /* Load value from RTC into receive pointer */ + return Ack_Status; + } + + + + +/* Status register write */ +sint32_t RSEDP_COM_PCF8583_Write_Status_Register(uint8_t Slave_Address, uint8_t payload) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[2]; /* Transmission array */ + + tx_array[0] = 0x00; /* Address 0x00 is where the control register is located */ + tx_array[1] = payload; /* Data to be written */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array,2); /* Send the data */ + return Ack_Status; + } + + +/* Read the real time clock information */ +sint32_t RSEDP_COM_PCF8583_Read_RTC(uint8_t Slave_Address, uint8_t *RTC_Array) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[2]; + sint8_t local_array[8]; + uint8_t n = 0u; + + tx_array[0] = 0x01; /* Memory address 0x01 */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); /* Set the RTC memory address */ + + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, local_array,7); /* Read single byte address */ + } + for (n = 0; n < 7; n++) + { + RTC_Array[n] = (uint8_t) (local_array[n]); + } + return Ack_Status; + } + + +/* Write the real time clock information */ +sint32_t RSEDP_COM_PCF8583_Write_RTC(uint8_t Slave_Address, uint8_t *RTC_Array) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[8]; + uint8_t n = 0; + + tx_array[0] = 0x01; /* Memory address 0x01 */ + for (n = 1; n < 8; n++) /* Copy data into array */ + { + tx_array[n] = *RTC_Array; + RTC_Array++; + } + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 8); /* Transmit the data */ + delay_small(); /* RTC is busy writing */ + return Ack_Status; + } + + +/* Set the clock inside the device */ +sint32_t RSEDP_COM_PCF8583_Set_Clock(uint8_t Slave_Address, uint8_t hours, uint8_t minutes, uint8_t seconds,uint8_t F24hour_flag, uint8_t AMPM_flag) + { + sint32_t Ack_Status = 0; + sint8_t RTC_Array[5] = {0,0,0,0,0}; + uint8_t high = 0; + uint8_t low = 0; + + /* Hundreths */ + RTC_Array[1] = 0x00; /* Hundreths of a second -set to zero */ + + /* Seconds */ /* Convert to BCD */ + low = (seconds % 10); + high = (seconds / 10); + RTC_Array[2] = ((high << 4) + low); + + /* Minutes */ /* Convert to BCD */ + low = (minutes % 10); + high = (minutes / 10); + RTC_Array[3] = ((high << 4) + low); + + /* Hours */ /* Convert to BCD and add in 24 hour and AM/PM flag */ + low = (hours % 10); + high = (hours / 10); + RTC_Array[4] = ((high << 4) + low); + RTC_Array[4] = (RTC_Array[4] & 0x3f); + + F24hour_flag = ((F24hour_flag & 0x01) << 7); + AMPM_flag = ((AMPM_flag & 0x01) << 6); + + RTC_Array[4] += F24hour_flag + AMPM_flag; + + RTC_Array[0] = 0x01; /* Target destination address of data */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, RTC_Array, 5); /* Transmit the data */ + delay_small(); /* RTC is busy writing */ + return Ack_Status; + } + + + +/* Write the time and date to the RTC clock */ +sint32_t RSEDP_COM_PCF8583_Set_Date(uint8_t Slave_Address, uint8_t dow, uint8_t day,uint8_t month, uint16_t year) + { + sint32_t Ack_Status = 0; + sint8_t RTC_Array[5] = {0,0,0,0,0}; + uint8_t high = 0; + uint8_t low = 0; + + /* day of month */ /* Convert to BCD */ + if (day > 31) day = 31; + low = (day % 10); + high = (day / 10); + RTC_Array[1] = (((high << 4) + low) & 0x3f); + + /* year */ + year = ((year - 2008) & 0x03); + RTC_Array[1] += (year << 6); + + /* Day of week */ + if (dow > 6) dow = 6; + dow = (dow << 5); + RTC_Array[2] = dow; + + /* months */ + if (month > 12) month = 12; + low = (month % 10); + high = (month / 10); + RTC_Array[2] += (((high << 4) + low)); + + + RTC_Array[0] = 0x05; /* Target destination address of data */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, RTC_Array, 3); /* Transmit the data */ + delay_small(); /* RTC is busy writing */ + return Ack_Status; + } + + + +/* Start the clock counting */ +sint32_t RSEDP_COM_PCF8583_Start_Clock(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + uint8_t status_reg = 0; + + Ack_Status = RSEDP_COM_PCF8583_Read_Status_Register(Slave_Address, &status_reg); + + status_reg = (status_reg & 0x7f); + + if (Ack_Status ==ACK) + { + Ack_Status = RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, status_reg); + } + return Ack_Status; + } + + + +/* Stop the clock */ +sint32_t RSEDP_COM_PCF8583_Stop_Clock(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + uint8_t status_reg = 0; + + Ack_Status = RSEDP_COM_PCF8583_Read_Status_Register(Slave_Address, &status_reg); + + status_reg = (status_reg | 0x80); + + if (Ack_Status == ACK) + { + RSEDP_COM_PCF8583_Write_Status_Register(Slave_Address, status_reg); + } + return Ack_Status; + } + + +/* Read the time component only */ +sint32_t RSEDP_COM_PCF8583_Read_Clock(uint8_t Slave_Address, uint8_t *Time_Array) + { + sint32_t Ack_Status = 0; + uint8_t RTC_Array[6] = {0,0,0,0,0,0}; /* Hundreths, seconds, minutes,hours, year/date, weekday/month */ + uint8_t temp8 = 0; + + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + + /* hours */ + temp8 = (((RTC_Array[3] & 0x30) >> 4) * 10); + *Time_Array = ((RTC_Array[3] & 0x0f) + temp8); + Time_Array++; + + /* Minutes */ + temp8=(((RTC_Array[2] & 0xf0) >> 4) * 10); + *Time_Array = ((RTC_Array[2] & 0x0f) + temp8); + Time_Array++; + + /* Seconds */ + temp8=(((RTC_Array[1] & 0xf0) >> 4) * 10); + *Time_Array = ((RTC_Array[1] & 0x0f) + temp8); + Time_Array++; + + /* Hundreths */ + temp8=(((RTC_Array[0] & 0xf0) >> 4) * 10); + *Time_Array = ((RTC_Array[0] & 0x0f) + temp8); + Time_Array++; + + // 24 Hour Flag + *Time_Array = ((RTC_Array[3] & 0x80) >> 7); + Time_Array++; + + // AMPM Flag + *Time_Array = (( RTC_Array[3] & 0x40) >> 6); + return Ack_Status; + } + + + +/* Read the date component only */ +sint32_t RSEDP_COM_PCF8583_Read_Date(uint8_t Slave_Address, uint8_t *Date_Array) + { + sint32_t Ack_Status = 0; + uint8_t RTC_Array[6] = {0,0,0,0,0,0}; /* Hundreths, seconds, minutes,hours, year/date, weekday/month */ + uint8_t temp8 = 0; + + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + + /* Weekday */ + *Date_Array = ((RTC_Array[5] & 0xe0) >> 5); + Date_Array++; + + /* Date */ + temp8=(((RTC_Array[4] & 0x30) >> 4) * 10); + *Date_Array = ((RTC_Array[4] & 0x0f) + temp8); + Date_Array++; + + /* Month */ + temp8 = (((RTC_Array[5] & 0x10) >> 4) * 10); + *Date_Array = ((RTC_Array[5] & 0x0f) + temp8); + Date_Array++; + + /* Year */ + *Date_Array = ((RTC_Array[4] & 0xc0) >> 6); + return Ack_Status; + } + + +/* Read time and date */ +sint32_t RSEDP_COM_PCF8583_Read_Clock_And_Date(uint8_t Slave_Address, uint8_t *Time_Array,uint8_t *Date_Array) + { + sint32_t Ack_Status = 0; + uint8_t RTC_Array[6] = {0,0,0,0,0,0}; /* Hundreths, seconds, minutes,hours, year/date, weekday/month */ + uint8_t temp8 = 0; + + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + + /* hours */ + temp8 = (((RTC_Array[3] & 0x30) >> 4) * 10); + *Time_Array = ((RTC_Array[3] & 0x0f) + temp8); + Time_Array++; + + /* Minutes */ + temp8 = (((RTC_Array[2] & 0xf0) >> 4) * 10); + *Time_Array = ((RTC_Array[2] & 0x0f) + temp8); + Time_Array++; + + /* Seconds */ + temp8 = (((RTC_Array[1] & 0xf0) >> 4) * 10); + *Time_Array = ((RTC_Array[1] & 0x0f) + temp8); + Time_Array++; + + /* Hundreths */ + temp8 = (((RTC_Array[0] & 0xf0) >> 4) * 10); + *Time_Array = ((RTC_Array[0] & 0x0f) + temp8); + Time_Array++; + + /* 24 Hour Flag */ + *Time_Array = ((RTC_Array[3] & 0x80)>>7); + Time_Array++; + + /* AMPM Flag */ + *Time_Array = (( RTC_Array[3] & 0x40) >> 6); + + + /* Date */ + /* Weekday */ + *Date_Array = ((RTC_Array[5] & 0xe0) >> 5); + Date_Array++; + + /* Date */ + temp8 = (((RTC_Array[4] & 0x30) >> 4) * 10); + *Date_Array = ((RTC_Array[4] & 0x0f) + temp8); + Date_Array++; + + /* Month */ + temp8 = (((RTC_Array[5] & 0x10) >> 4) * 10); + *Date_Array = ((RTC_Array[5] & 0x0f) + temp8); + Date_Array++; + + /* Year */ + *Date_Array = ((RTC_Array[4] & 0xc0) >> 6); + return Ack_Status; + } + + + + + + + +/* Battery Maintained SRAM functions */ + +/* Read data from the battery maintained SRAM */ +sint32_t RSEDP_COM_PCF8583_Read_SRAM(uint8_t Slave_Address, uint8_t *read_data, uint8_t address) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[2]; /* Transmission array of data */ + sint8_t rx_array=0; /* Variable used to receive data from slave */ + + tx_array[0] = address; /* Memory address to read */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); /* Set the RTC address */ + + if (Ack_Status == ACK) + { + CNTRL_I2C_Master_Mode_Receive(Slave_Address, &rx_array,1); /* Read single byte address */ + } + *read_data=rx_array; /* Load value from RTC into receive pointer */ + return Ack_Status; + } + + +/* Write data to the battery maintained SRAM */ +sint32_t RSEDP_COM_PCF8583_Write_SRAM(uint8_t Slave_Address, uint8_t payload, uint8_t address) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[2]; /* Transmission array */ + + tx_array[0] = address; /* Address */ + tx_array[1] = payload; /* Data */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array,2); /* Send the data */ + return Ack_Status; + + } + + + + +/* Print the time, date and year */ +void RSEDP_COM_Print_Time_Date_Year(uint8_t *RTC_Array) + { + uint8_t hundreths = 0; + uint8_t seconds = 0; + uint8_t minutes = 0; + uint8_t hours = 0; + uint8_t date = 0; + uint16_t year = 0; + uint8_t weekday = 0; + uint8_t month = 0; + uint8_t temp8 = 0; + uint8_t AMPM_flag = 0; + uint8_t F24hour_flag=0; + + /* Hundreths */ + temp8 = (((*RTC_Array & 0xf0) >> 4) * 10); + hundreths = ((*RTC_Array & 0x0f) + temp8); + RTC_Array++; + + /* Seconds */ + temp8 = (((*RTC_Array & 0xf0) >> 4) * 10); + seconds = ((*RTC_Array & 0x0f) + temp8); + RTC_Array++; + + /* Minutes */ + temp8 = (((*RTC_Array & 0xf0) >> 4) * 10); + minutes = ((*RTC_Array & 0x0f) + temp8); + RTC_Array++; + + /* hours */ + temp8 = (((*RTC_Array & 0x30) >> 4) * 10); + hours = ((*RTC_Array & 0x0f) + temp8); + F24hour_flag = ((*RTC_Array & 0x80) >> 7); + AMPM_flag = (( *RTC_Array & 0x40) >> 6); + RTC_Array++; + + /* Date */ + temp8 = (((*RTC_Array & 0x30) >> 4) * 10); + date = ((*RTC_Array & 0x0f) + temp8); + + /* Year */ + year = ((*RTC_Array & 0xc0) >> 6); + RTC_Array++; + + /* Weekday */ + weekday = ((*RTC_Array & 0xe0) >> 5); + + /* Month */ + temp8 = (((*RTC_Array & 0x10) >> 4) * 10); + month = ((*RTC_Array & 0x0f) + temp8); + + pc.printf("%.2d:", hours); + pc.printf("%.2d ", minutes); + + if (F24hour_flag==1) + { + if (AMPM_flag == 0) + { + pc.printf("AM "); + } + if (AMPM_flag == 1) + { + pc.printf("PM "); + } + } + + pc.printf("%.2d.",seconds); + pc.printf("%.2d seconds ", hundreths); + + if (weekday == 0) pc.printf("Monday"); + if (weekday == 1) pc.printf("Tuesday"); + if (weekday == 2) pc.printf("Wednesday"); + if (weekday == 3) pc.printf("Thursday"); + if (weekday == 4) pc.printf("Friday"); + if (weekday == 5) pc.printf("Saturday"); + if (weekday == 6) pc.printf("Sunday"); + + pc.printf(" %.2d ",date); + + if (month == 1) pc.printf("January"); + if (month == 2) pc.printf("Febuary"); + if (month == 3) pc.printf("March"); + if (month == 4) pc.printf("April"); + if (month == 5) pc.printf("May"); + if (month == 6) pc.printf("June"); + if (month == 7) pc.printf("July"); + if (month == 8) pc.printf("August"); + if (month == 9) pc.printf("September"); + if (month == 10) pc.printf("October"); + if (month == 11) pc.printf("November"); + if (month == 12) pc.printf("December"); + + year = year + START_YEAR; + pc.printf(" %.4d ", year); + + + } + +/* Print the Time */ +void RSEDP_COM_Print_Time(uint8_t *Time_Array) + { + uint8_t hours = 0; + uint8_t minutes = 0; + uint8_t seconds = 0; + uint8_t hundreths = 0; + uint8_t F24hour_flag=0; + uint8_t AMPM_flag = 0; + + hours = *Time_Array; + Time_Array++; + minutes = *Time_Array; + Time_Array++; + seconds = *Time_Array; + Time_Array++; + hundreths = *Time_Array; + Time_Array++; + F24hour_flag = *Time_Array; + Time_Array++; + AMPM_flag = *Time_Array; + + pc.printf("%.2d:",hours); + pc.printf("%.2d ",minutes); + + if (F24hour_flag == 1) + { + if (AMPM_flag == 0) + { + pc.printf("AM "); + } + if (AMPM_flag == 1) + { + pc.printf("PM "); + } + } + + pc.printf("%.2d.",seconds); + pc.printf("%.2d seconds ",hundreths); + + } + + +/* Print the date */ +void RSEDP_COM_Print_Date(uint8_t *Date_Array) + { + uint8_t date = 0; + uint16_t year = 0; + uint8_t weekday = 0; + uint8_t month = 0; + + weekday = *Date_Array; + Date_Array++; + date = *Date_Array; + Date_Array++; + month = *Date_Array; + Date_Array++; + year = *Date_Array; + Date_Array++; + + if (weekday == 0) pc.printf("Monday"); + if (weekday == 1) pc.printf("Tuesday"); + if (weekday == 2) pc.printf("Wednesday"); + if (weekday == 3) pc.printf("Thursday"); + if (weekday == 4) pc.printf("Friday"); + if (weekday == 5) pc.printf("Saturday"); + if (weekday == 6) pc.printf("Sunday"); + + pc.printf(" %.2d ",date); + + if (month == 1) pc.printf("January"); + if (month == 2) pc.printf("Febuary"); + if (month == 3) pc.printf("March"); + if (month == 4) pc.printf("April"); + if (month == 5) pc.printf("May"); + if (month == 6) pc.printf("June"); + if (month == 7) pc.printf("July"); + if (month == 8) pc.printf("August"); + if (month == 9) pc.printf("September"); + if (month == 10) pc.printf("October"); + if (month == 11) pc.printf("November"); + if (month == 12) pc.printf("December"); + + year = year + START_YEAR; + pc.printf(" %.4d ", year); + } + + + + + + + + + + + +/* Small 5ms delay approx */ +/* Note: Change this delay to suite the write time/busy period of the RTC */ +static void delay_small(void) + { + uint32_t nnnn=0; + + for(nnnn = 0; nnnn < 0x12000; nnnn++) + { + ; + } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_DIO_PCA9555_Serial_Digital_IO.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,93 @@ +/* This module is to drive the Serial Digital I/O PCA9555 Device */ +/* ************************************************************* */ + + +/* Version 1.00 */ +/* Start Date: 23/6/09 */ + + +/* The digital Output from the serial latch drive the ULN2003 line driver devices */ +/* The digital input devices come through a protection circuit on the board and are then fed into the serial input latch */ + + +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "RSEDP_Slave_Address_Defines.h" /* Slave Address of CNTRL I2C devices */ + +#include "mbed_Port_Structure.h" /* Port structure for MBED Module */ +#include "RSEDP_CNTRL_I2C.h" /* Control I2C Driver */ + + + + +/* Function Prototypes Here */ +sint32_t RSEDP_DIO_setup_PCA9555(uint8_t Slave_Address, uint8_t Port0_IO_Direction,uint8_t Port1_IO_Direction); /* Setup the device I/O Direction */ +sint32_t RSEDP_DIO_PCA9555_Write_Word(uint8_t Slave_Address, uint8_t Port0_Payload, uint8_t Port1_Payload); /* Write to the I/O pins */ +sint32_t RSEDP_DIO_PCA9555_Read_Data(uint8_t Slave_Address, uint8_t *Port0_Data, uint8_t*Port1_Data); /* Read data on the input pins */ + +static sint32_t PCA9555_Write_Data(uint8_t Slave_Address, uint8_t command_byte, uint8_t P0_payload, uint8_t P1_payload);/* Local function used to xfer data to the I2C Module */ + + + +/* Setup the device I/O Direction of the Latch*/ +sint32_t RSEDP_DIO_setup_PCA9555(uint8_t Slave_Address, uint8_t Port0_IO_Direction,uint8_t Port1_IO_Direction) + { + sint32_t Ack_Status = 0; + /* Assume the I2C peripheral and I/O is already configured */ + + Ack_Status = PCA9555_Write_Data(Slave_Address, 0x06, Port0_IO_Direction, Port1_IO_Direction); /* This 0x06 = configures the I/O direction */ + return Ack_Status; + } + + + +/* Write Data Out to the Port Latches */ +sint32_t RSEDP_DIO_PCA9555_Write_Word(uint8_t Slave_Address, uint8_t Port0_Payload, uint8_t Port1_Payload) + { + sint32_t Ack_Status = 0; + + Ack_Status = PCA9555_Write_Data(Slave_Address, 0x02, Port0_Payload, Port1_Payload); /* This Writes the data to the I/O latches */ + return Ack_Status; + } + + +/* Read the values on the serial latch pins */ +sint32_t RSEDP_DIO_PCA9555_Read_Data(uint8_t Slave_Address, uint8_t *Port0_Data, uint8_t*Port1_Data) + { + sint32_t Ack_Status = 0; + sint8_t rx_array[2] = {0x00, 0x00}; /* Local reception array */ + sint8_t tx_array[1] = {0x000}; /* Data to transmit */ + + tx_array[0] = 0; /* Command Byte For Read */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 1); + + if (Ack_Status == ACK) + { + Ack_Status = CNTRL_I2C_Master_Mode_Receive(Slave_Address, rx_array, 2); /* Receive two bytes from the serial latch */ + *Port0_Data = rx_array[0]; /* Transfer Port 0 Data to pointer */ + *Port1_Data = rx_array[1]; /* Transfer Port 1 Data to pointer */ + } + return Ack_Status; + } + + + + + +/* Write address, command byte plus two additional bytes of data to the device */ +static sint32_t PCA9555_Write_Data(uint8_t Slave_Address, uint8_t command_byte, uint8_t P0_payload, uint8_t P1_payload) + { + sint32_t Ack_Status = 0; + sint8_t tx_array[3]; /* Local array of data to be transmitted */ + + tx_array[0] = command_byte; /* Load transmit array */ + tx_array[1] = P0_payload; /* First is for Port 0 */ + tx_array[2] = P1_payload; /* Second is for Port 1 */ + + Ack_Status = CNTRL_I2C_Master_Mode_Transmit(Slave_Address, tx_array, 3); /* Send 3 bytes */ + return Ack_Status; + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_MC1.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,309 @@ +/* Driver for brushed DC Motor Controler */ +/* ************************************* */ + + + +/* Include Files Here */ +#include "mbed.h" /* mbed header file */ +#include "misra_types.h" /* MISRA Types header file */ +#include "defines.h" +#include "mbed_Port_Structure.h" /* Port structure for MBED Module */ + + + + + + /* + The standard software module for the MC1 has been modified to accomodate the mapping of the mbed pins to it. + Not all of the functions usually available for control of the MC1 module are available. + Below in the commented out section is the full section of functions. + In the function prototype section are the ones that are implemented + */ + + /* + The mapping of the various functions to the mbed module are as follows... + int16_t RSEDP_MC1_Read_VDCLINK(uint8_t channel); VDCLINK - Analogue AN2 - pin 17 mbed MCU + uint16_t RSEDP_MC1_Read_VSENSE(uint8_t channel); VSENSE - Analogue AN0 - pin 15 mbed MCU + uint16_t RSEDP_MC1_Read_VTACH(uint8-t channel); VTACH - possible Analogue AN4 - pin 19 mbed MCU - but not implemnted as this pin 19 used as brake input + uint16_t RSEDP_MC1_Read_Acceleration_Ramp(void); Accelration ramp - Not implemented + uint16_t RSEDP_MC1_Read_Deceleration_Ramp(void); Deceleration lamp - not implemented + + + uint8_t RSEDP_MC1_Read_External_Fault_Input(void); External Fault - not implemented + uint8_t RSEDP_MC1_Read_Fault_Reset_Switch(void); Fault Reset - not implemented + uint8_t RSEDP_MC1_Read_Open_Switch(uint8_t pin_option); Open Switch - Mapped to EVM2_GPIO41 - pin 11 mbed digital input + uint8_t RSEDP_MC1_Read_Closed_Switch(uint8_t pin_option); Closed Switch - not implemented + uint8_t RSEDP_MC1_Read_Encoder0_Input(uint8_t pin_option); Read Encoder0 - mapped to EVG6_GPIO52 - pin 30 mbed digital input (possible timer input capture) + uint8_t RSEDP_MC1_Read_Encoder1_Input(uint8_t pin_option); Read Encoder1 - mapped to EVG7_GPIO54 - pin 8 mbed digital input + uint8_t RSEDP_MC1_Read_Tacho_Input(uint8_t pin_option); Tacho Pulses - Duplicate function to Encoder0 + uint8_t RSEDP_MC1_Read_Motor_RunStop(uint8_t pin_option); Motor Run Stop - mapped to EVG3_GPIO46 pin 26 mbed digital input + uint8_t RSEDP_MC1_Read_Motor_Direction(uint8_t pin_option); Read Motor Direction - not implemented + uint8_t RSEDP_MC1_Read_Current_Limit_Match(uint8_t pin_option); Motor Current Limit - not implemented + + + void RSEDP_MC1_Set_Motor_Direction(uint8_t motor_direction, uint8_t pin_option); Set Motor Direction - mapped to pin 24 - digital out + void RSEDP_MC1_Brake(uint8_t brake_onoff, uint8_t pin_option); Brake on/off - mapped to GPIO0 - pin 19 mbed module digital out + void RSEDP_MC1_Set_Motor_Speed_Duty(float motor_speed_duty, uint8_t pin_option); Set motor speed duty - mapped to EVG0_GPIO40 - pin 23 mbed PWM out + void RSEDP_MC1_Set_Current_Trip_Duty(float current_trip_duty, uint8_t pin_option); Set current trip duty - mapped to CPU_DACO0_GPIO17 - pin 21 PWM out + */ + + + + + + +/* function Prototypes */ +void RSEDP_MC1_Setup(void); /* Setup the MC1 Board */ + +/* Analogue Levels */ +uint16_t RSEDP_MC1_Read_VDCLINK(uint8_t channel); /* Read the filtered 12V DC voltage on the MC1 board via pot down resistors */ +uint16_t RSEDP_MC1_Read_VSENSE(uint8_t channel); /* Read the filtered current sense output from the MC1 board */ + + +/* Digital level inputs */ +uint8_t RSEDP_MC1_Read_Encoder0_Input(uint8_t pin_option); /* Read the physical level on the Encoder0 input pin on P301 pin 8 on the MC1 board*/ +uint8_t RSEDP_MC1_Read_Encoder1_Input(uint8_t pin_option); /* Read the physical level on the Encoder1 input pin on P301 pin 10 on the MC1 board*/ +uint8_t RSEDP_MC1_Read_Tacho_Input(uint8_t pin_option); /* Read the physical level on the Tacho Pulses Input pin on P301 pin 6 on the MC1 board */ + + +/* Outputs */ +void RSEDP_MC1_Set_Motor_Direction(uint8_t motor_direction, uint8_t pin_option); /* Set the motor direction */ +void RSEDP_MC1_Brake(uint8_t brake_onoff, uint8_t pin_option); /* turn the brake on or off */ +void RSEDP_MC1_Set_Motor_Speed_Duty(float motor_speed_duty, uint8_t pin_option); /* Power control of motor speed controller using PWM */ + + + + + + +/* Setup the MC1 Board */ +void RSEDP_MC1_Setup(void) + { + PwmOut_Pin23.period_us(50); /* 20KHz fundemental PWM */ + RSEDP_MC1_Set_Motor_Speed_Duty(0, EVG0_GPIO40); /* Speed set to zero */ + RSEDP_MC1_Brake(BRAKE_ON, GPIO0); /* Brake ON */ + } + + +/* Read The VDCLINK Voltage */ +uint16_t RSEDP_MC1_Read_VDCLINK(uint8_t channel) + { + /* There are two possible AD conveter channels where we can measure the VDCLINK voltage */ + /* Either ADC channel AN2 or ADC channel AN12 selectable via JP312 */ + /* channel therefore has two value 2 or 12 */ + + float return_value = 0; + + if (channel == AN2) + { + /* Link JP312 1-2 */ + return_value = (AD2 * 3300); + } + + if (channel == AN12) + { + /* Link JP312 2-3 */ + /* AN12 is mapped onto AD3 on the mbed module via link option */ + return_value = (AD3 * 3300); + } + + return (uint16_t) return_value; + } + + +/* Read the current sense output from the MC1 board */ +uint16_t RSEDP_MC1_Read_VSENSE(uint8_t channel) + { + /* Read the current sense output from the motor drive device */ + /* This voltage signal is proprtional to the motor current */ + /* We can read this from a choice of two AD channels AN0 and AN10 selectable via JP307 */ + + float return_value = 0; + + if (channel == AN0) + { + /* Link JP307 1-2 */ + return_value = (AD0 * 3300); + + } + + if (channel == AN10) + { + /* Link JP307 2-3 */ + /* AN10 is mapped onto AD1 via link option on the mbed module */ + return_value = (AD1 * 3300); + } + + return (uint16_t) return_value; + } + + + +/* Read the filtered tacho voltage. This voltage is proportional to RPM */ +uint16_t RSEDP_MC1_Read_VTACH(uint8_t channel) + { + /* The VTACH signal is an analogue voltage produces by the tacho which is proprtional to RPM. The faster the rotation the higher the votlage */ + /* Not all tachos produce a variable output voltage but the motor drive module is able to cope with both pulse fed tacho and also voltage supplied tacho voltage feedback signals */ + /* This function is for the feedback voltage method */ + /* The VTACH voltage is available on two analogue pins AN4 and AN14 selectable via JP304 */ + + if (channel == AN4) + { + /* Link JP304 1-2 */ + /* not implemented */ + } + + if (channel == AN14) + { + /* Link JP304 2-3 */ + /* not implemented - AN14 is not mapped on to the MBED module */ + } + + /* not implemented */ + return 0; + } + + + + + + + +/* Read the physical level on the Encoder0 input pin on P301 pin 8 on the MC1 board*/ +uint8_t RSEDP_MC1_Read_Encoder0_Input(uint8_t pin_option) + { + /* The Encoder0 pin can be routed to two output pins EVM5_GPIO47 or EVG6_GPIO52 via JP302 on the MC1 motor Drive module */ + /* To use this Encoder input JP303 also needs to be set in the 2-3 position */ + + uint8_t return_value = 0; + + if (pin_option == EVM5_GPIO47) + { + /* Links JP302 1-2 and JP303 2-3 */ + /* not implemented */ + } + + if (pin_option == EVG6_GPIO52) + { + /* Links JP302 2-3 and JP303 2-3 */ + return_value = DigitalIn_Pin30; + } + + return return_value; + } + + + +/* Read the physical level on the Encoder1 input pin on P301 pin 10 on the MC1 board*/ +uint8_t RSEDP_MC1_Read_Encoder1_Input(uint8_t pin_option) + { + /* The Encoder1 pin can be routed to two output pins EVM6_GPIO49 or EVG7_GPIO54 via JP306 on the MC1 motor Drive module */ + + uint8_t return_value = 0; + + if (pin_option == EVM6_GPIO49) + { + /* Link option JP306 1-2 */ + /* not implemented */ + } + + if (pin_option == EVG7_GPIO54) + { + /* Link option JP306 2-3 */ + return_value = DigitalIn_Pin8; + } + + return return_value; + } + + + +/* Read the physical level on the Tacho Pulses Input pin on P301 pin 6 on the MC1 board */ +uint8_t RSEDP_MC1_Read_Tacho_Input(uint8_t pin_option) + { + /* The Tacho Pulses pin uses the same hardware as the Encoder0 pin and either input is selected via jumper JP303 */ + /* This tacho pulse can like the Encoder0 pin be routed to two output pins EVM5_GPIO47 or EVG6_GPIO52 */ + /* to use this Encoder input JP303 needs to be set in the 1-2 position */ + + return RSEDP_MC1_Read_Encoder0_Input(pin_option); + } + + + + + + + +/* Set the motor direction */ +void RSEDP_MC1_Set_Motor_Direction(uint8_t motor_direction, uint8_t pin_option) + { + /* the Motor Direction can be set by the MCU via EVG1_GPIO42 or EVG5_GPIO50 selectable via link option JP206 and JP207 on MC1 motor drive module */ + if (pin_option == EVG1_GPIO42) + { + /* Link options JP206 1-2 and JP207 2-3 */ + if (motor_direction == FORWARD) + { + DigitalOut_Pin24 = 1; + } + else{ + DigitalOut_Pin24 = 0; + } + } + + if (pin_option == EVG5_GPIO50) + { + /* Link options JP206 2-3 and JP207 2-3 */ + /* Not implemented */ + } + } + + + +/* turn the brake on or off */ +void RSEDP_MC1_Brake(uint8_t brake_onoff, uint8_t pin_option) + { + /* The brake can be turned ON or OFF via this function call */ + /* A choice of two pins can beused to control the brake, GPIO0 or GPIO1 selectable via jumper JP209 */ + if (pin_option == GPIO0) + { + /* Link option JP209 2-3 */ + if (brake_onoff == BRAKE_ON) + { + DigitalOut_Pin19 = 1; + } + else{ + DigitalOut_Pin19 = 0; + } + } + + if (pin_option == GPIO1) + { + /* Link option JP209 1-2 */ + /* Not implmented */ + } + } + + + +/* Power control of motor speed controller using PWM */ +void RSEDP_MC1_Set_Motor_Speed_Duty(float motor_speed_duty, uint8_t pin_option) + { + /* This function controls the speed of the motor by controlling the PWM duty of the bridge */ + /* The duty is fed by a PWM signal either from EVG0_GPIO40 or EVG4_GPIO48 selectable via link option JP204 and link JP203 & JP205 */ + if (pin_option == EVG0_GPIO40) + { + /* Link option JP204 1-2 and Link JP203 2-3 and JP205 1-2 */ + PwmOut_Pin23 = (1.0f - motor_speed_duty); + } + + if (pin_option == EVG4_GPIO48) + { + /* Link option JP204 2-3 and Link JP203 2-3 and JP205 1-2 */ + /* not implmented */ + + } + + + } + + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_Test.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,1393 @@ +/* Hardware Tests for RS-EDP Platform Using MBED Module */ +/* ************** */ + +/* Version 3.0 */ + + +/* This module is to test the hardware on the MCBSTR91x Module. */ + + +#include "mbed.h" /* Header file for mbed module */ +#include "misra_types.h" /* MISRA Types */ +#include "defines.h" /* User defines */ +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Devices defined hhere */ + +#include "RSEDP_Mbed_Module.h" /* all the low level peripheral drivers on te mbed module - IO ports, UART, SPI, I2C etc */ +#include "RSEDP_Base_Board.h" /* All the base board functions - EEPROM and erial latch */ +#include "RSEDP_Comms_Module.h" /* Functions to control the real time clock */ +#include "RSEDP_Digital_IO_Module.h" /* All the functions to control the serial input and output latches */ +#include "RSEDP_Analogue_Module.h" /* Functions to control digital pot and serial ADC */ +#include "RSEDP_MC1.h" /* Brushed DC Motor Drive MC1 Module */ +#include "RSEDP_Test_MC2.h" + + + + +/* Global Function prototype Here */ +void RSEDP_test_all(void); + + +/* Local Menu functions */ +static void Test_Processor_Module_Menu(void); +static void Test_Base_Board_Menu(void); +static void Test_Comms_Module_Menu(void); +static void Test_Digital_IO_Module_Menu(void); +static void Test_Analogue_Module_Menu(void); +static void Test_MC1_Module_Menu(void); + +/*Processor Board Tests */ +static void test_mbed_LEDs(void); +static void test_mbed_UART0(void); +static void test_mbed_UART1(void); +static void test_mbed_CNTRL_I2C_Master_Mode(void); +static void test_mbed_CNTRL_SPI_Master_Mode(void); + +/* Base Board Tests */ +static void test_BB_24LC32(uint8_t Slave_Address); +static void test_BB_PCA9675(uint8_t Slave_Address); +static void test_BB_RESET_Button(void); + +/* Communication Board Tests */ +static void test_PCF8583(uint8_t Slave_Address); + +/* Digital I/O board Tests */ +static void test_digital_output_PCA9555(uint8_t Slave_Address); +static void test_digital_input_PCA9555(uint8_t Slave_Address); + +/* Analogue Module Tests */ +static void test_MAX1x3x(uint8_t Slave_Address); +static void test_AD5263(uint8_t Slave_Address); + +/* MC1 Tests */ +static void test_MC1_VDCLINK(void); +static void test_MC1_VSENSE(void); +static void test_MC1_Read_Encoders(void); +static void test_MC1_Brakes(void); +static void test_MC1_Set_Direction(void); +static void test_MC1_Speed_Ramp_UpDown(void); +static void test_MC1_Set_Speed_PWM_Duty(void); +static void test_MC1_Stop_Motor(void); + + +static void delay_ms(uint16_t time_delay); + + + + +/* Main Test Selection Menu */ +void RSEDP_test_all(void) + { + uint16_t keypress = 0u; + + while(1) + { + pc.printf("\n\n\rMain Top Level Test Menu\n\n\r"); + pc.printf("1. Processor Module Test\n\r"); + pc.printf("2. Base Board Tests\n\r"); + + if (COMMS_MODULE_FITTED == YES) + { + pc.printf("3. Communications Module Tests\n\r"); + } + if (DIGITAL_IO_MODULE_FITTED == YES) + { + pc.printf("4. Digital I/O Module Tests\n\r"); + } + if (ANALOGUE_MODULE_FITTED == YES) + { + pc.printf("5. Analogue Module Tests\n\r"); + } + if (MOTOR_MC1_MODULE_FITTED == YES) + { + pc.printf("6. Brushed DC Motor Drive MC1 Module Tests\n\r"); + } + if (MOTOR_MC2_MODULE_FITTED == YES) + { + pc.printf("7. Brushless DC Motor Drive MC2 Module Tests\n\r"); + } + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + + if (keypress == '1') Test_Processor_Module_Menu(); + if (keypress == '2') Test_Base_Board_Menu(); + if (COMMS_MODULE_FITTED == YES) + { + if (keypress == '3') Test_Comms_Module_Menu(); + } + if (DIGITAL_IO_MODULE_FITTED == YES) + { + if (keypress == '4') Test_Digital_IO_Module_Menu(); + } + if (ANALOGUE_MODULE_FITTED == YES) + { + if (keypress == '5') Test_Analogue_Module_Menu(); + } + if (MOTOR_MC1_MODULE_FITTED == YES) + { + if (keypress == '6') Test_MC1_Module_Menu(); + } + if (MOTOR_MC2_MODULE_FITTED == YES) + { + if (keypress == '7') I2C_MMSC_Test_Suite(); + } + + } + } + + +/* Test The Microprocessor Module */ +static void Test_Processor_Module_Menu(void) + { + uint16_t keypress=0; + + while(1) + { + pc.printf("\n\n\rProcessor Module Test Menu\n\n\r"); + pc.printf("1. LED Test\n\r"); + pc.printf("2. UART0 Test\n\r"); + pc.printf("3. UART1 Test\n\r"); + pc.printf("4. CNTRL I2C Master Mode Test\n\r"); + pc.printf("5. CNTRL SPI Master Mode Test\n\r"); + + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + + if (keypress=='1') test_mbed_LEDs(); + if (keypress=='2') test_mbed_UART0(); + if (keypress=='3') test_mbed_UART1(); + if (keypress=='4') test_mbed_CNTRL_I2C_Master_Mode(); + if (keypress=='5') test_mbed_CNTRL_SPI_Master_Mode(); + if (keypress=='\r') break; + + } + } + + +/* This is the menu for the Base Board Tests */ +static void Test_Base_Board_Menu(void) + { + uint16_t keypress = 0u; + + while(1) + { + pc.printf("\n\n\rBase Board Test Menu\n\n\r"); + pc.printf("1. DIP Switch via PCA9675 Serial Input Latch\n\r"); + pc.printf("2. 24LC32 Serial EEPROM Test\n\r"); + pc.printf("3. Reset Button Test\n\r"); + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + + if (keypress == '1') test_BB_PCA9675(PCA9675_BASE_BOARD); + if (keypress == '2') test_BB_24LC32(M24C32_BASE_BOARD); + if (keypress == '3') test_BB_RESET_Button(); + if (keypress == '\r') break; + } + } + +/* Test The Communications Module */ +static void Test_Comms_Module_Menu(void) + { + uint16_t keypress=0; + + while(1) + { + pc.printf("\n\n\rCommunications Module Test Menu\n\r"); + pc.printf("1 PCF8385 Real Time Clock Test\n\r"); +// pc.printf("2 CAN2.0B Test\n\r"); + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + + if (keypress=='1') test_PCF8583(PCF8583_COMMS_MODULE); +// if (keypress=='2') test_CAN(); + if (keypress=='\r') break; + } + } + +/* Test The Digital I/O Module */ +static void Test_Digital_IO_Module_Menu(void) + { + uint16_t keypress=0; + + while(1) + { + pc.printf("\n\n\rDigital I/O Module Test Menu\n\n\r"); + pc.printf("1. Serial Digital Output OUT_P0(x) & OUT_P1(x)\n\r"); + pc.printf("2. Serial Digital Input IN_P0(x) & IN_P1(x)\n\r"); + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + if (keypress == '1') test_digital_output_PCA9555(PCA9555_DIGITAL_IO_OUT); + if (keypress == '2') test_digital_input_PCA9555(PCA9555_DIGITAL_IO_IN); + if (keypress == '\r') break; + + } + } + + +/* Test The Analogue Module */ +static void Test_Analogue_Module_Menu(void) + { + uint16_t keypress=0; + + while(1) + { + pc.printf("\n\n\rAnalogue Module Test Menu\n\n\r"); + pc.printf("1. MAX1x38 I2C Serial A to D Converter\n\r"); /* Production 10 bit ADC option */ + pc.printf("2. AD5263 I2C Digital Potentiometer\n\r"); + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + + if (keypress == '1') test_MAX1x3x(MAX1X3X_ANALOGUE_ADC); + if (keypress == '2') test_AD5263(AD5263_ANALOGUE_DIGITAL_POT); + if (keypress == '\r') break; + + } + } + + +/* This is the menu for the Brushed DC Motor Control MC! Module Tests */ +static void Test_MC1_Module_Menu(void) + { + uint16_t keypress = 0u; + + while(1) + { + pc.printf("\n\n\rBrushed DC Motor Drive Module MC1 Test Menu\n\n\r"); + pc.printf("1. Read the VDCLINK Voltage\n\r"); + pc.printf("2. Read the VSENSE Voltage\n\r"); + pc.printf("3. Read the Encoder0 & Encoder 1 Input Signals\n\r"); + pc.printf("4 Test the Brake ON & OFF Signal\n\r"); + pc.printf("5 Set the direction of rotation\n\r"); + pc.printf("6 Ramp the Motor Speed PWM Duty Up & Down\n\r"); + pc.printf("7 Set the Motor PWM Duty\n\r"); + pc.printf("8 Stop the motor\n\r"); + + pc.printf("\n\rPlease select one of the above tests\r\n"); + + keypress = pc.getc(); + + if (keypress == '1') test_MC1_VDCLINK(); + if (keypress == '2') test_MC1_VSENSE(); + if (keypress == '3') test_MC1_Read_Encoders(); + if (keypress == '4') test_MC1_Brakes(); + if (keypress == '5') test_MC1_Set_Direction(); + if (keypress == '6') test_MC1_Speed_Ramp_UpDown(); + if (keypress == '7') test_MC1_Set_Speed_PWM_Duty(); + if (keypress == '8') test_MC1_Stop_Motor(); + if (keypress == '\r') break; + } + } + + + + + + + +/* Processor Board Tests Starts Here */ +/* LED Tests on the Processor Card */ +static void test_mbed_LEDs(void) + { + uint8_t n = 0; + + + pc.printf("\n\n\n\rTesting the LEDs on the mbed module...\n\n\r"); + for (n = 0; n < 5; n++) + { + User_Led1 = LED_ON; /* Flash the LED to signal the world the firmware is running */ + User_Led2 = LED_ON; /* Flash the LED to signal the world the firmware is running */ + User_Led3 = LED_ON; /* Flash the LED to signal the world the firmware is running */ + User_Led4 = LED_ON; /* Flash the LED to signal the world the firmware is running */ + wait(0.5); + + User_Led1 = LED_OFF; /* Flash the LED to signal the world the firmware is running */ + User_Led2 = LED_OFF; /* Flash the LED to signal the world the firmware is running */ + User_Led3 = LED_OFF; /* Flash the LED to signal the world the firmware is running */ + User_Led4 = LED_OFF; /* Flash the LED to signal the world the firmware is running */ + wait(0.5); + + } + pc.printf("Finished testing the LEDs...\n\n\r"); + } + + + +/* UART0 Tests */ +static void test_mbed_UART0(void) + { + sint32_t keypress = 0; + + pc.printf("\n\n\n\rTesting UART0\n\n\r"); + UART0.printf("\n\n\rIf you can read this information then UART0 TRANSMIT is working correctly...\n\r"); + UART0.printf("Now to test the UART0 RECEIVE Input...\n\r"); + pc.printf("Now please keys on the keyboard and see if they are echoed on the monitor...\n\r"); + UART0.printf("Now please keys on the keyboard and see if they are echoed on the monitor...\n\r"); + UART0.printf("Press the Return key to quit...\n\r"); + pc.printf("Press the Return key to quit...\n\r"); + + do { + keypress = UART0.getc(); /* get a keypress */ + + UART0.putc(keypress); + UART0.printf("\r"); + + } while(keypress != '\r'); + + pc.printf("\n\rTest finished\n\r"); + UART0.printf("\n\rTest finished\n\r"); + } + + +/* UART1 Tests */ +static void test_mbed_UART1(void) + { + sint32_t keypress = 0; + + pc.printf("\n\n\n\rTesting UART1\n\n\r"); + UART1.printf("\n\n\rIf you can read this information then UART1 TRANSMIT is working correctly...\n\r"); + UART1.printf("Now to test the UART1 RECEIVE Input...\n\r"); + pc.printf("Now please keys on the keyboard and see if they are echoed on the monitor...\n\r"); + UART1.printf("Now please keys on the keyboard and see if they are echoed on the monitor...\n\r"); + UART1.printf("Press the Return key to quit...\n\r"); + pc.printf("Press the Return key to quit...\n\r"); + + do { + keypress = UART1.getc(); /* get a keypress */ + + UART1.putc(keypress); + UART1.printf("\r"); + + } while(keypress != '\r'); + + pc.printf("\n\rTest finished\n\r"); + UART1.printf("\n\rTest finished\n\r"); + } + + + + + +/* Test The CNTRL I2C in Master Mode */ +static void test_mbed_CNTRL_I2C_Master_Mode(void) + { + sint8_t cmd[1] = {0}; + sint8_t keypress = 0; + sint32_t Ack_Status = 0; + uint8_t n = 0; + + pc.printf("\n\n\n\rTesting the CNTRL I2C Peripheral...\n\r"); + pc.printf("Press return key to finish test.\n\n\r"); + cmd[0] = 0x0; /* dummy data to transmit */ + + + do { + pc.printf("Sending out the byte 0x00 to 8 bit address : %d \n\r", n); + + Ack_Status = CNTRL_i2c.write(n, cmd, 1); /* Send an I2C byte */ + if (Ack_Status == ACK) + { + pc.printf("Acknowledge received\n\r"); + } + else{ + pc.printf("No Acknowledge received\n\r"); + } + + n++; + keypress = pc.getc(); /* get a keypress */ + + } while (keypress != '\r'); + + pc.printf("Finished testing CNTRL I2C Peripheral.\n\n\r"); + } + + + +/* Test The CNTRL SPI in Master Mode */ +static void test_mbed_CNTRL_SPI_Master_Mode(void) + { + uint8_t n = 1; + sint8_t keypress = 0; + + pc.printf("\n\n\n\rTesting the CNTRL SPI Peripheral...\n\r"); + pc.printf("Press return key to finish test.\n\n\r"); + + do { + pc.printf("Sending out the byte:%d...\n\r",n); + + CNTRL_SPI_Write_Byte(n); + n++; + + keypress = pc.getc(); /* get a keypress */ + + } while (keypress != '\r'); + + pc.printf("Finished testing CNTRL SPI Peripheral.\n\n\r"); + } + + + + + + + + +/* Base Board Tests Start Here */ +/* *************************** */ + +/* Test The I2C PCA9675 Serial Latch Device on the base board */ +static void test_BB_PCA9675(uint8_t Slave_Address) + { + + uint8_t port_zero = 0; + uint8_t port_one = 0; + uint16_t keypress = 0; + uint8_t n = 0; + sint32_t Ack_Status = 0; + uint8_t Switch_Status = 0; + + pc.printf("\n\n\n\rTest The DIP Switches Via The PCA9675 Serial Input Latch\n\n\r"); + + pc.printf("Writing to the latch, to configure the chip for input...\n\r"); + Ack_Status = RSEDP_BB_PCA9675_write_data(Slave_Address, 0xff,0xff); /* Write 0xff to the output latches so we can read the dip switches */ + if (Ack_Status == ACK) + { + pc.printf("\n\rReading from the latch...\n\r"); + Ack_Status = RSEDP_BB_PCA9675_read_data(Slave_Address, &port_zero, &port_one); /* Read two bytes from the device */ + if (Ack_Status == ACK) + { + pc.printf("Value read...Port0: 0x%.2X",port_zero); + pc.printf(" and Port1: 0x%.2X\r\n",port_one); + + pc.printf("Turn each bit on and off independantly and press space bar to update screen...\n\r"); + pc.printf("To terminate this test press the Return key\n\r"); + + do { + for (n = 1; n < 9; n++) + { + Ack_Status = RS_EDP_BB_Read_DIP_Switch(n, &Switch_Status); + if (Switch_Status == DIP_SWITCH_CLOSED) + { + pc.printf("%.1d:ON ",n); + } + else{ + pc.printf("%.1d:OFF ",n); + } + } + + pc.printf("\r"); + + delay_ms(500); + + keypress = pc.getc(); /* get a keypress */ + + } while ((keypress != '\r') && (Ack_Status == ACK)); + } + } + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Received ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + + } + + + +/* Test The 32k bit 24LC32 Serial EEPROM on the Base Board */ +static void test_BB_24LC32(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + sint8_t I2C_Tx_Array[32]; + sint8_t I2C_Rx_Array[256]; + sint8_t n = 0; + uint16_t nn = 0; + uint8_t error_flag = 0; + + + pc.printf("\n\n\n\rTesting the 24LC32 Device....\n\n\r"); + + for (n=0;n<32;n++) + { + I2C_Tx_Array[n] = 255 - (n*4); /* Configure the array we want to write to the EEPROM */ + } + + n=0; + while(1) /* Clear receieve array */ + { + I2C_Rx_Array[n] = 0; + n++; + if (n == 0) break; + } + + + pc.printf("Writing one byte of data to the 24LC32 Device....\n\r"); + pc.printf("Writing the value 0x%.2X \n\r", EEPROM_TEST_BYTE); + Ack_Status = RSEDP_BB_eeprom_store_byte(Slave_Address, EEPROM_TEST_BYTE, 0x00); /* Store one byte in one location */ + if (Ack_Status == ACK) + { + pc.printf("Reading one byte from the EEPROM.\n\r"); + Ack_Status = RSEDP_BB_eeprom_read_byte(Slave_Address, &n, 0x0); /* Read one byte from one location */ + if (Ack_Status == ACK) + { + pc.printf("Value read...0x%.2X\n\r", n); + + + if (n != EEPROM_TEST_BYTE) + { + pc.printf("FAILED...Data read was different from the data written\n\r"); + while(1); + } + else{ + pc.printf("PASSED - Value read was the same as value written.\n\r"); + } + + + /* Writing Pages To The EEPROM */ + + pc.printf("\n\rWriting pages of data to the 24LC32 Device using page write....\n\r"); + Ack_Status = RSEDP_BB_eeprom_store_bytes(Slave_Address, I2C_Tx_Array, 32, 0x00); /* Write a 32 byte byte page to the I2C serial EEPROM. Note On a page boundary ! */ + + if (Ack_Status == ACK) + { + pc.printf("Reading back 32 bytes from the EEPROM.\n\r"); + Ack_Status = RSEDP_BB_eeprom_read_bytes(Slave_Address, I2C_Rx_Array,32, 0x0); /* Read multiple bytes back from the EEPROM */ + if (Ack_Status == ACK) + { + error_flag = 0; + for (n = 0; n < 32; n++) + { + if (I2C_Tx_Array[n] != I2C_Rx_Array[n]) + { + error_flag = 1; + } + } + + if (error_flag == 1) + { + pc.printf("FAILED...Data read was different from the data written\n\r"); + pc.printf("The transmit array was...\n\r"); + for (n = 0; n < 32; n++) + { + pc.printf("0x%.2X ", I2C_Tx_Array[n]); + } + + pc.printf("\n\r"); + pc.printf("The received array was...\n\r"); + for (n=0;n<32;n++) + { + pc.printf("0x%.2X ", I2C_Rx_Array[n]); + } + + while(1); + } + + else{ + pc.printf("PASSED - Value read was the same as value written.\n\r"); + } + + + /* Writing To The Whole Memory Area */ + pc.printf("\n\nWriting to the whole EEPROM memory address space...\n\r"); + + nn = 0; + do { + Ack_Status = RSEDP_BB_eeprom_store_byte(Slave_Address, (nn/8),nn); + pc.printf("."); + nn++; + wait(0.1); + } while ((Ack_Status == ACK) && (nn < 0x800)); + + pc.printf("\n\r\nChecking the EEPROM...\n\r"); + + if (Ack_Status == ACK) + { + error_flag = 0; + for (nn = 0; nn < 0x800; nn++) + { + Ack_Status = RSEDP_BB_eeprom_read_byte(Slave_Address, &n, nn); + + if (n != nn / 8) + { + error_flag = 1; + } + } + if (error_flag == 1) + { + pc.printf("Test FAILED - Data Read did not match the data written\n\n\r"); + while(1); + } + else{ + pc.printf("Test PASSED - EEPROM is working correctly\n\n\r"); + } + + + } + } + } + } + } + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Receieve ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + + pc.printf("Finished testing the 24LC32 Device....\n\n\r"); + } + + + +/* This funtction test the RESET Button on the base board */ +static void test_BB_RESET_Button(void) + { + pc.printf("\n\n\n\rTesting the RESET Button\n\r"); + pc.printf("Press The RESET Button and this program should reset back to the Main Test Menu\n\r"); + while(1); /* Wait for reset to be pressed */ + } + + + + + + +/* Communications Board Tests */ + +/* Test the serial RTC Device */ +static void test_PCF8583(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + uint8_t status_register = 0; + uint8_t RTC_Array[8]; + uint16_t keypress = 0; + uint16_t nn = 0; + uint8_t value = 0; + + pc.printf("\n\n\n\rTesting the PCA8583 Real Time Clock Chip...\n\r"); + pc.printf("Testing in CLOCK mode...\n\r"); + pc.printf("Configuring the device...\n\r"); + + Ack_Status = RSEDP_COM_setup_PCF8583(PCF8583_COMMS_MODULE,'C'); + + if (Ack_Status == ACK) + { + pc.printf("\n\rReading the status register...\n\r"); + Ack_Status = RSEDP_COM_PCF8583_Read_Status_Register(Slave_Address, &status_register); + } + if (Ack_Status == ACK) + { + pc.printf("Status Register = 0x%2X\r\n",status_register); + pc.printf("\n\rReading the Real Time Clock Contents\n\r"); + pc.printf("Press the retrun key to finish the test\n\r"); + + do { + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address,RTC_Array); + pc.printf("Time is "); + RSEDP_COM_Print_Time_Date_Year(RTC_Array); + pc.printf("\r"); + + keypress = pc.getc(); + + delay_ms(100); + + } while((keypress != '\r') && (Ack_Status == ACK)); + } + + if (Ack_Status == ACK) + { + pc.printf("\n\n\rWriting a new time and date to the RTC device\n\r"); + Ack_Status = RSEDP_COM_PCF8583_Set_Clock(Slave_Address,11,59,40,1,1); // 11:59AM and 45 seconds in AM/PM mode + RSEDP_COM_PCF8583_Set_Date(Slave_Address,6, 31,12,2008); + if (Ack_Status == ACK) + { + pc.printf("\n\rReading back the Real Time Clock Contents\n\r"); + } + pc.printf("Press the retrun key to finish the test\n\r"); + } + + if (Ack_Status == ACK) + { + do { + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + pc.printf("Time is "); + RSEDP_COM_Print_Time_Date_Year(RTC_Array); + pc.printf("\r"); + + keypress = pc.getc(); + + delay_ms(100); + + } while((keypress != '\r') && (Ack_Status == ACK)) ; + } + if (Ack_Status == ACK) + { + pc.printf("\n\n\rChanging to 24 hour notation\n\r"); + Ack_Status = RSEDP_COM_PCF8583_Set_Clock(Slave_Address,23,59,40,0,1); + if (Ack_Status == ACK) + { + Ack_Status = RSEDP_COM_PCF8583_Set_Date(Slave_Address,6, 31,12,2008); + pc.printf("\n\rReading back the Real Time Clock Contents\n\r"); + pc.printf("Press the return key to finish the test\n\r"); + } + } + if (Ack_Status == ACK) + { + do { + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + if (Ack_Status == ACK) + { + pc.printf("Time is "); + RSEDP_COM_Print_Time_Date_Year(RTC_Array); + pc.printf("\r"); + + keypress = pc.getc(); + + delay_ms(100); + } + + } while((keypress != '\r') && (Ack_Status == ACK)); + } + if (Ack_Status == ACK) + { + pc.printf("\n\n\rStopping the CLOCK\n\r\n"); + pc.printf("Press the return key to finish the test\n\r"); + + Ack_Status = RSEDP_COM_PCF8583_Stop_Clock(Slave_Address); + do { + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + if (Ack_Status == ACK) + { + pc.printf("Time is "); + RSEDP_COM_Print_Time_Date_Year(RTC_Array); + pc.printf("\r"); + keypress = pc.getc(); + + delay_ms(100); + } + + } while((keypress != '\r') && (Ack_Status == ACK)); + } + + if (Ack_Status == ACK) + { + pc.printf("\n\n\rStarting the CLOCK again\n\r\n"); + pc.printf("Press the return key to finish the test\n\r"); + + Ack_Status = RSEDP_COM_PCF8583_Start_Clock(Slave_Address); + do { + Ack_Status = RSEDP_COM_PCF8583_Read_RTC(Slave_Address, RTC_Array); + if (Ack_Status == ACK) + { + pc.printf("Time is "); + RSEDP_COM_Print_Time_Date_Year(RTC_Array); + pc.printf("\r"); + keypress = pc.getc(); + + delay_ms(100); + } + + } while((keypress != '\r') && (Ack_Status == ACK)); + } + + if (Ack_Status == ACK) + { + pc.printf("\n\n\rTesting the SRAM area of the RTC...\n\r\n"); + pc.printf("Writing Data to the memory...\n\r"); + + nn = 0x10; + do { + Ack_Status = RSEDP_COM_PCF8583_Write_SRAM(Slave_Address, nn/2, nn); + nn++; + } while ((nn<0x100) && ( Ack_Status == ACK)); + + if (Ack_Status == ACK) + { + pc.printf("Finished writing the SRAM area of the RTC.\n\r"); + pc.printf("Checking the SRAM area of the RTC...\n\r"); + } + + if (Ack_Status == ACK) + { + nn = 0x10; + do { + Ack_Status = RSEDP_COM_PCF8583_Read_SRAM(Slave_Address, &value, nn); + + if (value != nn/2) + { + pc.printf("FAILED TEST - The data read is different from the data written\n\r"); + pc.printf("Failed at memory location 0x%.3X\n\r",nn); + pc.printf("The data written was 0x%.2X\n\r",nn/2); + pc.printf("The data read was 0x%.2X\n\r",value); + while(1); /* Error reading from SRAM */ + } + nn++; + } while((nn < 0x100) && (Ack_Status == ACK)); + } + if (Ack_Status == ACK) + { + pc.printf("PASSED TEST\n\r"); + } + + } + + + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Receieve ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + + pc.printf("\n\rFinished testing the PCF8583 Real Time Clock device\n\r\n"); + } + + + + + + + +/* Digital I/O Module Tests */ + +/* Test the ULN2003 output with the PCA9555A Device */ +static void test_digital_output_PCA9555(uint8_t Slave_Address) + { + /* assume the I2C and I/O direction have been set up */ + + sint32_t Ack_Status = 0; + uint8_t port_pin = 1; + uint8_t temp8 = 1; + + pc.printf("\n\n\n\rTesting the Digital Outputs under I2C Control...\n\r"); + pc.printf("Press the return key to sequence through the tests.\n\r"); + + Ack_Status = RSEDP_DIO_setup_PCA9555(Slave_Address, 0x00, 0x00); /* Configure Both Port 0 and Port 1 as outputs */ + + if (Ack_Status == ACK) + { + pc.printf("\n\rTesting the Port0 of the PCA9555...\n\r"); + + port_pin = 0; + + do { + pc.printf("\n\rTurning ON the output OUT_P0(%.1d)", port_pin); + + Ack_Status = RSEDP_DIO_PCA9555_Write_Word(Slave_Address, temp8,0x00); + + if (Ack_Status == ACK) + { + pc.getc(); + + pc.printf("\n\rTurning OFF the output OUT_P0(%.1d)", port_pin); + + Ack_Status = RSEDP_DIO_PCA9555_Write_Word(Slave_Address, 0x00, 0x00); + } + if (Ack_Status == ACK) + { + pc.getc(); + } + + temp8 = (temp8 << 1); + pc.printf("\n\r"); + port_pin++; + + } while ((port_pin < 8) && (Ack_Status == ACK)); + + } + if (Ack_Status == ACK) + { + pc.printf("\n\rTesting the Port1 of the PCA9555...\n\r"); + temp8 = 0x01; + + port_pin = 0; + for (port_pin = 0; port_pin < 8; port_pin++) + do { + pc.printf("\n\rTurning ON the output OUT_P1(%.1d)", port_pin); + + Ack_Status = RSEDP_DIO_PCA9555_Write_Word(Slave_Address, 0x00, temp8); + if (Ack_Status == ACK) + { + pc.getc(); + + pc.printf("\n\rTurning OFF the output OUT_P1(%.1d)",port_pin); + + Ack_Status = RSEDP_DIO_PCA9555_Write_Word(Slave_Address, 0x00,0x00); + } + pc.getc(); + + temp8 = (temp8 << 1); + pc.printf("\n\r"); + port_pin++; + } while ((port_pin < 8) && (Ack_Status == ACK)); + } + + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Receieve ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + pc.printf("\n\r\nFinished testing the Digital Output under I2C Control\r\r\n"); + } + + + + + + +/* Test The Inputs to the PCA9555 serial I/O device */ +/* The device is configured as an input device. */ +static void test_digital_input_PCA9555(uint8_t Slave_Address) + { + + sint32_t Ack_Status = 0; + uint8_t port_one = 0; + uint8_t port_zero = 0; + uint16_t keypress = 0; + uint16_t input_data = 0; + uint8_t n= 0; + + + pc.printf("\n\n\n\rTesting the Digital Inputs via I2C Control...\n\r"); + pc.printf("Press the return key to sequence through the tests.\n\r"); + + Ack_Status = RSEDP_DIO_setup_PCA9555(Slave_Address, 0xff, 0xff); /* Configure Both Port 0 and Port 1 as inputs */ + + if (Ack_Status == ACK) + { + pc.printf("\n\rTesting the Ports of the I2C device in input mode...\n\r"); + + pc.printf("\n\rReading from the device...\n\r"); + pc.printf("To terminate this test press the Return key\n\r\n"); + + pc.printf("Value read of the Port 0 and Port 1 pins are:\n\r"); + pc.printf(" Port 0 Port 1 \n\r"); + pc.printf("0 1 2 3 4 5 6 7 {} 0 1 2 3 4 5 6 7\n\r"); + + + do { + Ack_Status = RSEDP_DIO_PCA9555_Read_Data(Slave_Address, &port_zero, &port_one); /* Read the DIP Switches onthe base board */ + + if (Ack_Status == ACK) + { + input_data = ((port_one << 8) + port_zero); + for (n = 0u; n < 16u; n++) + { + if (n == 8) + { + pc.printf(" "); + } + if ((input_data & 0x0001) == 0u) + { + pc.printf("O "); + } + else{ + pc.printf("1 "); + } + + input_data = input_data >> 1; + } + + pc.printf("\r"); + keypress = pc.getc(); + } + + } while ((keypress != '\r') && (Ack_Status == ACK)); + } + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Receieve ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + + pc.printf("\n\r\nFinished testing the Serial Digital Input\r\r\n"); + + } + + + + +/* Analogue Module Tests */ + +/* Test MAX1038 ADC On AN16 Module */ +static void test_MAX1x3x(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + uint8_t uiChannel = 0u; + uint8_t u8Result = 0u; + uint16_t u16Result = 0u; + uint8_t keypress = 0u; + + pc.printf("\n\rTesting the serial ADC on the Analogue Module...\n\r"); + + pc.printf("\n\rConfiguring the MAX1x3x %d bit ADC converter...\n\r",ADC_BITSIZE); + Ack_Status = RSEDP_AM_Init_MAX1x3x(Slave_Address) ; + if (Ack_Status == ACK) + { + pc.printf("\n\rMAX1x3x Now Configured"); + + + /* Test all channels */ + pc.printf("\n\rPress 'RETURN' key to terminate the test\n\rChannel Readings Are:\n\r"); + pc.printf("CH00 CH01 CH02 CH03 CH04 CH05 CH06 CH07 CH08 CH09 CH10 CH11\n\r"); + do { + for(uiChannel = 0u ; uiChannel < MAX1x3x_No_Of_Channels; uiChannel++) + { + if (ADC_BITSIZE == ADC_8BIT) /* 8 bit ADC fitted to analogue module */ + { + Ack_Status = RSEDP_AM_MAX103x_ReadChannel(Slave_Address, &u8Result, uiChannel); /* this line for 8 bit ADC */ + u16Result = u8Result; + } + else{ /* 10 bit ADC fitted to analogue module */ + Ack_Status = RSEDP_AM_MAX113x_ReadChannel(Slave_Address, &u16Result, uiChannel); /* this line for 10bit ADC */ + } + + pc.printf("0x%.3X ", (u16Result & 0x01ff)); + } + + pc.printf("\r"); + delay_ms(500u); + + keypress = pc.getc(); + + } while ((keypress != '\r') && (Ack_Status == ACK)); + } + + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Receieve ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + + pc.printf("\n\rfinished testing the ADC on the Analogue Module\n\r"); + } + + + + +/* Test AD5263 Digital Pot */ +static void test_AD5263(uint8_t Slave_Address) + { + sint32_t Ack_Status = 0; + uint8_t channel = 0; + uint32_t resistance =0; + + pc.printf("\n\rTesting the serial digital potentiometer on the Analogue Module...\n\r"); + + pc.printf("\n\rInitialising the AD5263 device...\n\r"); /* Initialise the on board ADC */ + Ack_Status = RSEDP_AM_Init_AD5263(Slave_Address) ; + + if (Ack_Status == ACK) + { + pc.printf("\n\rAD5263 Now Configured"); + + + for (channel = 1; channel < 5; channel++) + { + pc.printf("\n\rTesting the variable resistor on channel: %1d\n\r", channel); + resistance = 0u; + do { + pc.printf("\rSetting Resistance to: %5d ohms", resistance); + Ack_Status = RSEDP_AM_Set_AD5263_resistance(Slave_Address, channel, resistance); + resistance += (AD5263_Max_Resistance/256); + delay_ms(50); + } while ((Ack_Status == ACK) && (resistance < AD5263_Max_Resistance)); + pc.printf("\n\r"); + } + } + + if (Ack_Status == ACK) + { + Ack_Status = RSEDP_AM_Init_AD5263(Slave_Address) ; /* Reset the device back to power up state */ + } + + if (Ack_Status != ACK) + { + pc.printf("*** NO Acknowledge Receieve ***\n\r"); + pc.printf("Operation aborted\n\r"); + } + + pc.printf("\n\rFinished testing the AD5263 Device\n\r"); + } + + + + + +/* Motor Control MC1 Tests */ + +/* Test the VDCLINK Voltage */ +static void test_MC1_VDCLINK(void) + { + sint8_t keypress = 0; + uint16_t vdc_measured = 0; + float vbus_voltage = 0.0f; + + pc.printf("\n\rTesting the VDCLINK Voltage on the MC1 Brushed DC Motor Module...\n\r"); + do { + + vdc_measured = RSEDP_MC1_Read_VDCLINK(AN2); + vbus_voltage = ((float)vdc_measured / VSENSE_DIVISOR); + + pc.printf("The ADC Voltage measured is %4dmV, which is a bus voltage of %.0fV\r", vdc_measured, vbus_voltage); + + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\rFinished testing the VDCLINK bus voltage\n\r"); + } + + + +/* Test the motor current sense voltage */ +static void test_MC1_VSENSE(void) + { + sint8_t keypress = 0; + uint16_t vdc_measured = 0; + float motor_current = 0.0f; + + pc.printf("\n\rTesting the VSENSE Motor Current Voltage Feedback on the MC1 Brushed DC Motor Module...\n\r"); + do { + + vdc_measured = RSEDP_MC1_Read_VSENSE(AN0); + motor_current =( (float)vdc_measured /(CURRENT_TRANSFER_RATIO * MOTOR_CURRENT_SENSE_RESISTOR)); /* Work out current in mA */ + + pc.printf("The ADC Voltage measured is %4dmV, which is aprrox motor_current of %.0fmA\r", vdc_measured, motor_current); + + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\rFinished testing the VSENSE motor current sense input\n\r"); + } + + + + + + +/* Test the encoder inputs */ +static void test_MC1_Read_Encoders(void) + { + sint8_t keypress = 0; + uint8_t switch_status0 = 0; + uint8_t switch_status1 = 0; + + pc.printf("\n\rTesting the Encoder0 & 1 from P301 connector Pin8 & Pin10 on the MC1 Module...\n\r"); + pc.printf("The Encoder inputs are:\n\r"); + + do { + switch_status0 = RSEDP_MC1_Read_Encoder0_Input(EVG6_GPIO52); + switch_status1 = RSEDP_MC1_Read_Encoder1_Input(EVG7_GPIO54); + + if (switch_status0 == 0) + { + pc.printf("Encoder0: OPEN ,"); + } + else{ + pc.printf("Encoder0: CLOSED,"); + } + + if (switch_status1 == 0) + { + pc.printf("Encoder1: OPEN \r"); + } + else{ + pc.printf("Encoder1: CLOSED\r"); + } + + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\rFinished testing the Encoder inputs from P301\n\r"); + } + + +/* test the Brake control signal */ +static void test_MC1_Brakes(void) + { + sint8_t keypress = 0; + + pc.printf("\n\rTesting the Brake control signal to the motor control module...\n\r"); + + do { + pc.printf("Turning ON the brakes...\n\r"); + RSEDP_MC1_Brake(BRAKE_ON, GPIO0); /* Brake ON */ + pc.printf("Press any key to turn the brake OFF\n\r"); + pc.getc(); + RSEDP_MC1_Brake(BRAKE_OFF, GPIO0); /* Brake OFF */ + pc.printf("Press any key to turn the brake ON again or 'Return' to terminate test\n\r"); + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\rFinished testing the Brake control signal \n\r"); + } + +/* test the direction Signal */ +static void test_MC1_Set_Direction(void) + { + uint8_t motor_direction = FORWARD; + uint8_t keypress = 0; + + pc.printf("\n\rTesting the motor rotation direction signal...\n\r"); + + do { + pc.printf("Setting the motor direction as:"); + if (motor_direction == FORWARD) + { + pc.printf("FORWARD\r"); + } + if (motor_direction == REVERSE) + { + pc.printf("REVERSE\r"); + } + + RSEDP_MC1_Set_Motor_Direction(motor_direction, EVG1_GPIO42); /* Set the motor direction */ + + keypress = pc.getc(); + + if (motor_direction == FORWARD) + { + motor_direction = REVERSE; + } + else{ + motor_direction = FORWARD; + } + } while (keypress != '\r'); + + pc.printf("\n\rFinished motor direction test\n\r"); + } + + +/* Testing the motor speed control */ +static void test_MC1_Speed_Ramp_UpDown(void) + { + + uint8_t n= 0; + float motor_current = 0; + uint16_t vdc_measured = 0; + + pc.printf("\n\rTesting the speed control of the motor control module...\n\r"); + + pc.printf("Brake turned OFF\n\r"); + RSEDP_MC1_Brake(BRAKE_OFF, GPIO0); /* Brake OFF */ + + pc.printf("Ramping Up\n\r"); + + for (float ff = 0; ff < 1.0f; ff += 0.01f) + { + RSEDP_MC1_Set_Motor_Speed_Duty(ff, EVG0_GPIO40); + pc.printf("Duty %3.0f%%\r", (ff*100)); + wait(0.1); + } + + pc.printf("\n\rat full speed\n\r"); + + for (n = 0; n < 100; n++) + { + vdc_measured = RSEDP_MC1_Read_VSENSE(AN0); + motor_current =( (float)vdc_measured /(CURRENT_TRANSFER_RATIO * MOTOR_CURRENT_SENSE_RESISTOR)); /* Work out current in mA */ + + pc.printf("The ADC Voltage measured is %4dmV, which is aprrox motor_current of %.0fmA\r", vdc_measured, motor_current); + wait(0.1); + } + + + pc.printf("Ramping Down\n\r"); + + for (float ff=1.0; ff > 0.0f; ff-= 0.01f) + { + RSEDP_MC1_Set_Motor_Speed_Duty(ff, EVG0_GPIO40); + pc.printf("Duty %3.0f%%\r",(ff*100)); + wait(0.1); + } + + pc.printf("\n\rMotor Stopped\n\r"); + RSEDP_MC1_Set_Motor_Speed_Duty(0.0f, EVG0_GPIO40); + + RSEDP_MC1_Brake(BRAKE_ON, GPIO0); /* Brake ON */ + pc.printf("Brake turned ON\n\r"); + pc.printf("\n\rFinished testing the speed control of the motor control module\n\r"); + } + + +static void test_MC1_Set_Speed_PWM_Duty(void) + { + uint8_t keypress = 0; + float ff = 0.0f; + + pc.printf("\n\rSet the Motor Speed PWM Duty Ratio...\n\r"); + pc.printf("Use the '+' and '-' Keys to increase the duty and 'return' key to end.\n\r"); + + pc.printf("Brake turned OFF\n\r"); + RSEDP_MC1_Brake(BRAKE_OFF, GPIO0); /* Brake OFF */ + + + do { + keypress = pc.getc(); + if (keypress == '+') + { + ff = (ff + 0.1f); + if (ff > 1.0) ff = 1.0; + } + if (keypress == '-') + { + ff = (ff - 0.1f); + if (ff < 0.0) ff = 0.0; + } + + RSEDP_MC1_Set_Motor_Speed_Duty(ff, EVG0_GPIO40); + pc.printf("Duty %3.0f%%\r", (ff*100)); + } while (keypress != '\r'); + + pc.printf("\n\rLeaving Menu option with PWM duty still set\n\r"); + + } + + + +/* Stopping the motor */ +static void test_MC1_Stop_Motor(void) + { + pc.printf("\n\rRamping Down the motor\n\r"); + + for (float ff=0.5; ff > 0.0f; ff-= 0.01f) + { + RSEDP_MC1_Set_Motor_Speed_Duty(ff, EVG0_GPIO40); + wait(0.1); + } + + pc.printf("Motor Stopped\n\r"); + RSEDP_MC1_Set_Motor_Speed_Duty(0.0f, EVG0_GPIO40); + + RSEDP_MC1_Brake(BRAKE_ON, GPIO0); /* Brake ON */ + pc.printf("Brake turned ON\n\r"); + + pc.printf("\n\rFinished stopping the motor\n\r"); + + } + + + + + + + + + + + + + +/* General Purpose Delay Routine */ +static void delay_ms(uint16_t time_delay) + { + uint32_t nnnn=0; + + while(time_delay--!=0x0) + { + for (nnnn=0;nnnn<0x08ff;nnnn++); /* 1ms Loop */ + } + } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/RSEDP_Test_MC2.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,1163 @@ +/* Test Menu For I2C Master Mode System Controller */ +/* *********************************************** */ + + +/* Include Files Here */ +#include "mbed.h" /* Header file for mbed module */ +#include "misra_types.h" /* MISRA Types */ +#include "defines.h" /* User defines */ +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Devices defined hhere */ + +#include "RSEDP_Mbed_Module.h" /* all the low level peripheral drivers on te mbed module - IO ports, UART, SPI, I2C etc */ +#include "RSEDP_Base_Board.h" /* All the base board functions - EEPROM and erial latch */ +#include "RSEDP_Comms_Module.h" /* Functions to control the real time clock */ +#include "RSEDP_Digital_IO_Module.h" /* All the functions to control the serial input and output latches */ +#include "RSEDP_Analogue_Module.h" /* Functions to control digital pot and serial ADC */ +#include "RSEDP_MC1.h" /* Brushed DC Motor Drive MC1 Module */ + + +#include "MC2_Motor_Driver_I2C_Master.h" + + +#define MOTOR_SPEED_DEMAND_FORWARD_MAX 1023u +#define MOTOR_SPEED_DEMAND_FORWARD_MIN 1u +#define MOTOR_SPEED_DEMAND_REVERSE_MAX 1023u +#define MOTOR_SPEED_DEMAND_REVERSE_MIN 1u +#define RAMP_UP_SPEED_MAX 1023u +#define RAMP_UP_SPEED_MIN 1u +#define RAMP_DOWN_SPEED_MAX 1023u +#define RAMP_DOWN_SPEED_MIN 1u + + +/* Global Function Prototypes here */ +void I2C_MMSC_Test_Suite(void); /* Suites of tests for Master Mode Control */ + + + +/* Local Static Function Prototypes Here */ +static void i2C_control_submenu(void); +static sint32_t i2C_cs_ping(void); +static sint32_t i2C_cs_reset(void); +static sint32_t i2C_cs_emergency_stop(void); +static sint32_t i2C_cs_normal_stop(void); +static sint32_t i2C_cs_set_new_direction_forward(void); +static sint32_t i2C_cs_set_new_direction_reverse(void); +static sint32_t choose_the_ramp_up_speed(void); +static sint32_t i2C_cs_set_ramp_up_speed(uint16_t rampup); +static sint32_t choose_the_ramp_down_speed(void); +static sint32_t i2C_cs_set_ramp_down_speed(uint16_t rampdown); +static sint32_t choose_the_motor_demand_forward(void); +static sint32_t i2C_cs_set_motor_demand_forward(uint16_t demandforward); +static sint32_t choose_the_motor_demand_reverse(void); +static sint32_t i2C_cs_set_motor_demand_reverse(uint16_t demandreverse); +static sint32_t choose_the_rotary_encoder_counts(void); +static sint32_t i2C_cs_set_rotary_encoder_counts(uint32_t rotary_encoder_counter); +static sint32_t i2C_cs_start_rotation(void); +static sint32_t i2C_cs_goto_home(void); + +static sint32_t i2C_cs_read_RPMs(void); +static sint32_t i2C_cs_read_motor_currents(void); +static sint32_t i2C_cs_read_Vbus_voltages(void); +static sint32_t i2C_cs_read_demand_speed_potRPM(void); +static sint32_t i2C_cs_read_hall_sensors(void); +static sint32_t i2C_cs_read_status_flags(void); +static sint32_t i2C_cs_read_Maximum_RPM(void); +static sint32_t i2C_cs_read_Rotary_Encoder(void); + + +static void i2C_cs_execute_sequence(void); +static uint8_t get_a_number_digit(void); +static uint32_t get_a_complete_number(void); + + +/* Static Variables available at File Scope */ +static uint8_t Slave_Address = DSPIC_SLAVE_ADDRESS_MIN; + + + +/*This funtciton will control the other PIC on the board via I2C command */ +void I2C_MMSC_Test_Suite(void) + { + uint16_t keypress = 0u; + + + Slave_Address = DSPIC_SLAVE_ADDRESS_MIN; /* 7 bit slave address */ + + + setup_CNTRL_I2C_Master_Mode(); /* Setup the I2C Peripheral for master mode */ + + pc.printf("\n\n\n\rI2C Master Mode Controller.\n\r"); + pc.printf("This module will communicate and control the dsPIC I2C Slave devices\n\r"); + + do { + pc.printf("\n\rChoose the I2C Slave Address you want to control from this device\n\r"); + pc.printf("Press the + and - key to increase and decrease the selection\n\r"); + pc.printf("& then Return to finish.\n\r"); + pc.printf("or Q to quit and return to main menu.\n\r"); + pc.printf("\rNew Value is: %03d",Slave_Address); + + do { + keypress = pc.getc(); /* Read character from PC keyboard */ + if ((Slave_Address < DSPIC_SLAVE_ADDRESS_MAX) && (keypress == '+')) + { + Slave_Address++; + } + if ((Slave_Address > DSPIC_SLAVE_ADDRESS_MIN) && (keypress == '-')) + { + Slave_Address--; + } + + + pc.printf("\rNew Value is: %03d",Slave_Address); + + } while ((keypress != 'q') && (keypress != '\r')); + + if (keypress == '\r') + { + i2C_control_submenu(); + } + + } while (keypress != 'q'); + } + + + + + + +/* Sub Menu */ +static void i2C_control_submenu(void) + { + uint8_t temp8 = 0u; + uint16_t temp16 = 0u; + + do + { + pc.printf("\n\n\n\rTest Menu for Slave Address:%d\n\r", Slave_Address, 3u); + pc.printf("0 - Ping The Slave Address and Test For Acknowledge\n\r"); + pc.printf("1 - RESET the Slave Address MCU\n\r"); + pc.printf("2 - Emergency Stop\n\r"); + pc.printf("3 - Normal Stop\n\r"); + pc.printf("4 - Set New Direction As Forward\n\r"); + pc.printf("5 - Set New Direction As Reverse\n\r"); + pc.printf("6 - Set The Ramp Up Speed\n\r"); + pc.printf("7 - Set The Ramp Down Speed\n\r"); + pc.printf("8 - Set The Maximum Motor Demand Speed Forward/Clockwise\n\r"); + pc.printf("9 - Set The Maximum Motor Demand Speed Backward/Counter Clockwise\n\r"); + pc.printf("a - Set The Number of Rotary Encoder Pulses You Want To move\n\r"); + pc.printf("b - Start The Motor Turning\n\r"); + pc.printf("c - Goto/Locate Home Position\n\r"); + + pc.printf("d - Read The Tacho RPM Speeds\n\r"); + pc.printf("e - Read The Motor Currents\n\r"); + pc.printf("f - Read The Vbus Voltages\n\r"); + pc.printf("g - Read The Demand Speed Pot\n\r"); + pc.printf("h - Read The Hall Sensors\n\r"); + pc.printf("i - Read The Motor Status Flags\n\r"); + pc.printf("j - Read The Maximum RPM Speed OF The Motor\n\r"); + pc.printf("k - Read The Rotary Encoder Difference/Overshoot Value\n\r"); + + pc.printf("z - Execute A Sequence Of Tests\n\r"); + + pc.printf("RETURN - Quit this menu and return to Sub Menu\n\r"); + + pc.printf("Please select the test option\n\r"); + + temp16 = pc.getc(); + + temp8 = (uint8_t) (temp16); + + if (temp8 == '0') + { + i2C_cs_ping(); + } + if (temp8 == '1') + { + i2C_cs_reset(); + } + if (temp8 == '2') + { + i2C_cs_emergency_stop(); + } + if (temp8 == '3') + { + i2C_cs_normal_stop(); + } + if (temp8 == '4') + { + i2C_cs_set_new_direction_forward(); + } + if (temp8 == '5') + { + i2C_cs_set_new_direction_reverse(); + } + if (temp8 == '6') + { + choose_the_ramp_up_speed(); + } + if (temp8 == '7') + { + choose_the_ramp_down_speed(); + } + if (temp8 == '8') + { + choose_the_motor_demand_forward(); + } + if (temp8 == '9') + { + choose_the_motor_demand_reverse(); + } + if (temp8 == 'a') + { + choose_the_rotary_encoder_counts(); + } + if (temp8 == 'b') + { + i2C_cs_start_rotation(); + } + + if (temp8 == 'c') + { + i2C_cs_goto_home(); + } + + + + if (temp8 == 'd') + { + i2C_cs_read_RPMs(); + } + if (temp8 == 'e') + { + i2C_cs_read_motor_currents(); + } + if (temp8 == 'f') + { + i2C_cs_read_Vbus_voltages(); + } + if (temp8 == 'g') + { + i2C_cs_read_demand_speed_potRPM(); + } + if (temp8 == 'h') + { + i2C_cs_read_hall_sensors(); + } + if (temp8 == 'i') + { + i2C_cs_read_status_flags(); + } + if (temp8 == 'j') + { + i2C_cs_read_Maximum_RPM(); + } + if (temp8 == 'k') + { + i2C_cs_read_Rotary_Encoder(); + } + + + + + if (temp8 == 'z') + { + i2C_cs_execute_sequence(); + } + + } while (temp8 != '\r'); + + pc.printf("Returning to main menu...\n\r"); + } + + + + +/* Ping The I2C Slave Address */ +static sint32_t i2C_cs_ping(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + + pc.printf("\n\rPinging the I2C Slave Address:%d\r\n", Slave_Address, 3u); + do { + + Ack_Status = I2C0_dsPIC_Ping(Slave_Address); + if (Ack_Status != ACK) + { + pc.printf("NO Acknowledge received\n\r"); + } + else{ + pc.printf("Acknowledge received\n\r"); + } + wait(1.0); + keypress = pc.getc(); + + } while ((Ack_Status != ACK) && (keypress != '\r')); /* Loop until keypress or we get an Ack */ + return Ack_Status; + } + + +/* Reset The MCU at the I2C Slave Address */ +static sint32_t i2C_cs_reset(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rResetting the target MCU at the I2C Slave Address:%03d\r\n", Slave_Address); + + Ack_Status = I2C0_dsPIC_Reset(Slave_Address); + return Ack_Status; + } + + +/* Emergency Stop */ +static sint32_t i2C_cs_emergency_stop(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rEmergency Stop the motor - command sent\n\r"); + Ack_Status = I2C0_dsPIC_Emergency_Stop(Slave_Address); + return Ack_Status; + } + + +/* Normal Stop */ +static sint32_t i2C_cs_normal_stop(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rNormal Stop the motor - command sent\n\r"); + Ack_Status = I2C0_dsPIC_Normal_Stop(Slave_Address); + return Ack_Status; + } + + +/* Set The direction as Forward/Clockwise */ +static sint32_t i2C_cs_set_new_direction_forward(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Motor Direction - FORWARD - command sent\n\r"); + Ack_Status = I2C0_dsPIC_Set_Motor_Direction(Slave_Address, CLOCKWISE); + return Ack_Status; + } + + +/* Set The direction as reverse or counter clockwise */ +static sint32_t i2C_cs_set_new_direction_reverse(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Motor Direction - REVERSE - command sent\n\r"); + Ack_Status = I2C0_dsPIC_Set_Motor_Direction(Slave_Address, COUNTER_CLOCKWISE); + return Ack_Status; + } + + + +/* Choose the Ramp Up Speed */ +static sint32_t choose_the_ramp_up_speed(void) + { + uint16_t static rampup = RAMP_UP_SPEED_MIN; + uint16_t keypress = 0u; + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSelect the ramp up speed using the + and - keys. Press Return when done.\n\r"); + pc.printf("\rNew Value is: %04d", rampup); + + do { + keypress = pc.getc(); + + if ((rampup < RAMP_UP_SPEED_MAX) && (keypress == '+')) + { + rampup++; + } + if ((rampup > RAMP_UP_SPEED_MIN) && (keypress == '-')) + { + rampup--; + } + + pc.printf("\rNew Value is: %04d", rampup); + + + } while (keypress != '\r'); + + Ack_Status = i2C_cs_set_ramp_up_speed(rampup); + return Ack_Status; + } + + + +/* Set the ramp up speed */ +static sint32_t i2C_cs_set_ramp_up_speed(uint16_t rampup) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Ramp Up Speed to %04d - command sent\n\r", rampup); + Ack_Status = I2C0_dsPIC_Set_Ramp_Up_Speed(Slave_Address, rampup); + return Ack_Status; + } + + + +/* Choose the Ramp down Speed */ +static sint32_t choose_the_ramp_down_speed(void) + { + uint16_t static rampdown = RAMP_DOWN_SPEED_MIN; + uint16_t keypress = 0u; + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSelect the ramp down speed using the + and - keys. Press Return when done.\n\r"); + pc.printf("\rNew Value is: %04d", rampdown); + + do { + keypress = pc.getc(); + + if ((rampdown < RAMP_DOWN_SPEED_MAX) && (keypress == '+')) + { + rampdown++; + } + if ((rampdown > RAMP_DOWN_SPEED_MIN) && (keypress == '-')) + { + rampdown--; + } + + pc.printf("\rNew Value is: %04d", rampdown); + + } while (keypress != '\r'); + + Ack_Status = i2C_cs_set_ramp_down_speed(rampdown); + return Ack_Status; + } + + + +/* Set The Ramp Down Speed */ +static sint32_t i2C_cs_set_ramp_down_speed(uint16_t rampdown) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Ramp Down Speed to %04d - command sent\n\r", rampdown); + Ack_Status = I2C0_dsPIC_Set_Ramp_Down_Speed(Slave_Address, rampdown); + return Ack_Status; + } + + + +/* Choose the Motor Demand Forward Speed */ +static sint32_t choose_the_motor_demand_forward(void) + { + uint16_t static forwarddemand = MOTOR_SPEED_DEMAND_FORWARD_MIN; + uint16_t keypress = 0u; + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSelect the Forward Motor Demand speed using the + and - keys. Press Return when done.\n\r"); + pc.printf("\rNew Value is: %04d", forwarddemand); + + do { + keypress = pc.getc(); + if ((forwarddemand < MOTOR_SPEED_DEMAND_FORWARD_MAX) && (keypress == '+')) + { + forwarddemand += 9u; + if (forwarddemand > MOTOR_SPEED_DEMAND_FORWARD_MAX) + { + forwarddemand = MOTOR_SPEED_DEMAND_FORWARD_MAX; + } + } + if ((forwarddemand > MOTOR_SPEED_DEMAND_FORWARD_MIN) && (keypress == '-')) + { + if (forwarddemand <= 8u) + { + forwarddemand = MOTOR_SPEED_DEMAND_FORWARD_MIN; + } + else{ + forwarddemand-= 8u; + } + + } + pc.printf("\rNew Value is: %04d", forwarddemand); + + } while (keypress != '\r'); + + Ack_Status = i2C_cs_set_motor_demand_forward(forwarddemand); + return Ack_Status; + } + + + +/* Set the motor demand Speed */ +static sint32_t i2C_cs_set_motor_demand_forward(uint16_t demandforward) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Forward Motor Demand Speed to %04d - command sent\n\r",demandforward); + Ack_Status = I2C0_dsPIC_Set_Motor_Speed_Demand_Forward(Slave_Address, demandforward); + return Ack_Status; + } + + + +/* Choose the Motor Demand Reverse Speed */ +static sint32_t choose_the_motor_demand_reverse(void) + { + uint16_t static reversedemand = MOTOR_SPEED_DEMAND_REVERSE_MIN; + uint16_t keypress = 0u; + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSelect the Reverse Motor Demand speed using the + and - keys. Press Return when done.\n\r"); + pc.printf("\rNew Value is: %04d", reversedemand); + + do { + keypress = pc.getc(); + if ((reversedemand < MOTOR_SPEED_DEMAND_REVERSE_MAX) && (keypress == '+')) + { + reversedemand += 9u; + if (reversedemand > MOTOR_SPEED_DEMAND_REVERSE_MAX) + { + reversedemand = MOTOR_SPEED_DEMAND_REVERSE_MAX; + } + } + if ((reversedemand > MOTOR_SPEED_DEMAND_REVERSE_MIN) && (keypress == '-')) + { + if (reversedemand <= 8) + { + reversedemand = MOTOR_SPEED_DEMAND_REVERSE_MIN; + } + else{ + reversedemand -= 8u; + } + } + + pc.printf("\rNew Value is: %04d", reversedemand); + } while (keypress != '\r'); + + Ack_Status = i2C_cs_set_motor_demand_reverse(reversedemand); + return Ack_Status; + } + + + +/* Set the Reverse motor demand speed */ +static sint32_t i2C_cs_set_motor_demand_reverse(uint16_t demandreverse) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Reverse Motor Demand Speed to %04d - command sent\n\r",demandreverse); + Ack_Status = I2C0_dsPIC_Set_Motor_Speed_Demand_Reverse(Slave_Address, demandreverse); + return Ack_Status; + } + + + + +/* Select the number of rotart encoder counts you want to move */ +static sint32_t choose_the_rotary_encoder_counts(void) + { + uint32_t static encoder_counts = 25000u; + sint32_t Ack_Status = 0u; + + pc.printf("\n\rType In The Target Number of Rotary Encoder Counts you want the motor to move. \n\rPress Return when done.\n\r"); + + encoder_counts = get_a_complete_number(); + pc.printf("\rNew Value is: %010d", encoder_counts); + + Ack_Status = i2C_cs_set_rotary_encoder_counts(encoder_counts); + return Ack_Status; + } + + +/* Set the number of counts you want to move - send to the Slave unit */ +static sint32_t i2C_cs_set_rotary_encoder_counts(uint32_t rotary_encoder_counter) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rSetting The Rotary Encoder Counter Target to %010d - command sent\n\r", rotary_encoder_counter); + Ack_Status = I2C0_dsPIC_Set_Rotation_Counts(Slave_Address, rotary_encoder_counter); + return Ack_Status; + } + + +/* Start Rotation */ +static sint32_t i2C_cs_start_rotation(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\rRun The Motor - command sent\n\r"); + Ack_Status = I2C0_dsPIC_Start_Motor_Rotation(Slave_Address); + return Ack_Status; + } + + +static sint32_t i2C_cs_goto_home(void) + { + sint32_t Ack_Status = 0u; + uint8_t rx_array[2] = {0u, 0u}; + uint8_t temp8 = 0u; + uint8_t abort_flag = 0u; + uint16_t keypress = 0u; + + pc.printf("\n\rGoto Home - command sent\n\r"); + pc.printf("CLOCKWISE direction - Home Speed 100\n\r"); + Ack_Status = I2C0_dsPIC_Goto_Home(Slave_Address, CLOCKWISE, 100u); /* Goto home, run until sensor, CLOCKWISE, speed 100 */ + pc.printf("Waiting for the sensor to reach the home position\n\r"); + + wait(0.5); + + do { + Ack_Status = I2C0_dsPIC_Read_Motor_Status(Slave_Address, rx_array); + keypress = pc.getc(); + + if (keypress == '2') + { + i2C_cs_emergency_stop(); + abort_flag = 1u; + } + if (keypress == '3') + { + i2C_cs_normal_stop(); + abort_flag = 1u; + } + wait(0.1); + + } while (rx_array[1] == GOTO_HOME); + + temp8 = (rx_array[0] & 0x3cu); /* Strip out the fault flags bits */ + + if ((temp8 == 0x3cu) && (abort_flag == 0u)) + { + pc.printf("Home position detected\n\r"); + pc.printf("Backing off 1/2 rev\n\r"); + Ack_Status = I2C0_dsPIC_Set_Motor_Direction(Slave_Address, COUNTER_CLOCKWISE); + Ack_Status = I2C0_dsPIC_Set_Ramp_Up_Speed(Slave_Address, 1u); + Ack_Status = I2C0_dsPIC_Set_Motor_Speed_Demand_Reverse(Slave_Address, 5u); + Ack_Status = I2C0_dsPIC_Set_Rotation_Counts(Slave_Address, 500u); + Ack_Status = I2C0_dsPIC_Start_Motor_Rotation(Slave_Address); + wait(0.5); + do { + Ack_Status = I2C0_dsPIC_Read_Motor_Status(Slave_Address, rx_array); + keypress = pc.getc(); /* Read character from PC keyboard */ + + if (keypress == '2') + { + i2C_cs_emergency_stop(); + abort_flag = 1u; + } + if (keypress == '3') + { + i2C_cs_normal_stop(); + abort_flag = 1u; + } + + + wait(0.1); + } while (rx_array[1] != STOPPED); + + temp8 = (rx_array[0] & 0x3cu); /* Strip out the fault flags bits */ + } + + if ((temp8 == 0x3cu) && (abort_flag == 0u)) + { + pc.printf("Finished backing off\n\r"); + pc.printf("Slow close...\n\r"); + Ack_Status = I2C0_dsPIC_Goto_Home(Slave_Address, CLOCKWISE, 1u); /* Goto home, run until sensor, CLOCKWISE, speed 100 */ + pc.printf("Waiting for the sensor to reach home position\n\r"); + + wait(0.25); + + do { + Ack_Status = I2C0_dsPIC_Read_Motor_Status(Slave_Address, rx_array); + wait(0.1); + } while (rx_array[1] == GOTO_HOME); + + temp8 = (rx_array[0] & 0x3cu); /* Strip out the fault flags bits */ + } + + if ((temp8 == 0x3cu) && (abort_flag == 0u)) + { + pc.printf("All done home position achieved\n\r"); + } + if (temp8 != 0x3cu) + { + pc.printf("Fault detected - goto home aborted\n\r"); + } + if (abort_flag == 1u) + { + pc.printf("Motor stopped - goto home aborted\n\r"); + } + + return Ack_Status; + } + + + + + +/* Read the RPM's */ +static sint32_t i2C_cs_read_RPMs(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + pc.printf("\n\rReading the RPM's from the target drive\n\r"); + pc.printf("Press any key to continue\n\r"); + + do { + pc.printf("RPM "); + Ack_Status = I2C0_dsPIC_Read_Tacho_Speed_Instantaneous(Slave_Address, rx_array); /* Instantaneous first */ + pc.printf("%05d ",((rx_array[0] * 256u) + rx_array[1])); + Ack_Status = I2C0_dsPIC_Read_Tacho_Speed_Average(Slave_Address, rx_array); /* then Average next */ + pc.printf("%05d\r",((rx_array[0] * 256u) + rx_array[1])); + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\r"); + return Ack_Status; + } + + + +/* Read The Motor Current Signals */ +static sint32_t i2C_cs_read_motor_currents(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + pc.printf("\n\rReading the Motor Current signals from the target drive\n\r"); + pc.printf("Press any key to continue\n\r"); + + do { + pc.printf("Motor Current "); + Ack_Status = I2C0_dsPIC_Read_Motor_Current_Instantaneous(Slave_Address, rx_array); /* Instantaneous first */ + pc.printf("%05dmA ",((rx_array[0] * 256u) + rx_array[1])); + + Ack_Status = I2C0_dsPIC_Read_Motor_Current_Average(Slave_Address, rx_array); /* then Average next */ + pc.printf("%05dmA\r",((rx_array[0] * 256u) + rx_array[1])); + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\r"); + return Ack_Status; + } + + + +/* Reading The Vbus voltage */ +static sint32_t i2C_cs_read_Vbus_voltages(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint16_t temp16 = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + pc.printf("\n\rReading the Vbus Voltage levels from the target drive\n\r"); + pc.printf("Press any key to continue\n\r"); + + do { + pc.printf("Vbus Voltage "); + + Ack_Status = I2C0_dsPIC_Read_Vbus_Instantaneous(Slave_Address, rx_array); /* Instantaneous Voltage first */ + temp16 = ((rx_array[0] * 256u) + rx_array[1]); + pc.printf("%05dmV ",temp16); + + Ack_Status = I2C0_dsPIC_Read_Vbus_Average(Slave_Address, rx_array); /* then Average next */ + temp16 = ((rx_array[0] *256u) + rx_array[1]); + pc.printf("%05dmV\r",temp16); + + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\r"); + return Ack_Status; + } + + +/* Motor Demand Speed Pot */ +static sint32_t i2C_cs_read_demand_speed_potRPM(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + pc.printf("\n\rReading the Motor Speed Demand Pot\n\r"); + pc.printf("Press any key to continue\n\r"); + + do { + pc.printf("Demand Pot "); + Ack_Status = I2C0_dsPIC_Read_Demand_Pot_Instantaneous(Slave_Address, rx_array); /* Instantaneous Voltage first */ + pc.printf("%05d ",((rx_array[0] * 256u) + rx_array[1])); + + Ack_Status = I2C0_dsPIC_Read_Demand_Pot_Average(Slave_Address, rx_array); /* then Average next */ + pc.printf("%05d\r",((rx_array[0] * 256u) + rx_array[1])); + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + + pc.printf("\n\r"); + return Ack_Status; + } + + +/* Read the Hall Sensors */ +static sint32_t i2C_cs_read_hall_sensors(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + pc.printf("\n\rReading the Hall Switches \n\r"); + pc.printf("Press any key to continue\n\r"); + + do { + pc.printf("Hall Sensors "); + Ack_Status = I2C0_dsPIC_Read_Hall_Sensor_Positions(Slave_Address, rx_array); + pc.printf("%05d\r",((rx_array[0] * 256u) + rx_array[1])); + + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\r"); + return Ack_Status; + } + + + +/* Read The Status Register */ +static sint32_t i2C_cs_read_status_flags(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + union u_type + { + struct bit_structure + { + unsigned bit7: 1u; /* Motor Run Flag */ + unsigned bit6: 1u; /* Direction */ + unsigned bit5: 1u; /* RPM Fault Flag */ + unsigned bit4: 1u; /* Inst Current Fault Flag */ + unsigned bit3: 1u; /* Ave Current Fault Flag */ + unsigned bit2: 1u; /* Ext Comparator Fault Flag */ + unsigned bit1: 1u; /* spare1 */ + unsigned bit0: 1u; /* spare2 */ + } temp8; + uint8_t temp8_byte; + } status_flag_bits; + + + + pc.printf("\n\rReading the Status Flags And State Machine \n\r"); + pc.printf("Press any key to continue\n\r"); + pc.printf("Run/Stop Direction RPM Flt InstCur AveCur ExtCom Current State\n\r"); + + do { + Ack_Status = I2C0_dsPIC_Read_Motor_Status(Slave_Address, rx_array); + + status_flag_bits.temp8_byte = rx_array[0]; + + if (status_flag_bits.temp8.bit7 == MOTOR_RUNNING) + { + pc.printf("RUNNING "); + } + else{ + pc.printf("STOPPED "); + } + + if (status_flag_bits.temp8.bit6 == CLOCKWISE) + { + pc.printf("Clockwise "); + } + else{ + pc.printf("Anti CW "); + } + + if (status_flag_bits.temp8.bit5 == FAULT_PRESENT) + { + pc.printf("FAULT "); + } + else{ + pc.printf("NO FAULT "); + } + + if (status_flag_bits.temp8.bit4 == FAULT_PRESENT) + { + pc.printf("FAULT "); + } + else{ + pc.printf("NO FAULT "); + } + + if (status_flag_bits.temp8.bit3 == FAULT_PRESENT) + { + pc.printf("FAULT "); + } + else{ + pc.printf("NO FAULT "); + } + + if (status_flag_bits.temp8.bit2 == FAULT_PRESENT) + { + pc.printf("FAULT "); + } + else{ + pc.printf("NO FAULT "); + } + + + if (rx_array[1] == STOPPED) + { + pc.printf("Stopped "); + } + if (rx_array[1] == STOPPING) + { + pc.printf("Stopping "); + } + if (rx_array[1] == NEW_MOTOR_DEMAND_FORWARD) + { + pc.printf("New Demand Forward"); + } + if (rx_array[1] == NEW_MOTOR_DEMAND_REVERSE) + { + pc.printf("New Demand Reverse"); + } + if (rx_array[1] == NORMAL_RUNNING) + { + pc.printf("Normal Running "); + } + if (rx_array[1] == ROTATE_X_QUAD_COUNTS) + { + pc.printf("Rotating X Counts "); + } + if (rx_array[1] == LAST_REVOLUTION) + { + pc.printf("Last Revolution "); + } + if (rx_array[1] == GOTO_HOME) + { + pc.printf("Goto Home Position"); + } + + + pc.printf("\r"); + + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + pc.printf("\n\r"); + return Ack_Status; + } + + + + +/* Read The Maximum RPM Speed of the motor */ +static sint32_t i2C_cs_read_Maximum_RPM(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[2] = {0u, 0u}; + + pc.printf("\n\rReading the Maximum RPM from the target drive\n\r"); + pc.printf("Press any key to continue\n\r"); + + Ack_Status = I2C0_dsPIC_Read_Maximum_RPM(Slave_Address, rx_array); /* Maximum RPM */ + pc.printf("Maximum RPM: %05d\n\r",((rx_array[0] * 256u) + rx_array[1])); + + do { + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + return Ack_Status; + } + + + +/* Read The Difference and overshoot of the rotary encoder on the Slave */ +static sint32_t i2C_cs_read_Rotary_Encoder(void) + { + sint32_t Ack_Status = 0u; + uint16_t keypress = 0u; + uint8_t rx_array[4] = {0u, 0u, 0u, 0u}; + sint32_t quad_encoder_difference = 0u; + uint32_t temp32 = 0u; + + pc.printf("\n\rReading the Rotary Encoder Difference/Overshoot from the target drive\n\r"); + pc.printf("Press any key to continue\n\r"); + + do { + Ack_Status = I2C0_dsPIC_Read_Quad_Encoder_Counter(Slave_Address, rx_array); + + quad_encoder_difference = rx_array[0]; + quad_encoder_difference = (quad_encoder_difference << 8u); + quad_encoder_difference = (quad_encoder_difference + rx_array[1]); + quad_encoder_difference = (quad_encoder_difference << 8u); + quad_encoder_difference = (quad_encoder_difference + rx_array[2]); + quad_encoder_difference = (quad_encoder_difference << 8u); + quad_encoder_difference = (quad_encoder_difference + rx_array[3]); + + temp32 = ((~quad_encoder_difference) + 1u); + + pc.printf("\rDifference/Overshoot:"); + if (quad_encoder_difference == 0u) + { + pc.printf(" %010d", quad_encoder_difference); + } + else if(quad_encoder_difference > 0u) + { + pc.printf("+%010d", quad_encoder_difference); + } + else + { + pc.printf("-%010d", temp32); + } + + + + wait(0.1); + keypress = pc.getc(); + } while (keypress != '\r'); + + return Ack_Status; + } + + + + + + + + + + +/* Execute a sequence of instruction */ +static void i2C_cs_execute_sequence(void) + { + sint32_t Ack_Status = 0u; + + pc.printf("\n\n\rTransmitting data From Master I2C to Slave..."); + + Ack_Status = i2C_cs_ping(); + + if (Ack_Status == ACK) + { + pc.printf("Setting up the slave motor parameters...\n\r"); + + i2C_cs_set_new_direction_forward(); /* Motor direction forward */ + i2C_cs_set_ramp_up_speed(5u); /* Set the Ramp up speed */ + i2C_cs_set_ramp_down_speed(25u); /* Set the ramp down speed */ + i2C_cs_set_motor_demand_forward(400u); /* Set the target speed forward */ + i2C_cs_set_rotary_encoder_counts(50000u); /* Set the number of rotary encoder countes we want to move */ + + i2C_cs_start_rotation(); /* Start Rotation */ + pc.printf("Slave Motor is running...\n\r"); + i2C_cs_read_status_flags(); /* Display the fault/status information */ + + i2C_cs_set_rotary_encoder_counts(150000ul); /* Set the number of rotary encoder countes we want to move */ + i2C_cs_set_motor_demand_forward(750u); /* Increase the target speed forward */ + i2C_cs_start_rotation(); /* Start Rotation */ + i2C_cs_read_status_flags(); /* Display the fault/status information */ + + pc.printf("Reading some of the motor characteristics...\n\r"); + + i2C_cs_read_RPMs(); /* Display The RPM Figures from the slave */ + + i2C_cs_read_motor_currents(); /* Display The Motor Currents */ + + i2C_cs_read_Vbus_voltages(); /* Display the Vbus voltage */ + + i2C_cs_read_demand_speed_potRPM(); /* Display the demand pot */ + + i2C_cs_read_status_flags(); /* Display the fault information */ + + pc.printf("Stopping the motor\n\r"); + i2C_cs_normal_stop(); /* Soft Stop motor rotation */ + + pc.printf("Press any key to skip to next section\n\r"); + + pc.getc(); + + + pc.printf("Setting the new direction Reverse/Counter clockwise\n\r"); + i2C_cs_set_new_direction_reverse(); + i2C_cs_set_motor_demand_reverse(1023u); /* Demand speed in reverse */ + i2C_cs_set_rotary_encoder_counts(40250ul); /* Set the number of rotary encoder countes we want to move */ + i2C_cs_start_rotation(); /* Start the motor rotating */ + i2C_cs_read_status_flags(); /* Display the fault/status information */ + + + + pc.printf("Press any key to skip to next section\n\r"); + + pc.getc(); + + pc.printf("\n\rTests Complete\n\r"); /* Tests Complete */ + } + + } + + + + + + +/* Get a single number (0-9) from the host PC terminal */ +static uint8_t get_a_number_digit(void) + { + sint8_t temp8 = 0u; + uint8_t break_flag = 0u; + + do { + + temp8 = pc.getc(); /* Get a character first of all */ + + if ((temp8 > 0x2fu) && (temp8 < 0x3au)) + { + break_flag = 1u; /* Check for valid number digit 0-9 */ + } + if (temp8 == '\r') + { + break_flag = 1u; + } + } while (break_flag == 0u); + + /* We have valid number key press */ + pc.printf("%c", temp8); + + if (temp8 != '\r') + { + temp8 = temp8 - 48; /* convert to number from ASCII to decimal */ + } + + return temp8; /* Retrun with a number or '\r' */ + } + + + + +/* Get a complete number 32 bit from the host terminal */ +static uint32_t get_a_complete_number(void) + { + uint8_t n = 0u; + uint32_t number_input = 0u; + + do { + n = get_a_number_digit(); + if (n != '\r') + { + number_input = (number_input * 10u) + n; + } + } while (n != '\r'); + return number_input; + } + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/main.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,87 @@ +/* MBED Module - RS-EDP Platform */ +/* ***************************** */ + +#include "mbed.h" +#include "RSEDP_Mbed_Complete.h" + + + + +/* Main Loop Here */ +int main(void) + { + + setup_mbed_ports(); /* Setup the I/O Structure of the mbed module */ + pc.printf("\n\n\n\n\n\n\n\rWelcome the the MBED LPC1768 Developers Module\n\r"); + pc.printf("Using the RS-EDP Development Platform hardware\n\r"); + pc.printf("Software Revision Number: %d\n\r\n", FIRMWARE_VERSION); + + + /* mbed Setup */ + pc.printf("\nMbed Module setup...\n\r"); + pc.printf(" Setting up the CNTRL SPI for Master mode\n\r"); + setup_CNTRL_SPI_Master_Mode(); /* SPI setup */ + pc.printf(" Setting up the CNTRL I2C for Master mode\n\r"); + setup_CNTRL_I2C_Master_Mode(); /* Main CNTRL I2C control channel */ + pc.printf(" Setting up the ASC0, UART0 Serial Channel\n\r"); + setup_UART0(); /* Standard UART */ + pc.printf(" Setting up the ASC1, UART1 Serial Channel\n\r"); + setup_UART1(); /* Additional UART */ + + + /* Base Board Configuration & setup */ + pc.printf("\nBase Board setup...\n\r"); + pc.printf(" Setting up the 24LC32 Serial EEPROM\n\r"); + RSEDP_BB_setup_24LC32(M24C32_BASE_BOARD); /* Setup the Serial EEPROM device on the base board */ + pc.printf(" Setting up the PCA9675 Serial Latch For reading the DIP Switches\n\r"); +// RSEDP_BB_setup_PCA9675(PCA9675_BASE_BOARD); /* Setup the Serial Latch on the base board */ + + if (COMMS_MODULE_FITTED == YES) + { + /* Communications module Setup */ + pc.printf("\nCommunications Board setup...\n\r"); + pc.printf(" Setting up the serial PCF8583 Real Time Clock IC\n\r"); + RSEDP_COM_setup_PCF8583(PCF8583_COMMS_MODULE,'C'); /* Setup the Real Time Clock for Clock mode on the Comms Module */ + } + + if (DIGITAL_IO_MODULE_FITTED == YES) + { + /* Digital I/O module Setup */ + pc.printf("\nDigital I/O Module setup...\n\r"); + pc.printf(" Setting up the serial PCA9555 Digital Output Expander\n\r"); + RSEDP_DIO_setup_PCA9555(PCA9555_DIGITAL_IO_OUT, 0xff,0xff); /* Setup the Serial digital output latch on the digital I/O board */ + pc.printf(" Setting up the serial PCA9555 Digital Input Expander\n\r"); /* setup the serial digital input latch */ + RSEDP_DIO_setup_PCA9555(PCA9555_DIGITAL_IO_IN, 0xff,0xff); /* Setup the Serial I/O Expander on the digital I/O Board */ + } + + if (ANALOGUE_MODULE_FITTED == YES) + { + /* Analogue Module setup */ + pc.printf("\nAnalogue Module setup...\n\r"); + pc.printf(" Setting up the ADC5263 serial Digital Potentiometer\n\r"); /* Digital Pot used in the input filter */ + RSEDP_AM_Init_AD5263(AD5263_ANALOGUE_DIGITAL_POT); + pc.printf(" Setting up the MAX1x3x serial ADC\n\r"); /* Serial ADC Convter IC */ + RSEDP_AM_Init_MAX1x3x(MAX1X3X_ANALOGUE_ADC) ; + } + + if (MOTOR_MC1_MODULE_FITTED == YES) + { + /* Brushed DC MC1 Module Drive Module setup */ + pc.printf("\nMC1 Brushed DC Motor Drive Module setup...\n\r"); + pc.printf(" Setting up the PWM\n\r"); /* Set the PWM frequency */ + RSEDP_MC1_Setup(); + } + + RSEDP_test_all(); /* Run the test and diagnostic facility for the board */ + + + + /* never get here */ + while(1) + { + ; + } + } + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SourceFiles/mbed_Port_Structure.cpp Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,109 @@ +/* Configure the I/O Port Structure */ +/* ******************************** */ + + + + +/* includes files */ +#include "mbed.h" /* Header file for mbed module */ +#include "defines.h" /* User defines */ +#include "misra_types.h" /* MISRA Types */ +#include "RSEDP_Slave_Address_Defines.h" /* Slave address of I2C Devices defined here */ + + + +/* Digital I/O */ +DigitalOut User_Led1(LED1); +DigitalOut User_Led2(LED2); +DigitalOut User_Led3(LED3); +DigitalOut User_Led4(LED4); + + +/* SPI Interface to RS-EDP CNTRL_SPI and the SD Card on Adapter board */ +SPI CNTRL_spi(p5, p6, p7); /* MOSI, MISO, SCLK */ + +/* pin 8 used as input */ +DigitalIn DigitalIn_Pin8(p8); + +/* I2C Interface to RS-EDP CNTRL I2C */ +I2C CNTRL_i2c(p9, p10); /* SDA, SCL */ + + +/* SPI interface to base board MCI Pins and to LCD pins on the adapter board */ +SPI MCI_spi(p11, p12, p13); /* MOSI, MISO, SCLK */ + +/* pin 14 used as digital out */ +DigitalOut DigitalOut_Pin14(p14); + + +/* Analogue I/O Pin Definitions or General I/O */ +AnalogIn AD0(p15); +AnalogIn AD1(p16); +AnalogIn AD2(p17); +AnalogIn AD3(p18); + +DigitalOut DigitalOut_Pin19(p19); + +/* pin 20 not configured */ + + +/* Pin21 used as PWM */ +PwmOut PwmOut_Pin21(p21); + +/* pin 22 - not configured */ +PwmOut PwmOut_Pin23(p23); + +/* Pin24 used as PWM */ +DigitalOut DigitalOut_Pin24(p24); + + +/* Serial Interface to RS-EDP ASC1 UART1 */ +Serial UART1(p26, p25); /* Tx,Rx Serial UART0/ASC0 - secondary UART channel */ + + +/* Serial Interface to RS-EDP ASC0 UART0 */ +Serial UART0(p28, p27); /* Tx,Rx Serial UART0/ASC0 - primary UART channel */ + + +/* pin 29 - not configured */ + + +/* Pin29 & Pin30 - used as CAN or general I/O */ +DigitalIn DigitalIn_Pin30(p30); + + + +/* Configure the USB as a virtual communications port */ +Serial pc(USBTX, USBRX); + + + + +/* Function Prototypes */ +void setup_mbed_ports(void); + + + +/* Configure the I/O Ports */ +void setup_mbed_ports(void) + { + pc.baud(115000); /* Baud rate should be 115k baud */ + pc.format(8,Serial::None,1); /* format is 8 data bits, no stop bit, no parity */ + + User_Led1 = LED_ON; + User_Led2 = LED_OFF; + User_Led3 = LED_ON; + User_Led4 = LED_OFF; + + DigitalOut_Pin14 = 0; + DigitalOut_Pin19 = 1; /* if motor drive fitted set brake to ON */ + DigitalOut_Pin24 = 0; + + PwmOut_Pin23 = (1.0f); /* if motor drive board fitted set PWM duty to zero */ + + } + + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Nov 19 09:49:16 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/49a220cc26e0