Welcome Guest! To enable all features please Login or Register.
Options
Go to last post Go to first unread
HermanvdB  
#1 Posted : Sunday, March 05, 2017 10:36:33 AM(UTC)
HermanvdB

Rank: Newbie

Groups: BetaUser, Registered
Joined: 2/5/2017(UTC)
Posts: 5
Netherlands

Was thanked: 2 time(s) in 2 post(s)
I am trying to create short pulses to be used in a spot welder. Triggered by a microswitch to a digital input, I need a single digital pulse output. The pulse duration should be set by a potentiometer (analogue Input). The pulsed output I will use with TTL to switch the big currents (120 Ampere).
My trouble is that I can get a pulse generator made in Embrio with timer etc. but I am not able to create short enough pulses. It should be able to give me shortest 1 milliseconds and longest at least 200 ms fairly accurately.
In IDE I can create it fairly easily by just switching an output on, delay for one millisecond and then switch it off again but in Embrio, "delay(1);" does not work.

Any ideas?

I still have challenges to make my own defined Nodes work - some tips here will also help.
thanks 1 user thanked HermanvdB for this useful post.
sample@email.tst on 4/7/2024(UTC)
EmbrioAdmin  
#2 Posted : Sunday, March 05, 2017 11:17:05 AM(UTC)
EmbrioAdmin

Rank: Administration

Groups: Administrators
Joined: 12/11/2014(UTC)
Posts: 661

Thanks: 1 times
Was thanked: 109 time(s) in 104 post(s)
Yes a timer won't work for that. The timer only updates X times per second, based on the refresh rate in the bottom right corner of the editor. So even at the fastest refresh rate you'll get a minimum pulse of about 8 milliseconds, and the pulse could only be in increments of about 8 ms.

You can use delay in a custom Arduino node. Paste the below xml into a node screen, it takes an analog input and transforms that into a pulse between 1 and 200 milliseconds on pin 3.

Note that this isn't great for Embrio, as when the pulse is running, none of the other nodes in the program will execute until the pulse is done. Depending on what else you have going on in your project this may or may not be ok.

Basically Embrio fakes parallelism by spreading each node's code out on a time line. For each node, the maximum amount of time it will take to execute is reserved. When the node executes, it's actual execution time is calculated, and any unused time is delayed. This way the nodes in the program all execute x times per second with very high accuracy.

The problem here is that the timing program will find that your node takes a long time to run, and will reserve that time. So even when the pulse isn't running high, it will still delay for about 200 milliseconds. You could of course have your node run only 2 or 4 times per second if this is ok. But note you won't really be able to have other agents running faster.

Currently there isn't an easy way to override the measured timing of a node in the application itself, but there are 2 ways you can get around this.

First, in the folder where Embrio has files (something like /Users/YourUserName/AppData/Roaming/Embrio) is a file called timingdata.txt. After you run a timing program for your node, you can open that file, find it's timing data, and change the MeasuredMicroseconds from the high number to something very low, or maybe 1000 for 1 millisecond.

Or in that same folder, in the ArduinoCompile folder you can open the ArduinoCompile.ino file. Down in the loop function you will see something like "ProcessTimedFunction(Group_2_1, 124197);". Change that high number again to 1000.

Now when the node executes, it will take as long as it takes to execute depending on how long the pulse is, then continue with the rest of the program without waiting for the unused time. So say your agent runs at 32 x per second, with a low pulse rate everything will run fine. When the pulse rate gets longer, like 200 milliseconds, then your potentiometer reading will only happen a few times per second instead of 32.

What your are trying to do kind of hits a limitation in Embrio. It will probably work, but depending on what else is happening in your program, it might not work very well. Other than a knob setting a pulse width, what else is happening in your project?

Sorry for the long post, I hope it makes sense.

