T J SHARON Posted January 23, 2020 Report Posted January 23, 2020 Hi all, I have an FB (ST) which will calculate the UINT values that need to send to DA outputs. Currently i was requested to add a delay between the calculated output & DA units. I am not sure how to do it? can I just use a TON? Any sample ST code?
chelton Posted January 23, 2020 Report Posted January 23, 2020 How big a delay are you wanting to achieve? You will need to push the current value onto a stack at a defined rate. Then move the last value of the stack to the output. If you were to create a delay of 10 seconds updating every 100ms you would need 100 registers.
T J SHARON Posted January 23, 2020 Author Report Posted January 23, 2020 hi Chelton, Mostly 1-5 seconds delay. Do you have any sample prgm?
chelton Posted January 25, 2020 Report Posted January 25, 2020 Try something like this. Time delay is adjustable from 0 - 10 Seconds IF EN AND Run AND NOT Ring_Buffer_Initialize THEN Ring_Buffer_Write_Index:= 0; Ring_Buffer_Read_Index:= 0; Ring_Buffer_Size:= LIMIT(0,Time_Delay,10); Ring_Buffer_Size:= Ring_Buffer_Size*10; Ring_Buffer_Initialize:= TRUE; END_IF; IF NOT Run THEN Ring_Buffer_Initialize:= FALSE; RB_Loaded:= FALSE; END_IF; IF P_0_1s AND Run AND NOT ONS_Trig THEN Ring_Buffer[Ring_Buffer_Write_Index]:= Analogue_In; Ring_Buffer_Write_Index:= (Ring_Buffer_Write_Index+1)MOD Ring_Buffer_Size; IF Ring_Buffer_Write_Index = Ring_Buffer_Read_Index THEN RB_Loaded:= TRUE; Analogue_Out:=Ring_Buffer[Ring_Buffer_Read_Index]; Ring_Buffer_Read_Index:= (Ring_Buffer_Read_Index+1)MOD Ring_Buffer_Size; ELSE RB_Loaded:= False; END_IF; ONS_Trig:= TRUE; END_IF; IF NOT P_0_1s THEN ONS_Trig:= FALSE; END_IF;
T J SHARON Posted January 28, 2020 Author Report Posted January 28, 2020 (edited) thanks It seems like a code for FB. Could you please specify the input,output and internal variables and data type? I managed to identify some. EN (bool) ------>INPUT Run (Bool)------>INPUT Ring_Buffer_Initialize (bool) Ring_Buffer_Write_Index Ring_Buffer_Read_Index Ring_Buffer_Size Ring_Buffer_Read_Index RB-Loaded (bool)------>OUTPUT ONS_Trig (bool)------>OUTPUT Ring_Buffer[ ] ------>INTERNAL Analogue_In (UINT)------>INPUT Analogue_Out(UINT) ------>OUTPUT Appreciate all your help Regards, T J sharon Edited January 28, 2020 by T J SHARON
chelton Posted January 28, 2020 Report Posted January 28, 2020 (edited) Yes code for a FB EN (bool) ------>INPUT Run (Bool)------>INPUT Ring_Buffer_Initialize (bool) internal Ring_Buffer_Write_Index UINT internal Ring_Buffer_Read_Index UINT internal Ring_Buffer_Size UINT internal Ring_Buffer_Read_Index UINT internal RB-Loaded (bool)------>OUTPUT ONS_Trig (bool)------>internal Ring_Buffer[ ] UINT array [100] internal Analogue_In------>INPUT Analogue_Out ------>OUTPUT Time_Delay UINT INPUT I put a bool output (RB-Loaded) that indicates the buffer is full and the time delay is active. There is no value moved to the analogue output on start-up until the delay is reached. Edited January 28, 2020 by chelton missing variable
T J SHARON Posted January 29, 2020 Author Report Posted January 29, 2020 hi Chelton. Thanks a lot. Let me go thru and work it out.
T J SHARON Posted February 12, 2020 Author Report Posted February 12, 2020 HI, Its tested and working well. I have 8 Analogue inputs and will be using 8FBs, which need 800 words for Buffer_Ring array. But i don't have much free words in H-memory for Buffer_Ring array. Is there any way that i can assign Dmemory for the array? ( Assign "AT" in the Fb variable session not possible as this FB is using simultaneously for different Analogue inputs)
chelton Posted February 12, 2020 Report Posted February 12, 2020 Can you increase the FB memory allocation area? (PLC menu → Memory Allocation → Function Block/SFC Memory → Function Block/SFC Memory Allocation) Another option would be to change the array variable from internal to an in/out variable the just pass a DM array in as a parameter on each instance
T J SHARON Posted February 13, 2020 Author Report Posted February 13, 2020 Hi , I already extended FB areas of H-memory. Is there any issue if I change my over all FB memory allocation to d10000 ? Mean while I will try the feasibility of using IN-OUT method.
chelton Posted February 16, 2020 Report Posted February 16, 2020 I can not see any issue with changing the auto allocation memory area from H*** to D*** but I haven't had to do it on any projects. You would just need to ensure the memory area will remain free. D20000-D29599 and D30000-D31599 are for special I/O memory.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now