Ticket 8 discussion
Wharfie
tickets
(Thread)
Ticket 8 discussion
Last updated: 2018-02-24
Ticket 2 discussion
Wharfie
tickets
(Thread)
Ticket 2 discussion
Last updated: 2018-03-31
(no subject)
Wharfie
tickets
(Thread)
Last updated: 2020-08-03
Home (version 11) discussion
Wharfie
wiki
(Thread)
Home (version 11) discussion
Last updated: 2019-11-19
(no subject)
Wharfie
tickets
(Thread)
Last updated: 2020-08-04
CODESYS (version 1) discussion
Wharfie
wiki
(Thread)
CODESYS (version 1) discussion
Last updated: 2018-09-14
(no subject)
Wharfie
tickets
(Thread)
Last updated: 2019-04-03
Home (version 7) discussion
Wharfie
wiki
(Thread)
Home (version 7) discussion
Last updated: 2019-01-06
Command Reference (version 16) discussion
Wharfie
wiki
(Thread)
Command Reference (version 16) discussion
Last updated: 2020-03-07
IndexMain (version 1) discussion
Wharfie
wiki
(Thread)
IndexMain (version 1) discussion
Last updated: 2018-09-06
Raspberry Pi (version 1) discussion
Wharfie
wiki
(Thread)
Raspberry Pi (version 1) discussion
Last updated: 2018-02-14
Home (version 14) discussion
Wharfie
wiki
(Thread)
Home (version 14) discussion
Last updated: 2020-03-07
Ticket 10 discussion
Wharfie
tickets
(Thread)
Ticket 10 discussion
Last updated: 2018-02-24
(no subject)
Wharfie
wiki
(Thread)
Last updated: 2018-02-25
(no subject)
Wharfie
wiki
(Thread)
Last updated: 2018-02-14
(no subject)
Wharfie
wiki
(Thread)
Last updated: 2018-02-14
Quickstart Tutorial (version 1) discussion
Wharfie
wiki
(Thread)
Quickstart Tutorial (version 1) discussion
Last updated: 2018-09-10
(no subject)
Wharfie
tickets
(Thread)
Last updated: 2019-04-05
(no subject)
Wharfie
wiki
(Thread)
Last updated: 2018-02-14
CODESYS (version 2) discussion
Wharfie
wiki
(Thread)
CODESYS (version 2) discussion
Last updated: 2018-09-03
gpio-mod: ./trunk/gpiomod/GPIOMods.library.md
Bash
bash
(Bash)
---
This FB can be used to sample analog data by using two
GPIO Pins:
- one digital input
- one digital output
There are also other circuits out there, which only
need one single GPIO. But they have the clear disadvantage
that they need to reconfigure this GPIO constantly. Additionally
you have to take care about the VRef, which you are using, as it
will be pulled to ground by the GPIO acting as an output.
You need to take care to not destroy your board with that. In the
Circuit, recommended here, it is to my understanding much safer,
as we simply use the digital output as our VRef. Therefore we can
easily and safely pull it to ground.
Wirering::
Digital Output (VRef)
v
R1 (2,2kOhm)
v
Transistor / Poti / LDR / ...
|---> Input Pin
C1 (1uF)
v
GND
Scheduling:
The accuracy of the measurement relies in some aspects on the scheduling.
So it is recommended to schedule the task, which is driving this FB, as
frequent as possible. It is generally OK to combine this FB with the SoftPWM.
Just the sampling accuracy will slightly vary, depending on the frequency
of the PWM.
~~~ST
FUNCTION_BLOCK SoftAIN
VAR_INPUT
xInput: BOOL;
END_VAR
VAR_OUTPUT
xOutput: BOOL;
rVal: REAL;
END_VAR
VAR
xSampling: BOOL;
tStart: SYSTIME;
tCurrent: SYSTIME;
xInit: BOOL;
END_VAR
VAR
ctDischarge: SYSTIME;
crScale: REAL;
END_VAR
~~~
~~~ST
SysTimeGetUs(tCurrent);
IF xInit THEN
xInit := FALSE;
tStart := tCurrent;
END_IF
IF xSampling THEN
// Reading the sampling pin, and measure the time
IF xInput THEN
/// capacitor is full, stop sampling, and discharge
xSampling := FALSE;
rVal := LWORD_TO_REAL(tCurrent - tStart) * crScale;
tStart := tCurrent;
END_IF
ELSE
// Discharge the capacitor
IF tCurrent - tStart > ctDischarge THEN
// start sampling
tStart := tCurrent;
xOutput := TRUE;
END_IF
END_IF
~~~
---
This FB can be used to implement a Soft PWM, based
on the scheduler of a Linux system.
Note, that this function block should be used in a
a high priority task. The interval of the task will
constantly change.
~~~ST
FUNCTION_BLOCK SoftPWM
VAR_INPUT
dwFrequ: DWORD;
rDutyCycle: REAL;
END_VAR
VAR_OUTPUT
xPWM: BOOL;
END_VAR
VAR
hTask: SysTask.RTS_IEC_HANDLE;
ulInterval: DWORD;
END_VAR
VAR
cMinInterval: DWORD;
END_VAR
~~~
~~~ST
(* If current task is not, yet, determined, get it *)
IF hTask = SysTask.RTS_INVALID_HANDLE THEN
SysTask.SysTaskGetCurrent(ADR(hTask));
END_IF
(* if task is determined, adjust next cycle *)
IF hTask <> SysTask.RTS_INVALID_HANDLE THEN
IF xPWM THEN
ulInterval := LREAL_TO_DWORD((LREAL#1000000 / DWORD_TO_LREAL(dwFrequ)) * rDutyCycle);
ELSE
ulInterval := LREAL_TO_DWORD((LREAL#1000000 / DWORD_TO_LREAL(dwFrequ)) * (LREAL#1 - rDutyCycle));
END_IF
(* if we are near the boundary values, we snap the output either to TRUE or FALSE *)
IF ulInterval < cMinInterval THEN
SysTask.SysTaskSetInterval(hTask, DWORD#1000000 / dwFrequ);
ELSE
SysTask.SysTaskSetInterval(hTask, ulInterval);
xPWM := NOT xPWM;
END_IF
END_IF
~~~
Last updated: 2018-09-18
gpio-mod: ./trunk/gpiomod/license.txt
Bash
bash
(Bash)
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Last updated: 2018-08-22
gpio-mod: ./trunk/gpiomod/package.manifest
Bash
bash
(Bash)
<?xml version="1.0" encoding="ISO-8859-1"?>
<Package>
<Strings>
<String Id="GeneralName">
<Neutral>GPIO Mods</Neutral>
</String>
<String Id="GeneralVendor">
<Neutral>Open Source Software</Neutral>
</String>
<String Id="GeneralCopyright">
<Neutral>all rights reserved</Neutral>
</String>
<String Id="GeneralDescription">
<Neutral></Neutral>
</String>
<String Id="license">
<Neutral>LICENSE.TXT</Neutral>
</String>
<String Id="TargetDir">
<Neutral>Target directory</Neutral>
</String>
<String Id="TargetDirDescription">
<Neutral>The target directory where the projects are saved.</Neutral>
</String>
</Strings>
<General>
<Id>{3d79667a-a648-11e8-a9fd-e5f6498540b8}</Id>
<Version>1.0.0.3</Version>
<Name>$GeneralName</Name>
<Vendor>$GeneralVendor</Vendor>
<Copyright>$GeneralCopyright</Copyright>
<Description>$GeneralDescription</Description>
<LicenseAgreement>$license</LicenseAgreement>
<RequiredInstallerVersion>3.5.10.0</RequiredInstallerVersion>
</General>
<TargetDirectoryDefinitions>
<TargetDirectoryDefinition>
<Id>1</Id>
<Name>$TargetDir</Name>
<Description>$TargetDirDescription</Description>
<PromptUser>True</PromptUser>
<DefaultValue>%USERPROFILE%\CODESYS Projects\</DefaultValue>
</TargetDirectoryDefinition>
</TargetDirectoryDefinitions>
<Components>
<Component>
<General>
<Id>1</Id>
<Name>Default</Name>
<Description>Default Package</Description>
<Selectable>false</Selectable>
<SelectedByDefault>true</SelectedByDefault>
</General>
<Dependencies>
</Dependencies>
<Items>
<Library>
<Path>GPIOMods.library</Path>
</Library>
</Items>
</Component>
</Components>
</Package>
Last updated: 2018-09-18
wharfie: Artifact 5a91d5852a9858000a44ec3d
Wharfie
tickets
(Bin)
Last updated: 2018-02-24
wharfie: Artifact 5a91d5852a9858000a44ec3e
Wharfie
tickets
(Bin)
Last updated: 2018-02-24