From 62451ffb05addfea9f387e09d5dc1bdaca8971b7 Mon Sep 17 00:00:00 2001 From: Avi Levkovich Date: Sun, 3 Jun 2018 15:04:23 +0300 Subject: Add ADC Sequence 1 for ADC0 in order to work with more than 16 channels --- Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Thread') diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index b0bdfea4d..fb7a7651a 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -136,7 +136,7 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) LOG_ERROR (IfIndex, "Wrong Motor"); return 0xFFFFFFFF; } - CurrentPosition = MotorGetPositionFromFPGA_Res(ThreadMotorIdToMotorId[index]); + CurrentPosition = MotorGetPosition(ThreadMotorIdToMotorId[index]); if (initialpos == 0xFFFF) initialpos = CurrentPosition; positionDiff = Control_Delta_Position_Pass(CurrentPosition,PreviousPosition); -- cgit v1.3.1 From c3acf10f9c8b6ab44751332a885a7200966a499c Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Sun, 3 Jun 2018 18:22:15 +0300 Subject: Handling job length correcly. a UART bug solved (?) --- .../Common/Sys_PinOut_Config/MCU_MAIN_pinout.c | 2 + .../Embedded/Drivers/Heater/TemperatureSensor.c | 9 ++- .../Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c | 67 ++-------------------- .../Embedded/Modules/General/GeneralHardware.c | 1 + .../Embedded/Modules/Thread/Thread_print.c | 59 ++++++++++++++++--- .../Embedded/StateMachines/Printing/JobSTM.c | 4 +- 6 files changed, 66 insertions(+), 76 deletions(-) (limited to 'Software/Embedded_SW/Embedded/Modules/Thread') diff --git a/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c b/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c index 484c99d1a..88198353e 100644 --- a/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c +++ b/Software/Embedded_SW/Embedded/Common/Sys_PinOut_Config/MCU_MAIN_pinout.c @@ -87,6 +87,8 @@ PinoutSet(void) MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); + MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); + //hardware timers enabled manually because the pinout tool //initialize automatically gpio per timer , deleting the gpio disables the timer diff --git a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c index 731dd2b31..0249a775a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c +++ b/Software/Embedded_SW/Embedded/Drivers/Heater/TemperatureSensor.c @@ -249,11 +249,12 @@ uint32_t TemperatureSensorReadFromFPGA(TEMPERATURE_SENSOR_ID_ENUM SensorId) temp = ADS1220_CMD_SYNC;//ADS1220_CMD_RDATA; temp = temp << 24; +#ifndef EVALUATION_BOARD SPISendFPGARequest(SensorId,temp, 2); ////////// //MillisecReadFromTempSensor(SensorId, ADS1220_CMD_RDATA, 4, TemperatureSensorReadFromFPGA_Res); - +#endif return Status; } @@ -268,9 +269,10 @@ uint32_t TemperatureSendSensorDummyClk(TEMPERATURE_SENSOR_ID_ENUM SensorId) Status = ERROR; temp = 0x10FFFFFF ; +#ifndef EVALUATION_BOARD SPISendFPGARequest(SensorId,temp, 4); - +#endif return Status; } @@ -418,12 +420,13 @@ uint32_t TemperatureSensorReadRegFromFPGA(TEMPERATURE_SENSOR_ID_ENUM SensorId, u temp = ADS1220_CMD_RREG | ((Reg<<2) ); temp = temp << 24; +#ifndef EVALUATION_BOARD SPISendFPGARequest(SensorId,temp, 2); //MillisecReadFromTempSensor(SensorId, temp, 4, TemperatureSensorReadFromFPGA_Res); SysCtlDelay(3000); - +#endif TemperatureSensorReadRegFromFPGA_Res( SensorId, Reg) ; diff --git a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c index 7a33cb6fe..9d6f50e51 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c +++ b/Software/Embedded_SW/Embedded/Drivers/Uart_Comm/Uart.c @@ -66,8 +66,11 @@ void UARTIntHandler(UArg arg0); -void Init_U0_Interrupt() +void Init_U0(void) { + ROM_IntMasterDisable(); + UARTStdioConfig(0, U0_BAUDRATE, 120000000); + // // Configure and enable UART interrupts. // @@ -97,67 +100,7 @@ void Init_U0_Interrupt() // ROM_IntEnable(INT_UART0); - IntMasterEnable(); -} - -void Init_U0(void) -{ - //UART_Handle handle; - //UART_Params params; - -// ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | -// SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | -// SYSCTL_CFG_VCO_480), 120000000); - // SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);//OK - - // - // Enable GPIO port A which is used for UART0 pins. - // TODO: change this to whichever GPIO port you are using. - // - SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); - - // - // Configure the pin muxing for UART0 functions on port A0 and A1. - // This step is not necessary if your part does not support pin muxing. - // TODO: change this to select the port/pin you are using. - // - GPIOPinConfigure(GPIO_PA0_U0RX); - GPIOPinConfigure(GPIO_PA1_U0TX); - - // - // Enable UART0 so that we can configure the clock. - // - SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); - - // - // Use the internal 16MHz oscillator as the UART clock source. - // - //UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); - - // - // Select the alternate (UART) function for these pins. - // TODO: change this to select the port/pin you are using. - // - GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); - - // - // Initialize the UART for console I/O. - // - UARTStdioConfig(0, U0_BAUDRATE, 120000000); - - //UARTprintf("InitConsole_U0 1\n"); - //UARTprintf("InitConsole_U0 2\n"); - /*UART_Params_init(¶ms); - params.baudRate = 115200; - params.writeDataMode = UART_DATA_BINARY; - params.readDataMode = UART_DATA_BINARY; - params.readReturnMode = UART_RETURN_FULL; - params.readEcho = UART_ECHO_OFF; - handle = UART_open(0, ¶ms); - if (!handle) { - LOG_ERROR (handle,"UART did not open"); - }*/ - Init_U0_Interrupt(); + ROM_IntMasterEnable(); } diff --git a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c index 992a2f279..c40499bd7 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c +++ b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c @@ -321,6 +321,7 @@ uint32_t HWConfigurationFunc(MessageContainer* requestContainer) UploadHardwareConfigurationResponse response = UPLOAD_HARDWARE_CONFIGURATION_RESPONSE__INIT; UploadHardwareConfigurationRequest* UploadRequest = upload_hardware_configuration_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + if (UploadRequest == NULL) { LOG_ERROR (0, "Wrong Data Allocation"); diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index fb7a7651a..cc3e317fe 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -57,6 +57,7 @@ uint32_t PreviousPosition = 0, CurrentPosition = 0; double totalLength = 0.0; double CurrentRequestedLength = 0.0; double CurrentProcessedLength = 0.0; +double LengthCalculationMultiplier; typedef void (* ProcessedLengthFunc)(void); ProcessedLengthFunc ProcessedLengthFuncPtr = NULL; @@ -112,7 +113,7 @@ void ThreadUpdateProcessLength (double length, void *Funcptr) totalLength = 0; ProcessedLengthFuncPtr = (ProcessedLengthFunc)Funcptr; } -uint32_t MotorSentData[1000] = {0}; +double MotorSentData[1000] = {0}; uint32_t PosDif[1000] = {0}; uint32_t tick[1000] = {0}; uint32_t initialpos = 0xFFFF; @@ -131,12 +132,16 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) return 0xFFFFFFFF; } index = IfIndex&0xFF; + if (CurrentRequestedLength == 0.0) + return; if (index != FEEDER_MOTOR) { LOG_ERROR (IfIndex, "Wrong Motor"); return 0xFFFFFFFF; } - CurrentPosition = MotorGetPosition(ThreadMotorIdToMotorId[index]); + CurrentPosition = MotorGetPositionFromFPGA_Res(ThreadMotorIdToMotorId[index]); + if (CurrentPosition == 0) + return; //unusable data if (initialpos == 0xFFFF) initialpos = CurrentPosition; positionDiff = Control_Delta_Position_Pass(CurrentPosition,PreviousPosition); @@ -146,7 +151,8 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) // total length = (position diff / full cycle) * pulley perimeter //(positionDiff/pulseperround)*((2*PI*motor_Radius) - length = (positionDiff/MotorsCfg[ThreadMotorIdToMotorId[index]].pulseperround)*(2*PI*MotorsCfg[ThreadMotorIdToMotorId[index]].pulleyradius); + //positionDiff = positionDiff / MotorsCfg[ThreadMotorIdToMotorId[index]].microstep; + length = (double)(positionDiff)*LengthCalculationMultiplier; if (length > 0.1) { totalLength+=length; @@ -155,11 +161,33 @@ uint32_t ThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) #warning control disabled CurrentProcessedLength+=length; #warning control disabled - PosDif[MotorDataIndex] = positionDiff; + PosDif[MotorDataIndex] = CurrentPosition; + //PosDif[MotorDataIndex] = positionDiff; MotorSentData[MotorDataIndex] = length; tick[MotorDataIndex] = UsersysTickGet(); MotorDataIndex+=1; if (MotorDataIndex == 999) MotorDataIndex = 0; + static int pooler_counter = 0; + pooler_counter++; + if (pooler_counter>=100) + { + /*{ +"HeaterGroupId": 0, +"Zone1Temp": 80, +"Zone2Temp": 2641, +"Heater1Active": false, +"Heater2Active": false, +"Heater1Percentage": 3, +"Heater2Percentage": 4000, +"InfoMessage": "Standard DC" +} void HeatingTestSendResonse(uint32_t status, bool last,bool heater1Active,bool heater2Active, int temperature1, int temperature2,int Heater1Percentage,int Heater2Percentage, char* Message) + +}*/ + //HeatingTestSendResonse(0, false,true,true, MotorDriverRequest[22].Speed,MotorDriverRequest[18].Speed,MotorDriverRequest[15].Speed,MotorDriverRequest[3].Speed, "MotorSpeed"); + + HeatingTestSendResonse(0, false,true,true, /*OriginalMotorSpd_2PPS[index]*/length,positionDiff/*(int)error_integered*/,CurrentProcessedLength,CurrentRequestedLength, "FeederLength"); + pooler_counter = 0; + } if (CurrentProcessedLength>=CurrentRequestedLength ) { // segment/intersegment/distance to spool finished @@ -355,15 +383,18 @@ bool InitialProcess = false; MotorControlConfig[Motor_i].m_preError = 0; MotorControlConfig[Motor_i].m_SetParam = 0;//need to update SetParams on presegment stage - MotorSetDirection((TimerMotors_t)HW_Motor_Id,MotorsCfg[HW_Motor_Id].directionthreadwize); + if (MotorsCfg[HW_Motor_Id].has_directionthreadwize) + MotorSetDirection((TimerMotors_t)HW_Motor_Id,MotorsCfg[HW_Motor_Id].directionthreadwize); if (Motor_i == FEEDER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled { if (SpeedControlId != 0xFF) { RemoveControlCallback(SpeedControlId,ThreadLengthCBFunction); + SpeedControlId = 0xFF; } SetMotHome(ThreadMotorIdToMotorId[Motor_i]); + LengthCalculationMultiplier = (MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].pulleyradius*2*PI)/(MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].pulseperround*MotorsCfg[ThreadMotorIdToMotorId[Motor_i]].microstep); SpeedControlId = AddControlCallback(ThreadLengthCBFunction, eHundredMillisecond,MotorGetPositionFromFPGA,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToMotorId[Motor_i],Motor_i); } if (Motor_i == FEEDER_MOTOR) // dryer motor is speed controlled. later a speed sensor will be utilized, but for now it will not be controlled @@ -371,6 +402,8 @@ bool InitialProcess = false; if (ControlIdtoMotorId[Motor_i] != 0xFF) { RemoveControlCallback(ControlIdtoMotorId[Motor_i],ThreadControlCBFunction); + ControlIdtoMotorId[Motor_i] = 0xFF; + CurrentControlledSpeed[Motor_i] = 0; } ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); AddControlCallback(ThreadControlSpeedReadFunction, eHundredMillisecond,MotorGetSpeedFromFPGA,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToMotorId[Motor_i],Motor_i); @@ -380,6 +413,8 @@ bool InitialProcess = false; if (ControlIdtoMotorId[Motor_i] != 0xFF) { RemoveControlCallback(ControlIdtoMotorId[Motor_i],ThreadControlCBFunction); + CurrentControlledSpeed[Motor_i] = 0; + ControlIdtoMotorId[Motor_i] = 0xFF; } ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); } @@ -388,6 +423,8 @@ bool InitialProcess = false; if (ControlIdtoMotorId[Motor_i] != 0xFF) { RemoveControlCallback(ControlIdtoMotorId[Motor_i],ThreadControlCBFunction); + CurrentControlledSpeed[Motor_i] = 0; + ControlIdtoMotorId[Motor_i] = 0xFF; } ControlIdtoMotorId[Motor_i] = AddControlCallback(ThreadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+Motor_i),ThreadMotorIdToDancerId[Motor_i],Motor_i); } @@ -442,10 +479,14 @@ uint32_t ThreadPreSegmentState(void *JobDetails) //only for testing - when control works, these motors will take their speed from the dryer //MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_RDRIVING, OriginalMotorSpd_2PPS[FEEDER_MOTOR]); -#warning rocker disabled -// MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 50); -// MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 50); -#warning rocker disabled +//#warning rocker disabled + if (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].has_directionthreadwize) + MotorSetDirection((TimerMotors_t)HARDWARE_MOTOR_TYPE__MOTO_RLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RLOADING].directionthreadwize); + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_RLOADING, 10); + if (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].has_directionthreadwize) + MotorSetDirection((TimerMotors_t)HARDWARE_MOTOR_TYPE__MOTO_LLOADING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LLOADING].directionthreadwize); + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_LLOADING, 10); +//#warning rocker disabled // activate control fr all motors diff --git a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c index cfdd0057d..bb7b42840 100644 --- a/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c +++ b/Software/Embedded_SW/Embedded/StateMachines/Printing/JobSTM.c @@ -264,7 +264,7 @@ void JobRequestFunc(MessageContainer* requestContainer) { memcpy(CurrentJob, Ticket,TicketSize); status = PASSED; - /*status += */HandleProcessParameters(Ticket->processparameters); + HandleProcessParameters(Ticket->processparameters); // PrepareWaiting[Module_Heaters] = ModuleWaiting; } if (status == PASSED) @@ -272,9 +272,9 @@ void JobRequestFunc(MessageContainer* requestContainer) StartJob(CurrentJob); } + JobResponse response = JOB_RESPONSE__INIT; JobStatus jobStatus = JOB_STATUS__INIT; - if (status == PASSED) { char Msg[13] = "Job Accepted"; -- cgit v1.3.1