diff options
| author | Avi Levkovich <avi@twine-s.com> | 2019-01-09 13:45:40 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2019-01-09 13:45:40 +0200 |
| commit | c2019e2a94afc7f25258ae38478ae74434414a1f (patch) | |
| tree | ee9cf870d5738004ebd92cf841c1bdbd26793984 /Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c | |
| parent | c84c8852f2889235a181ec74f0d2fdf8584f2a7d (diff) | |
| parent | d50d729a2b7d45ca4b22df7ff0d8823825c479b6 (diff) | |
| download | Tango-c2019e2a94afc7f25258ae38478ae74434414a1f.tar.gz Tango-c2019e2a94afc7f25258ae38478ae74434414a1f.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c')
| -rw-r--r-- | Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c index 14769ec05..b080c45c9 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_Winder.c @@ -26,29 +26,28 @@ #include <inc/hw_memmap.h> -bool Winder_ScrewHoming = false; - #define MAX_WINDER_SPEED_CALCULATION 200 + uint32_t Winder_ScrewAtOffsetCallback(uint32_t deviceID, uint32_t BusyFlag); uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue); +void ScrewTimerInterruptInit(void); +void ScrewsStopControlTimer (void); +void ScrewsStartControlTimer (void); -bool ScrewCurrentDirection = false; //holds current screw direction +bool Winder_ScrewHoming = false; +bool ScrewCurrentDirection = false; //holds current screw direction uint32_t ScrewDirectionChangeCounter = 1; //holds the current number of runs of the screw - will be used to build the cone uint32_t CalculationDirectionChangeCounter = 1; //holds the current number of runs of the screw - will be used to build the cone uint16_t WinderMotorSpeed[MAX_WINDER_SPEED_CALCULATION]; uint16_t WinderMotorSpeedCounter = 0; -bool WinderMotorSpeedRollOver = false; -double ScrewSpeed = 0; -double ScrewRunningTime = 0; +bool WinderMotorSpeedRollOver = false; +double ScrewSpeed = 0; +double ScrewRunningTime = 0; uint32_t ScrewNumberOfSteps = 0; //holds the current number of steps for the next screw run - will be used to build the cone -bool SCREW_TimerActivated = false; -//ScrewSpeed +bool SCREW_TimerActivated = false; uint32_t ScrewControlId = 0xFF; InternalWinderConfigStruc InternalWinderCfg = {0}; -void ScrewTimerInterruptInit(void); -void ScrewsStopControlTimer (void); -void ScrewsStartControlTimer (void); uint32_t Winder_Init(void) { @@ -107,7 +106,7 @@ uint32_t Winder_Prepare(void) //REPORT_MSG(ScrewSpeed, "Winder_Prepare"); Winder_ScrewHoming = true; //REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, "Winder_Prepare move to limit"); - status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, Winder_PrepareStage2); + status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, Winder_PrepareStage2,2000); } return status; } @@ -126,7 +125,7 @@ uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue) //REPORT_MSG(numOfSteps, "Winder_PrepareStage2"); REPORT_MSG(millisecondCounter/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency*/, "Winder_PrepareStage2"); - status |= MotorMoveWithCallback(HARDWARE_MOTOR_TYPE__MOTO_SCREW, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize),numOfSteps, Winder_ScrewAtOffsetCallback); + status |= MotorMoveWithCallback(HARDWARE_MOTOR_TYPE__MOTO_SCREW, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize),numOfSteps, Winder_ScrewAtOffsetCallback,1000); //set motor location 0 here return status; @@ -181,7 +180,7 @@ int32_t TotalWinderSpeed=0; uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag) { uint32_t Steps; - double temp; + double temp,tempScrewSpeed; double screw_horizontal_speed = 0; double RotationsPerSecond; int32_t Averagewinderspeed = 0; @@ -226,34 +225,35 @@ uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag) }*/ Averagewinderspeed = TotalWinderSpeed/MAX_WINDER_SPEED_CALCULATION; //REPORT_MSG(winderspeed, "WinderSpeedUpdated"); - Report("WinderSpeedUpdated",__FILE__,__LINE__,TotalWinderSpeed,RpWarning,Averagewinderspeed,0); + //Report("WinderSpeedUpdated",__FILE__,__LINE__,TotalWinderSpeed,RpWarning,Averagewinderspeed,0); WinderReferenceSpeed = Averagewinderspeed; } screw_horizontal_speed = ScrewNumberOfSteps / InternalWinderCfg.NumberOfRotationPerPassage; RotationsPerSecond = WinderReferenceSpeed / (double)MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround; - ROM_IntMasterDisable(); - ScrewSpeed = screw_horizontal_speed*RotationsPerSecond; + tempScrewSpeed = screw_horizontal_speed*RotationsPerSecond; + //ROM_IntMasterDisable(); CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed; temp = SYS_CLK_FREQ; temp *= ScrewNumberOfSteps; - temp /= ScrewSpeed; - if (ScrewRunningTime != temp) + temp /= tempScrewSpeed; + if ((ScrewRunningTime != temp)||(ScrewSpeed != tempScrewSpeed)) { + ScrewSpeed = tempScrewSpeed; ScrewRunningTime = temp;//(SYS_CLK_FREQ*Steps)/ScrewSpeed; - ROM_IntMasterEnable(); + //ROM_IntMasterEnable(); //usnprintf(TempScrewStr, 100, "Winder: Horizon,Rotation, PPR, RPP{ %d, %d ,%d, %d} ",(int)screw_horizontal_speed,(int)RotationsPerSecond,(int)InternalWinderCfg.NumberOfRotationPerPassage,(int)MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround); - usnprintf(ScrewStr, 100, "Winder: Steps,Speed, Time, WinderSpeed{ %d, %d ,%d, %d} ",(int)ScrewNumberOfSteps,(int)ScrewSpeed,(int)temp,(int)WinderReferenceSpeed); + //usnprintf(ScrewStr, 100, "Winder: Steps,Speed, Time, WinderSpeed{ %d, %d ,%d, %d} ",(int)ScrewNumberOfSteps,(int)ScrewSpeed,(int)temp,(int)WinderReferenceSpeed); // Report(logmsg[index],__FILE__,__LINE__,index,RpWarning,index, Counter[index]); // #warning PID is now only proportional (above) //Report(TempScrewStr,__FILE__,__LINE__,0,RpWarning,0, 0); - Report(ScrewStr,__FILE__,__LINE__,ScrewCurrentDirection,RpWarning,CalculationDirectionChangeCounter, 0); + //Report(ScrewStr,__FILE__,__LINE__,ScrewCurrentDirection,RpWarning,CalculationDirectionChangeCounter, 0); //REPORT_MSG(temp , "new winder speed"); //Report("new winder speed",__FILE__,__LINE__,temp,RpWarning,ScrewSpeed,0); } /********************************************************************************/ - ROM_IntMasterEnable(); + //ROM_IntMasterEnable(); return OK; } @@ -313,6 +313,7 @@ uint32_t Winder_Presegment(void *JobDetails, uint32_t SegmentId) REPORT_MSG(ScrewRunningTime,"Winder pre segment - ScrewRunningTime"); // MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); //ScrewDirection = 1-ScrewDirection; + REPORT_MSG(SegmentId,"Winder pre segment - SegmentId"); REPORT_MSG(ScrewSpeed,"Winder pre segment - ScrewSpeed"); //MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); ScrewsStartControlTimer (); @@ -340,7 +341,7 @@ uint32_t Winder_End(void) CurrentControlledSpeed[SCREW_MOTOR] = 0; ScrewsStopControlTimer(); //move the cart to the edge so the spool can be easily replaced - MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, 1000, GPI_LS_SCREW_RIGHT, NULL); + MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, 1000, GPI_LS_SCREW_RIGHT, NULL,0); return OK; } @@ -398,12 +399,10 @@ void ScrewTimerInterrupt(int ARG0) { ROM_TimerIntClear(Screw_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt ROM_IntMasterDisable(); - //ScrewDirectionChange(0,NOTBUSY); if (SCREW_TimerActivated == true) { MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection); -// ScrewCurrentDirection = 1-ScrewCurrentDirection; MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed); ROM_TimerLoadSet(Screw_timerBase, TIMER_A,(int)ScrewRunningTime); ScrewDirectionChangeCounter++; @@ -412,11 +411,11 @@ void ScrewTimerInterrupt(int ARG0) { TimerDisable(Screw_timerBase, TIMER_A); } - Report("ScrewTimerInterrupt dir, duration, speed", __FILE__,ScrewCurrentDirection,ScrewRunningTime, RpMessage, ScrewSpeed, 0); + ROM_IntMasterEnable(); + //Report("ScrewTimerInterrupt dir, duration, speed", __FILE__,ScrewCurrentDirection,ScrewRunningTime, RpMessage, ScrewSpeed, 0); // // Enable all interrupts. // - ROM_IntMasterEnable(); return ; } |