<EmbrioCopy>
<Version>1.3.6.0</Version>
<Nodes>
<Node>
<UniqueID>b528ac1d-5d7a-4c48-b724-50455710d264</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerCustomArduinoNode</AssemblyType>
<NodeType>Custom Arduino Node</NodeType>
<UserDefinedName></UserDefinedName>
<Description>A node that lets you write any Arduino code to interact with the Arduino hardware. Can be both an input and output.</Description>
<NodeColor>144,183,227,255</NodeColor>
<X>316.242857142857</X>
<Y>28.6805194805197</Y>
<Width>747</Width>
<IncludeCode>int pinNumber = 3;</IncludeCode>
<DeclerationCode></DeclerationCode>
<SetupCode></SetupCode>
<ImageName>arduino.png</ImageName>
<InfoURL></InfoURL>
<IsOpen>True</IsOpen>
<EditWidth>360</EditWidth>
<CodeDefinitions>
<CodeDefinition>
<UpdateCondition>InputChange</UpdateCondition>
<Code>digitalWrite(pinNumber, HIGH);
// Use a built in Embrio function. Pass it a number of microseconds to delay.
// It first uses delay() to delay the milliseconds, then delayMicros for the remaining microseconds.
// Transform the input activation from 1 to 200 milliseconds
EmbrioWait(transform(Input_Activation, 0.0, 1.0, 1000, 200000));
digitalWrite(pinNumber, LOW);</Code>
<UniqueID>69c45ca7-a63d-479c-bb2e-8487a1afd8e0</UniqueID>
<Inputs>
<Input>54335ea2-d9be-47bf-845f-e9e1cc8e6875</Input>
</Inputs>
</CodeDefinition>
</CodeDefinitions>
<Inputs>
<Input>
<UniqueID>54335ea2-d9be-47bf-845f-e9e1cc8e6875</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>False</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>True</IsUserAdded>
<ConnectedOutputs>
<Output>c313d3e3-25a6-4952-96fa-d71fe0d3a735</Output>
</ConnectedOutputs>
<BlendMode>Add</BlendMode>
<DisconnectedValue>0</DisconnectedValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Input>
</Inputs>
<Outputs></Outputs>
</Node>
<Node>
<UniqueID>fe79ca01-d815-4948-990f-c2ffa00f10ee</UniqueID>
<AssemblyType>Embrio.NodeEngine.AgentController.Nodes.AgentControllerInputNode</AssemblyType>
<NodeType>Controller Input</NodeType>
<UserDefinedName></UserDefinedName>
<Description>Reads an input from an analog or digital Arduino pin.</Description>
<NodeColor>144,183,227,255</NodeColor>
<X>0</X>
<Y>0</Y>
<Width>260</Width>
<PinType>Analog</PinType>
<RangeMin>0</RangeMin>
<RangeMax>1023</RangeMax>
<Pin>A2</Pin>
<UsePullup>False</UsePullup>
<Inputs>
<Input>
<UniqueID>d2ddae12-5d26-45de-ba27-3986d1bec116</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Design Time Activation</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>True</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeInput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>False</IsUserAdded>
<ConnectedOutputs></ConnectedOutputs>
<BlendMode>Add</BlendMode>
<DisconnectedValue>0</DisconnectedValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Input>
</Inputs>
<Outputs>
<Output>
<UniqueID>c313d3e3-25a6-4952-96fa-d71fe0d3a735</UniqueID>
<DefinitionID>00000000-0000-0000-0000-000000000000</DefinitionID>
<DefaultName>Activation</DefaultName>
<CustomName></CustomName>
<IsDisplayed>True</IsDisplayed>
<IsNative>True</IsNative>
<TypeName>Numeric</TypeName>
<IsOutsideConnection>False</IsOutsideConnection>
<IOType>Embrio.NodeEngine.NodeIO.NumericNodeOutput</IOType>
<ShowGraph>False</ShowGraph>
<LinkedIOID>00000000-0000-0000-0000-000000000000</LinkedIOID>
<IsUserAdded>False</IsUserAdded>
<MinValue>0</MinValue>
<MaxValue>1</MaxValue>
<UseNegativeRange>False</UseNegativeRange>
<CanUseNegativeRange>True</CanUseNegativeRange>
</Output>
</Outputs>
</Node>
</Nodes>
</EmbrioCopy>
thanks 1 user thanked EmbrioAdmin for this useful post.
sample@email.tst on 4/7/2024(UTC)
HermanvdB  
#3 Posted : Thursday, March 09, 2017 1:07:39 AM(UTC)
HermanvdB

Rank: Newbie

Groups: BetaUser, Registered
Joined: 2/5/2017(UTC)
Posts: 5
Netherlands

Was thanked: 2 time(s) in 2 post(s)
Thank you very much! Very detailed answer - so now I also understand better how Embrio works and how I can work with it! Much appreciated.

The rest of the project is not time critical and even with 500 ms delay will not impact the overall project.
thanks 1 user thanked HermanvdB for this useful post.
sample@email.tst on 4/7/2024(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error