Sign in to follow this  
Followers 0
T J SHARON

Add Delay to to the Analogue out

12 posts in this topic

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?

 

Untitled.png

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

hi Chelton,

Mostly 1-5 seconds delay.  

Do you have any sample prgm?

 

Share this post


Link to post
Share on other sites

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;


	

 

Share this post


Link to post
Share on other sites

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 by T J SHARON

Share this post


Link to post
Share on other sites

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 by chelton
missing variable

Share this post


Link to post
Share on other sites

hi Chelton.

Thanks a lot.

Let me go thru and work it out.

Share this post


Link to post
Share on other sites

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)

 

 

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0