<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Tango.Scripting.IDE.Themes">
<Style x:Key="TangoMenuStyle" TargetType="{x:Type Menu}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Background" Value="{DynamicResource Menu.Background}"/>
<Setter Property="FontFamily" Value="{DynamicResource {x:Static SystemFonts.MenuFontFamilyKey}}"/>
<Setter Property="FontSize" Value="{DynamicResource {x:Static SystemFonts.MenuFontSizeKey}}"/>
<Setter Property="FontStyle" Value="{DynamicResource {x:Static SystemFonts.MenuFontStyleKey}}"/>
<Setter Property="FontWeight" Value="{DynamicResource {x:Static SystemFonts.MenuFontWeightKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource Menu.Foreground}"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Menu}">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Style.Triggers>
<Trigger Property="Role" Value="TopLevelHeader">
<Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}" />
<Setter Property="Grid.IsSharedSizeScope" Value="true" />
</Trigger>
<Trigger Property="Role" Value="TopLevelItem">
<Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.TopLevelItemTemplateKey}}" />
</Trigger>
<Trigger Property="Role" Value="SubmenuHeader">
<Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}" />
</Trigger>
<Trigger Property="Role" Value="SubmenuItem">
<Setter Property="Template" Value="{DynamicResource {x:Static MenuItem.SubmenuItemTemplateKey}}" />
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="TextBlock">
<Setter Property="TextWrapping" Value="Wrap"></Setter>
</Style>
</Style.Resources>
</Style>
<Geometry x:Key="Checkmark">M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z</Geometry>
<!-- TopLevelHeader -->
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
<Grid x:Name="Border" Background="Transparent" Margin="0,2,0,2">
<Rectangle x:Name="Bg" Fill="Transparent" />
<Rectangle x:Name="Inner_Border" Margin="4" Fill="Transparent"/>
<ContentPresenter Margin="8,2,8,2" ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Popup x:Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade" HorizontalOffset="2">
<Border x:Name="SubmenuBorder" BorderBrush="{DynamicResource MenuItemHighlightedBackground}" BorderThickness="1" Background="{DynamicResource Menu.Background}" Padding="2" Margin="0,0,8,8">
<Border.Effect>
<DropShadowEffect BlurRadius="6" Opacity="0.5" ShadowDepth="4" Direction="330"/>
</Border.Effect>
<Grid RenderOptions.ClearTypeHint="Enabled" Background="Transparent">
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/>
</Grid>
</Border>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSuspendingPopupAnimation" Value="true">
<Setter TargetName="Popup" Property="PopupAnimation" Value="None" />
</Trigger>
<Trigger Property="IsHighlighted" Value="true">
<Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Menu.Submenu.MouseOverColor}"/>
</Trigger>
<Trigger SourceName="Popup" Property="AllowsTransparency" Value="True">
<Setter TargetName="SubmenuBorder" Property="CornerRadius" Value="0,0,0,0" />
<Setter TargetName="SubmenuBorder" Property="Padding" Value="0,0,0,3" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource Menu.Disable.Foreground}"/>
</Trigger>
<Trigger Property="IsSubmenuOpen" Value="true">
<Setter Property="Background" TargetName="Border" Value="{DynamicResource Menu.Submenu.Background}"/>
<Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Menu.Submenu.Background}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<!-- TopLevelItem -->
<ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}" >
<Grid SnapsToDevicePixels="true" Background="Transparent" Margin="0,2,0,2">
<Rectangle x:Name="Bg" Fill="Transparent" />
<Rectangle x:Name="InnerBorder" Margin="4" Fill="Transparent"/>
<!--<DockPanel>
<ContentPresenter x:Name="Icon" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/>
<Path x:Name="GlyphPanel" Data="{StaticResource Checkmark}" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="7,0,0,0" Visibility="Collapsed" VerticalAlignment="Center"/>-->
<ContentPresenter ContentSource="Header" Margin="8,2,8,2" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<!--</DockPanel>-->
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Menu.Submenu.MouseOverColor}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource Menu.Disable.Foreground}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Menu.Submenu.MouseOverColor}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="MenuItem">
<Grid SnapsToDevicePixels="true" Background="{DynamicResource Menu.Submenu.Background}" x:Name="_grid" MinHeight="22">
<Rectangle x:Name="Bg" Fill="Transparent" />
<Rectangle x:Name="Inner_Border" Margin="4" Fill="Transparent"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Icon" Width="Auto" MinWidth="20"/>
<ColumnDefinition Width="*" MinWidth="60"/>
<ColumnDefinition SharedSizeGroup="MenuItemIGTColumnGroup" Width="Auto" MinWidth="60"/>
<ColumnDefinition Width="13" />
</Grid.ColumnDefinitions>
<ContentPresenter x:Name="Iconh" ContentSource="Icon" Margin="3" VerticalAlignment="Center" Grid.Column="0"/>
<ContentPresenter x:Name="HeaderHost" Margin="3,0,3,0" Grid.Column="1" VerticalAlignment="Center" ContentSource="Header" RecognizesAccessKey="True" TextOptions.TextFormattingMode="Display" />
<TextBlock Grid.Column="2" Margin="10,0,0,0" Text="{TemplateBinding InputGestureText}" VerticalAlignment="Center"/>
<Path x:Name="RightArrow" Grid.Column="3" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 0 7 L 4 3.5 Z" Fill="{DynamicResource Grip.Submenu.Background.Static}" Margin="8,0,0,0"/>
<Popup x:Name="popup" PlacementTarget="{Binding ElementName=_grid}" Placement="Right" HorizontalOffset="0" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
<Border x:Name="SubmenuBorder" SnapsToDevicePixels="True" Background="{DynamicResource Menu.Submenu.Background}" BorderThickness="1" BorderBrush="{DynamicResource MenuItemHighlightedBackground}" Margin="0,0,10,10">
<Border.Effect>
<DropShadowEffect BlurRadius="6" Opacity="0.5" ShadowDepth="4" Direction="330" />
</Border.Effect>
<ItemsPresenter x:Name="_items" />
</Border>
</Popup>
</Grid>
</Grid>
<!--</Border>-->
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="True" >
<Setter Property="Visibility" Value="Visible" TargetName="_items" />
<Setter Property="IsOpen" Value="True" TargetName="popup" />
<Setter Property="Fill" TargetName="Bg" Value="{DynamicResource Menu.Submenu.MouseOverColor}"/>
<Setter Property="Fill" TargetName="Inner_Border" Value="{DynamicResource Menu.Submenu.MouseOverColor}"/>
<Setter TargetName="RightArrow" Property="Fill" Value="{DynamicResource Grip.Submenu.Background.Selected}"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource Menu.Disable.Foreground}"/>
</Trigger>
<Trigger Property="IsSubmenuOpen" Value="true">
<Setter Property="Fill" TargetName="Bg" Value="{Dynamic/*
* Thread_Winder.c
*
* Created on: 25 áîøõ 2018
* Author: shlomo
*/
#include"include.h"
#include "thread.h"
#include "drivers/Motors/Motor.h"
#include "StateMachines/Printing/PrintingSTM.h"
#include "Modules/Control/Control.h"
#include "Modules/Control/MillisecTask.h"
#include "modules/General/process.h"
#include "Common/report/report.h"
#include "drivers/FPGA/FPGA.h"
#include "drivers/Flash_ram/MCU_E2Prom.h"
#include "drivers/FPGA/FPGA_SPI_Comm.h"
#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
#include <PMR/Diagnostics/EventType.pb-c.h>
#include "Modules/AlarmHandling/AlarmHandling.h"
#include <driverlib/timer.h>
#include <inc/hw_ints.h>
#include <inc/hw_memmap.h>
#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);
void ScrewTimerInterrupt(int);
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 ScrewChangeCounter = 0;
//uint32_t ScrewChangeLimit = 0;
uint32_t CalculationDirectionChangeCounter = 1; //holds the current number of runs of the screw - will be used to build the cone
double WinderMotorSpeed[MAX_WINDER_SPEED_CALCULATION];
uint16_t WinderMotorSpeedCounter = 0;
bool WinderMotorSpeedRollOver = false;
int StartWinderCalculation = 0;
#define DEFAULT_SCREW_SPEED 1200
double ScrewSpeed = DEFAULT_SCREW_SPEED;
double RetreatTime = 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;
uint32_t ScrewControlId = 0xFF;
bool IgnoreConeMissing = false;
static bool KeepWindingCone = false;
static uint32_t WindingConeLocation;
static uint32_t WinderBackToBaseTime = 1500;
float NumberOfRotationPerPassage = 0.0;
InternalWinderConfigStruc InternalWinderCfg = {0};
//#define READ_SCREW_ENCODER
#ifdef READ_SCREW_ENCODER
uint32_t ScrewLocationLimitSwitch = 0,ScrewLocationStart = 0;
uint32_t ScrewLocationRun[3];
uint32_t ScrewLocationPrev[3];
float WinderRunAverage = 0.0,WinderRunSum = 0.0;
int WinderRunSamples = 0;
#endif
bool SampleWinding = false;
uint32_t Winder_Init(void)
{
ScrewTimerInterruptInit();
return OK;
}
void SetKeepWindingCone(bool value)
{
KeepWindingCone = value;
ReportWithPackageFilter(ThreadFilter,"set KeepWindingCone",__FILE__,__LINE__,WindingConeLocation,RpWarning,KeepWindingCone, 0);
}
void SetWinderBackToBaseTime(uint32_t value)
{
WinderBackToBaseTime = value;
ReportWithPackageFilter(ThreadFilter,"Set WinderBackToBaseTime",__FILE__,__LINE__,WinderBackToBaseTime,RpWarning,KeepWindingCone, 0);
}
/*uint32_t InternalWinderConfigMessage(HardwareWinder* request)
{
uint32_t status = PASSED;
InternalWinderCfg.milimetersperrotation = request->millimeterperrotation;
return status;
}*/
char ScrewStr[150];
uint32_t InternalWindingConfigMessage(JobSpool* request)
{
uint32_t status = PASSED;
int limitswitchstartpointoffset = 0;
InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses;
InternalWinderCfg.spoolbackingrate = request->backingrate;
InternalWinderCfg.startoffsetpulses = request->startoffsetpulses;
if (request->has_limitswitchstartpointoffset)
{
//InternalWinderCfg.startoffsetpulses += request->limitswitchstartpointoffset;
Report("limit switch start point offset",__FILE__,__LINE__,(int)(request->startoffsetpulses),RpWarning,(int)(request->limitswitchstartpointoffset), 0);
}
status |= MCU_E2PromRead(EEPROM_STORAGE_WINDER_CALIBRATION,&limitswitchstartpointoffset);
if ((status!= OK )||(limitswitchstartpointoffset >= 200))
limitswitchstartpointoffset = 0;
Report("limit switch start point offset",__FILE__,(int)(request->startoffsetpulses),(int)(limitswitchstartpointoffset),RpWarning,status, 0);
InternalWinderCfg.startoffsetpulses += limitswitchstartpointoffset;
InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate;
InternalWinderCfg.NumberOfRotationPerPassage = 3.1415926*3;//request->rotationsperpassage;
if (request->rotationsperpassage > 5.1)
InternalWinderCfg.NumberOfRotationPerPassage = request->rotationsperpassage;
if (NumberOfRotationPerPassage > 1)
{
InternalWinderCfg.NumberOfRotationPerPassage = NumberOfRotationPerPassage;
Report("Rotation per passage set from stub",__FILE__,__LINE__,(int)(request->rotationsperpassage*1000),RpWarning,(int)(InternalWinderCfg.NumberOfRotationPerPassage*1000), 0);
}
InternalWinderCfg.diameter = request->diameter;
usnprintf(ScrewStr, 150, "WindingConfig start,offset,head,tail {, %d, %d, %d, %d, %d}",InternalWinderCfg.startoffsetpulses,(int)InternalWinderCfg.segmentoffsetpulses,
(int)InternalWinderCfg.spoolbackingrate,(int)InternalWinderCfg.SpoolBottomBackingRate,(int)(InternalWinderCfg.NumberOfRotationPerPassage*1000));
Report(ScrewStr,__FILE__,__LINE__,(int)InternalWinderCfg.startoffsetpulses,RpWarning,(int)(InternalWinderCfg.NumberOfRotationPerPassage*1000), 0);
return status;
}
/*
*uint32_t Winder_Prepare(void *JobDetails)
* 1. move home to the limit switch (check that the cart is clear from the limit switch, start moving, with acceleration to maximal speed. enable interrupt on the limit switch, upon interrupt stop.
* report ready to the job STM
*/
int Screw_wait_counter;
uint32_t Winder_Check_Cone(void)
{
if (FPGA_Read_limit_Switches(GPI_SW_SPOOL_EXISTS)==LIMIT)
{
REPORT_MSG(LIMIT, "No cone in winder");
if (Is_PP_Machine())
{
if (IgnoreConeMissing == false)
{
//JobEndReason = JOB_THREAD_BREAK;
usnprintf(AlarmReasonStr, 100, "No cone in winder");
//PrepareReady(Module_Winder,ModuleFail);
AlarmHandlingSetAlarm(EVENT_TYPE__WINDER_CONE_DOES_NOT_EXIST,true);
return JOB_THREAD_BREAK;
}
}
}
return JOB_OK;
}
uint32_t Winder_Prepare(void *JobDetails)
{
JobTicket* JobTicket = JobDetails;
uint32_t status = 0;
//JobTicket* JobTicket = JobDetails;
//float process_speed = JobTicket->processparameters->dyeingspeed;
double ScrewSpeed = DEFAULT_SCREW_SPEED;//(process_speed*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].pulleyradius); // we will use pulley radius of the screw for this purpose, as of now
WinderMotorSpeedRollOver=false;
StartWinderCalculation = 0;
//MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses);
//REPORT_MSG(ScrewSpeed, "Winder_Prepare");
/*
* 1. move home to the limit switch (check that the cart is clear from the limit switch, start moving, with acceleration to maximal speed. enable interrupt on the limit switch, upon interrupt stop.
* 2. move back x steps - according to thehw specifications and bobine definitions in the job. move for a predefined number of steps. get a callback when done
* report ready to the job STM
*/
/*if (FPGA_Read_limit_Switches(GPI_SW_SPOOL_EXISTS)==LIMIT)
{
REPORT_MSG(LIMIT, "No cone in winder");
if (Is_PP_Machine())
{
if (IgnoreConeMissing == false)
{
JobEndReason = JOB_THREAD_BREAK;
usnprintf(AlarmReasonStr, 100, "No cone in winder");
PrepareReady(Module_Winder,ModuleFail);
AlarmHandlingSetAlarm(EVENT_TYPE__WINDER_CONE_DOES_NOT_EXIST,true);
return ERROR;
}
}
}*/
#ifdef READ_SCREW_ENCODER
ScrewLocationRun[0] = 0;
ScrewLocationRun[1] = 0;
WinderRunAverage = 0.0;
WinderRunSum = 0.0;
WinderRunSamples = 0;
#endif
if (( KeepWindingCone == false)||(WindingConeLocation == 0))
{
WindingConeLocation = InternalWinderCfg.startoffsetpulses;
ReportWithPackageFilter(ThreadFilter,"WindingConeLocation set",__FILE__,__LINE__,WindingConeLocation,RpWarning,KeepWindingCone, 0);
}
else
{
ReportWithPackageFilter(ThreadFilter,"WindingConeLocation use previous",__FILE__,__LINE__,WindingConeLocation,RpWarning,KeepWindingCone, 0);
}
if (JobTicket->has_samplewinding == true)
{
SampleWinding = JobTicket->samplewinding;
SampleWinding = true;
}
if (FPGA_Read_limit_Switches(GPI_LS_SCREW_RIGHT)==LIMIT)
{
//REPORT_MSG(LIMIT, "Winder_Prepare at limit");
Winder_PrepareStage2(0,0);
Screw_wait_counter=1;
}
else
{
//REPORT_MSG(ScrewSpeed, "Winder_Prepare");
Winder_ScrewHoming = true;
//REPORT_MSG(MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, "Winder_Prepare move to limit");
Screw_wait_counter=1;
status = MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, Winder_PrepareStage2,2000);
}
#ifdef FOUR_WINDERS
if (FPGA_Read_limit_Switches(GPI_LS_SPARE2_2)==LIMIT)
{
Winder_PrepareStage2(0,0);
Screw_wait_counter++;
}
else
{
Winder_ScrewHoming = true;
Screw_wait_counter++;
status = MotorMovetoLimitSwitch (SCREW_2_Motor,MotorsCfg[SCREW_2_Motor].directionthreadwize, ScrewSpeed, GPI_LS_SPARE2_2, Winder_PrepareStage2,2000);
}
if (FPGA_Read_limit_Switches(GPI_LS_SPARE1_2)==LIMIT)
{
Winder_PrepareStage2(0,0);
Screw_wait_counter++;
}
else
{
Winder_ScrewHoming = true;
Screw_wait_counter++;
status = MotorMovetoLimitSwitch (SCREW_3_Motor,MotorsCfg[SCREW_3_Motor].directionthreadwize, ScrewSpeed, GPI_LS_SPARE1_2, Winder_PrepareStage2,2000);
}
if (FPGA_Read_limit_Switches(GPI_LS_RDANCER_UP)==LIMIT)
{
Winder_PrepareStage2(0,0);
Screw_wait_counter++;
}
else
{
Winder_ScrewHoming = true;
Screw_wait_counter++;
status = MotorMovetoLimitSwitch (SCREW_4_Motor,MotorsCfg[SCREW_4_Motor].directionthreadwize, ScrewSpeed, GPI_LS_RDANCER_UP, Winder_PrepareStage2,2000);
}
#endif
return status;
}
/*
* uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue)
* 2. move back x steps - according to thehw specifications and bobine definitions in the job. move for a predefined number of steps. get a callback when done
* report ready to the job STM
*/
uint32_t Winder_PrepareStage2(uint32_t deviceID, uint32_t ReadValue)
{
uint32_t status=OK;
uint32_t numOfSteps = WindingConeLocation*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep;
//MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,InternalWinderCfg.segmentoffsetpulses);
//REPORT_MSG(numOfSteps, "Winder_PrepareStage2");
#ifdef READ_SCREW_ENCODER
Read_Screw_Encoder();
ScrewLocationLimitSwitch = Screw_RotEnc.Position;
REPORT_MSG(ScrewLocationLimitSwitch, "Winder_PrepareStage2 Encoder Location");
#endif
REPORT_MSG(millisecondCounter/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].maxfrequency*/, "Winder_PrepareStage2");
Screw_wait_counter--;
if (ReadValue != LIMIT)
{
if (JobIsActive()==true)
{
LOG_ERROR(deviceID,"Screw failed to reach the limit switch!!");
//returned with a timeout
Winder_ScrewAtOffsetCallback(0,0);
PrepareReady(Module_Winder, ModuleFail);
}
else //short jog, etc
{
AlarmHandlingSetAlarm (EVENT_TYPE__SCREW_MOTOR_LIMIT_TIMEOUT,OFF); //on a short jog, this callback will be called without need
}
}
else
{
if (Screw_wait_counter!=0)
{
ReportWithPackageFilter(ThreadFilter,"waiting for winders",__FILE__,__LINE__,Screw_wait_counter,RpWarning,deviceID, 0);
return status;
}
Screw_wait_counter++;
status |= MotorMoveWithCallback(HARDWARE_MOTOR_TYPE__MOTO_SCREW, (1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize),numOfSteps, Winder_ScrewAtOffsetCallback,1000);
#ifdef FOUR_WINDERS
Screw_wait_counter++;
status |= MotorMoveWithCallback (SCREW_2_Motor,(1-MotorsCfg[SCREW_2_Motor].directionthreadwize), numOfSteps, Winder_ScrewAtOffsetCallback,1000);
Screw_wait_counter++;
status |= MotorMoveWithCallback (SCREW_3_Motor,(1-MotorsCfg[SCREW_3_Motor].directionthreadwize), numOfSteps, Winder_ScrewAtOffsetCallback,1000);
Screw_wait_counter++;
status |= MotorMoveWithCallback (SCREW_4_Motor,(1-MotorsCfg[SCREW_4_Motor].directionthreadwize), numOfSteps, Winder_ScrewAtOffsetCallback,1000);
#endif
}
//set motor location 0 here
return status;
}
uint32_t Winder_ScrewAtOffsetCallback(uint32_t MotorId, uint32_t BusyFlag)
{
//MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,temp_MaxFrequency);
if (Screw_wait_counter)
Screw_wait_counter--;
MotorStop (MotorId,Soft_Hiz); //per L6470 errata between mov and run commands
/*#ifdef FOUR_WINDERS
MotorStop(SCREW_2_Motor, Hard_Hiz);
MotorStop(SCREW_3_Motor, Hard_Hiz);
MotorStop(SCREW_4_Motor, Hard_Hiz);
#endif*/
Task_sleep(5);
#ifdef READ_SCREW_ENCODER
Reset_Screw_Encoder();
Task_sleep(5);
Read_Screw_Encoder();
Task_sleep(5);
ScrewLocationStart = Screw_RotEnc.Position;
REPORT_MSG(ScrewLocationStart, "Winder_ScrewAtOffsetCallback Encoder Location");
#endif
SetMotHome(MotorId); //set this point as the spool home
/*#ifdef FOUR_WINDERS
SetMotHome(SCREW_2_Motor);
SetMotHome(SCREW_3_Motor);
SetMotHome(SCREW_4_Motor);
#endif*/
ScrewCurrentDirection = false;
#ifdef READ_SCREW_ENCODER
ScrewLocationRun[ScrewCurrentDirection] = Screw_RotEnc.Position;
#endif
ScrewSpeed = 0;
ScrewControlId = 0xFF;
ScrewNumberOfSteps = 0;
ReportWithPackageFilter(ThreadFilter,"Winder_ScrewAtOffsetCallback",__FILE__,millisecondCounter,Screw_wait_counter,RpWarning,MotorId, 0);
if (Screw_wait_counter == 0)
PrepareReady(Module_Winder, ModuleDone);
return OK;
}
/*
* this is the main operational function of the screw - run back and forth until stopped
*/
/*
InternalWinderCfg.segmentoffsetpulses = request->segmentoffsetpulses;
InternalWinderCfg.spoolbackingrate = request->backingrate;
InternalWinderCfg.startoffsetpulses = request->startoffsetpulses;
InternalWinderCfg.SpoolBottomBackingRate = request->bottombackingrate;
InternalWinderCfg.NumberOfRotationPerPassage = request->rotationsperpassage;
*
Calculate the number of steps.
Initial home position = ...
Initial out movement = ScrewNumberOfSteps
if DirectionChangeCounter %= backingrate : reduce one from the ScrewNumberOfSteps
if DirectionChangeCounter %= bottombackingrate && direction was out: ADD one to the ScrewNumberOfSteps,
// WRONG? if the flag is raised - lower it and reduce one from the ScrewNumberOfSteps
30:100 - 70
30:99 - 69
30:98 - 68
29:98 - 69
29:97 -68
InternalWinderCfg.segmentoffsetpulses
int32_t backingrate;
int32_t bottombackingrate;
numOfSteps = InternalWinderCfg.startoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep;
*/
//char TempScrewStr[100];
double WinderReferenceSpeed=0;
double TotalWinderSpeed=0;
bool Add100 = false;
int flipflop = 0;
uint32_t motspeed;
float speedf;
int WinderCalculation = 0;
#ifdef FOUR_WINDERS
int MotorOrder[4] = {HARDWARE_MOTOR_TYPE__MOTO_SCREW,SCREW_2_Motor,SCREW_3_Motor,SCREW_4_Motor};
#endif
uint32_t Screw100msecDirectionChange(uint32_t deviceID, uint32_t BusyFlag)
{
//uint32_t Steps;
double temp,tempScrewSpeed;
#ifdef FOUR_WINDERS
int tempmot;
#endif
//double screw_horizontal_speed = 0;
//double RotationsPerSecond;
if (WinderMotorSpeedCounter++>=MAX_WINDER_SPEED_CALCULATION)
{
if (WinderMotorSpeedRollOver == false)
{
Add100 = true;
//LOG_ERROR(Add100, "Add100 = true");
}
// WinderMotorSpeedCounter=0;
}
if (ScrewDirectionChangeCounter == CalculationDirectionChangeCounter)
return OK;
//deley TODO
//flipflop = 0;
ScrewCurrentDirection = 1-ScrewCurrentDirection;
CalculationDirectionChangeCounter++;
#ifdef FOUR_WINDERS
tempmot = MotorOrder[0];
MotorOrder[0] = MotorOrder[1];
MotorOrder[1] = MotorOrder[2];
MotorOrder[2] = MotorOrder[3];
MotorOrder[3] = tempmot;
//Report("order change" ,__FILE__,MotorOrder[0],MotorOrder[1],RpWarning,MotorOrder[2], 0);
#endif
if (SampleWinding)
return OK;
//double calcsteps = (ScrewRunningTime/SYS_CLK_FREQ)*ScrewSpeed;
#ifdef READ_SCREW_ENCODER
int WinderRun;
WinderRun = abs(ScrewLocationRun[1] - ScrewLocationRun[0]);
if (WinderMotorSpeedRollOver == true)
StartWinderCalculation++;
if ((WinderRun < 30000)&&(StartWinderCalculation >= 2))
{
WinderRunSamples++;
WinderRunSum+=WinderRun;
WinderRunAverage = WinderRunSum/WinderRunSamples;
if ((fabs(WinderRun-WinderRunAverage)>=30)||(WinderRunSamples%100 == 0))
{
usnprintf(ScrewStr, 150, "curr,sum,avg,samples {Winder Encoder:, %d, %d, %d, %d, %d}",WinderRun,(int)WinderRunSum,(int)WinderRunAverage,(int)WinderRunSamples,
(int)(100*WinderRun/ScrewNumberOfSteps));
Report(ScrewStr,__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewLocationStart, 0);
}
}
if (abs(ScrewLocationPrev[1]-ScrewLocationRun[1])>21)
{
Report("Winder difference",__FILE__,CalculationDirectionChangeCounter,ScrewLocationPrev[1],RpWarning,ScrewLocationRun[1], 0);
}
ScrewLocationPrev[1] = ScrewLocationRun[1];
if (abs(ScrewLocationPrev[0]-ScrewLocationRun[0])>21)
{
Report("Winder difference",__FILE__,CalculationDirectionChangeCounter,ScrewLocationPrev[0],RpWarning,ScrewLocationRun[0], 0);
}
ScrewLocationPrev[0] = ScrewLocationRun[0];
#endif
if (ScrewCurrentDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize) //next time going out
{
if (Add100 == true) //once per job
{
ScrewNumberOfSteps += 100;
Add100 = false;
WinderMotorSpeedRollOver=true;
}
if ((CalculationDirectionChangeCounter/2)%InternalWinderCfg.spoolbackingrate == 0)
{
ScrewNumberOfSteps--;
WindingConeLocation--;
// ReportWithPackageFilter(ThreadFilter,"Head Backing",__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewNumberOfSteps, 0);
}
}
else //next time going back
{
if ((CalculationDirectionChangeCounter/2)%InternalWinderCfg.SpoolBottomBackingRate == 0)
{
ScrewNumberOfSteps++;
// Report("Bottom Backing ",__FILE__,__LINE__,CalculationDirectionChangeCounter,RpWarning,ScrewNumberOfSteps, 0);
}
}
tempScrewSpeed = ScrewSpeed;
CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed;
temp = SYS_CLK_FREQ;
temp *= ScrewNumberOfSteps;
temp /= tempScrewSpeed;
if ((ScrewRunningTime != temp)||(ScrewSpeed != tempScrewSpeed))
{
ScrewSpeed = tempScrewSpeed;
//ScrewSpeed = DEFAULT_SCREW_SPEED;
ScrewRunningTime = temp;//(SYS_CLK_FREQ*Steps)/ScrewSpeed;
//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);
// 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_MSG(temp , "new winder speed");
//Report("new winder speed",__FILE__,ScrewNumberOfSteps,temp,RpWarning,ScrewSpeed,0);
}
/********************************************************************************/
//ROM_IntMasterEnable();
return OK;
}
uint32_t WinderPresegmentReady(uint32_t deviceID, uint32_t ReadValue)
{
return PreSegmentReady(Module_Winder,ModuleDone);
}
uint32_t WinderSamplesSegmentCallback(uint32_t SegmentDetails, uint32_t SegmentId)
{
ScrewTimerInterrupt(0);
return OK;
}
uint32_t Winder_Presegment(void *SegmentDetails, uint32_t SegmentId)
{
double screw_horizontal_speed = 0;
double RotationsPerSecond;
double temp = 0;
if (dyeingspeed == 0)
{
LOG_ERROR (dyeingspeed," job speed zero");
return ERROR;
}
if ((SegmentId == 0)||(SampleWinding)) // do all this only in the beginning of the job. do not touch after that (assuming spool does not change mid job)
{
ScrewCurrentDirection = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize;
if ((SegmentId > 0)&&(SampleWinding))
{
InternalWinderCfg.segmentoffsetpulses = 120;
MotorGotoWithBusyCallback (HARDWARE_MOTOR_TYPE__MOTO_SCREW,true, (InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep*(SegmentId-1)), WinderSamplesSegmentCallback,2000); //TODO
Report("ScrewsMotorGoTo direction,speed ", __FILE__,__LINE__,InternalWinderCfg.segmentoffsetpulses*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep*(SegmentId-1), RpMessage, ScrewSpeed, 0);
InternalWinderCfg.spoolbackingrate = 2000; //no cone for samples
InternalWinderCfg.SpoolBottomBackingRate = 2000; //no cone shape for samples
InternalWinderCfg.NumberOfRotationPerPassage = 100; // a very slow movement of the screw
JobSegment* Segment = SegmentDetails;
ScrewSpeed = InternalWinderCfg.segmentoffsetpulses/(((Segment->length *100)/dyeingspeed)/3);
ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep;
//three passages during the segment
}
else if (SampleWinding) //first segment
{
//InternalWinderCfg.segmentoffsetpulses = 120;
InternalWinderCfg.spoolbackingrate = 2000; //no cone for samples
InternalWinderCfg.SpoolBottomBackingRate = 2000; //no cone shape for samples
InternalWinderCfg.NumberOfRotationPerPassage = 100; // a very slow movement of the screw
JobSegment* Segment = SegmentDetails;
ScrewSpeed = InternalWinderCfg.segmentoffsetpulses/(((Segment->length *100)/dyeingspeed)/20);
ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep;
}
else if ((SegmentId == 0)&&(SampleWinding == false))
{
/*
// * speed is set by the winding parameters and by winder rotational speed (read POSITION every 10msec)
// * calculate
// * 1. calculate speed according to JobTicket->processparameters->dyeingspeed
// * calculation input: traverse length in milimeters/pulses, number of rotations per traverse ==> length of traverse per rotation.
ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep;
ScrewNumberOfSteps -= 100;
screw_horizontal_speed = ScrewNumberOfSteps / InternalWinderCfg.NumberOfRotationPerPassage;
// calculation input#2: number of rotations per second - (basically: speed/winder perimeter. later - according to winder actual speed - calculate according to winder position accumulation in the last second.
//RotationsPerSecond = dyeingspeed / (MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulleyradius * PI);
RotationsPerSecond = OriginalMotorSpd_2PPS[WINDER_MOTOR] / MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].pulseperround;
// calculation input#3: speed = rotation per second * traverse per rotation = traverse per second. speed set: traverse per second (mm) * pulses per mm.
ScrewSpeed = screw_horizontal_speed*RotationsPerSecond;
ScrewSpeed = DEFAULT_SCREW_SPEED;
//MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed);
usnprintf(ScrewStr, 100, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond,(int)screw_horizontal_speed,(int)ScrewSpeed);
//REPORT_MSG(segmentfirst_speed,ScrewStr);
Report(ScrewStr,__FILE__,__LINE__,RotationsPerSecond,RpWarning,ScrewSpeed,0);
SendJobProgress(0.0,0,false, ScrewStr);
*/
// * speed is set by the winding parameters and by winder rotational speed (read POSITION every 10msec)
// * calculate
// * 1. calculate speed according to JobTicket->processparameters->dyeingspeed
// * calculation input: traverse length in pulses, number of rotations per traverse ==> length of traverse per rotation.
ScrewNumberOfSteps = InternalWinderCfg.segmentoffsetpulses;//*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].microstep;
screw_horizontal_speed = InternalWinderCfg.segmentoffsetpulses / InternalWinderCfg.NumberOfRotationPerPassage; //steps per winder cycle
// calculation input#2: number of rotations per second - speed/winder diameter. WE USE HERE 39 MM AS ATHE WINDER DIAMETER - SOME AVERAGE BETWEEN EMPTY AND FULL
RotationsPerSecond = (dyeingspeed*10.0)/(19.50*PI);
// calculation input#3: speed = rotation per second * traverse per rotation = traverse per second. speed set: traverse per second (mm) * pulses per mm.
ScrewSpeed = screw_horizontal_speed*RotationsPerSecond;
ScrewNumberOfSteps -= 100;
Add100 = false;
LOG_ERROR(Add100, "Add100 = false");
}
usnprintf(ScrewStr, 100, "SCREW speed Rot/sec %d horizon %d pulses %d",(int)RotationsPerSecond*100,(int)screw_horizontal_speed*100,(int)ScrewSpeed);
//REPORT_MSG(segmentfirst_speed,ScrewStr);
Report(ScrewStr,__FILE__,__LINE__,RotationsPerSecond,RpWarning,ScrewSpeed,0);
SendJobProgress(0.0,0,false, ScrewStr);
ScrewDirectionChangeCounter = 1;
CalculationDirectionChangeCounter = 1;
memset (WinderMotorSpeed,0,sizeof(WinderMotorSpeed) );
WinderMotorSpeedCounter=0;
TotalWinderSpeed = 0;
WinderMotorSpeedRollOver=false;
///////////////////////
CurrentControlledSpeed[SCREW_MOTOR] = ScrewSpeed;
OriginalMotorSpd_2PPS[SCREW_MOTOR] = ScrewSpeed;
WinderReferenceSpeed = OriginalMotorSpd_2PPS[WINDER_MOTOR];
//screw_horizontal_speed = InternalWinderCfg.milimetersperrotation
// * 2. determine optimal micro-step setting
// * 3. calculate cart travel length from winding parameters
// * 4. start move of travel length
// * 5. register motor nBusy callback. this callback will flip between move(traverse length, hardstop) and goto(0), with handline og the coneshape and adjusting maxspeed
temp = SYS_CLK_FREQ;
temp *= ScrewNumberOfSteps;
temp /= ScrewSpeed;
ScrewRunningTime = temp;//(SYS_CLK_FREQ*InternalWinderCfg.segmentoffsetpulses)/ScrewSpeed;
RetreatTime = ScrewNumberOfSteps*1000/ScrewSpeed;
REPORT_MSG((int)ScrewNumberOfSteps,"Winder pre segment - ScrewNumberOfSteps");
REPORT_MSG((int)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 ();
}
if (SegmentId == 0)
{
ScrewControlId = AddControlCallback("screw control",Screw100msecDirectionChange, eHundredMillisecond,TemplateDataReadCBFunction,0,0,0);
}
PreSegmentReady(Module_Winder,ModuleDone);
return OK;
}
uint32_t ScrewDTSControlId = 0xFF;
uint32_t WinderDistanceToSpoolEnded(uint32_t deviceID, uint32_t ReadValue)
{
REPORT_MSG ((int)msec_millisecondCounter,"WinderDistanceToSpoolEnded called");
return OK;
}
uint32_t ScrewDTSCallback(uint32_t deviceID, uint32_t BusyFlag)
{
Report("ScrewDTSCallback called", __FILE__,__LINE__,msec_millisecondCounter, RpMessage, ScrewSpeed, 0);
SafeRemoveControlCallback(ScrewDTSControlId, ScrewDTSCallback);
if (ScrewControlId != 0xFF)
{
RemoveControlCallback(ScrewControlId,Screw100msecDirectionChange);
ScrewControlId = 0xFF;
}
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,0);
//MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz);
MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize, ScrewSpeed, GPI_LS_SCREW_RIGHT, WinderDistanceToSpoolEnded,RetreatTime*2);
#ifdef FOUR_WINDERS
MotorMovetoLimitSwitch (SCREW_2_Motor,MotorsCfg[SCREW_2_Motor].directionthreadwize, ScrewSpeed, GPI_LS_SPARE2_2, NULL,RetreatTime*2);
MotorMovetoLimitSwitch (SCREW_3_Motor,MotorsCfg[SCREW_3_Motor].directionthreadwize, ScrewSpeed, GPI_LS_SPARE1_2, NULL,RetreatTime*2);
MotorMovetoLimitSwitch (SCREW_4_Motor,MotorsCfg[SCREW_4_Motor].directionthreadwize, ScrewSpeed, GPI_LS_RDANCER_UP, NULL,RetreatTime*2);
#endif
return OK;
}
uint32_t WinderDistanceToSpoolState(void )
{
double DTS_Time = (dryerbufferCentimeters/dyeingspeed)*1000;//distance to spool time in milliseconds
double WinderBackTimeBySpeed = WinderBackToBaseTime;
WinderBackTimeBySpeed *= 50;
WinderBackTimeBySpeed /= dyeingspeed;
Report("WinderDistanceToSpoolState start", __FILE__,DTS_Time,RetreatTime, RpMessage, (int)WinderBackTimeBySpeed, 0);
//REPORT_MSG ((int)DTS_Time,"WinderDistanceToSpoolState");
ScrewDTSControlId = AddControlCallback("screw DTS",ScrewDTSCallback, DTS_Time-RetreatTime,TemplateDataReadCBFunction,0,0,0);
Report("ScrewDTSCallback start", __FILE__,DTS_Time,msec_millisecondCounter, RpMessage, (int)WinderBackTimeBySpeed, 0);
return OK;
}
uint32_t Winder_End(void)
{
//stop screw
ScrewNumberOfSteps = 0;
if (ScrewControlId != 0xFF)
{
RemoveControlCallback(ScrewControlId,Screw100msecDirectionChange);
ScrewControlId = 0xFF;
}
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,0);
//MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz);
MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_SCREW); //bug #2709
#ifdef FOUR_WINDERS
MotorAbortMovetoLimitSwitch (SCREW_2_Motor);
MotorAbortMovetoLimitSwitch (SCREW_3_Motor);
MotorAbortMovetoLimitSwitch (SCREW_4_Motor);
#endif
return OK;
}
/*void Winder_ScrewHomeLimitSwitchInterrupt(void)
{
//uint32_t status;
//handle glitch - send information to the next time that the motor stops
if (Winder_ScrewHoming)
{
MotorStop(HARDWARE_MOTOR_TYPE__MOTO_SCREW,Hard_Hiz); //stop ASAP
}
MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out
}
void Winder_ScrewOutLimitSwitchInterrupt(void)
{
//handle glitch - send information to the next time that the motor stops
//uint32_t status;
MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_SCREW,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_SCREW].directionthreadwize);//make sure to move the cart out
}*/
uint32_t Screw_timerBase = TIMER3_BASE; //Timer handle
void ScrewTimerInterruptInit(void)
{
ROM_TimerConfigure(Screw_timerBase, TIMER_CFG_PERIODIC); // 32 bits Timer
ROM_TimerEnable(Screw_timerBase, TIMER_A);
ROM_IntEnable(INT_TIMER3A);
ROM_TimerIntEnable(Screw_timerBase, TIMER_TIMA_TIMEOUT);
}
void ScrewsStopControlTimer (void)
{
SCREW_TimerActivated = false;
ROM_TimerDisable(Screw_timerBase, TIMER_A);
//ROM_IntDisable(INT_TIMER3A);
//ROM_TimerIntDisable(Screw_timerBase, TIMER_TIMA_TIMEOUT);
}
void ScrewsStartControlTimer (void)
{
if (SCREW_TimerActivated == true)
return;
SCREW_TimerActivated = true;
//ROM_TimerConfigure(Screw_timerBase, TIMER_CFG_PERIODIC); // 32 bits Timer
TimerEnable(Screw_timerBase, TIMER_A);
ROM_IntEnable(INT_TIMER3A);
//IntPrioritySet(Screw_timerBase, 0x40);
ROM_TimerIntEnable(Screw_timerBase, TIMER_TIMA_TIMEOUT);
ROM_TimerLoadSet(Screw_timerBase, TIMER_A,(int)1200000/*10 millisec*/ );
Report("ScrewsStartControlTimer direction,speed ", __FILE__,__LINE__,ScrewCurrentDirection, RpMessage, ScrewSpeed, 0);
return;
}
void ScrewTimerInterrupt(int ARG0)
{
ROM_TimerIntClear(Screw_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt
ROM_IntMasterDisable();
if (SCREW_TimerActivated == true)
{
ROM_TimerLoadSet(Screw_timerBase, TIMER_A,(int)ScrewRunningTime);
MotorSetDirection (HARDWARE_MOTOR_TYPE__MOTO_SCREW, ScrewCurrentDirection);
#ifdef FOUR_WINDERS
MotorSetDirection (SCREW_2_Motor, ScrewCurrentDirection);
MotorSetDirection (SCREW_3_Motor, ScrewCurrentDirection);
MotorSetDirection (SCREW_4_Motor, ScrewCurrentDirection);
#endif
#ifdef FOUR_WINDERS
MotorSetSpeedDirect(MotorOrder[0],ScrewSpeed);
MotorSetSpeedDirect (MotorOrder[1], ScrewSpeed);
MotorSetSpeedDirect (MotorOrder[2], ScrewSpeed);
MotorSetSpeedDirect (MotorOrder[3], ScrewSpeed);
#else
MotorSetSpeedDirect(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed);
#endif
#ifdef READ_SCREW_ENCODER
Read_Screw_Encoder();
ScrewLocationRun[ScrewCurrentDirection] = Screw_RotEnc.Position;
#endif
// ScrewChangeCounter = 0;
// ScrewChangeLimit = ScrewRunningTime/12000000;
ScrewDirectionChangeCounter++;
}
else
{
TimerDisable(Screw_timerBase, TIMER_A);
}
ROM_IntMasterEnable();
//Report("ScrewsStartControlTimer time direction,speed ", __FILE__,msec_millisecondCounter,ScrewCurrentDirection, RpMessage, ScrewSpeed, 0);
//MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_SCREW,ScrewSpeed);
//Rotations+=0.03;
return ;
}