Created
May 5, 2012 13:28
-
-
Save ah01/2602423 to your computer and use it in GitHub Desktop.
LDmicro, Arduino and PWM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LDmicro export text | |
for 'ANSI C Code', 4.000000 MHz crystal, 10.0 ms cycle time | |
LADDER DIAGRAM: | |
|| || | |
|| ; Interier Light || | |
1 || ; When you press the button (d2) led (pwm) will turn on and after some time (5 sec) fade out. || | |
|| || | |
|| || | |
|| || | |
|| || | |
|| Xd2 Ron || | |
2 ||-------] [------+---------------------------------------------------------------------------(S)-------|| | |
|| | || | |
|| | {pwm := } || | |
|| +---------------------------------------------------------------------{ 255 MOV}--|| | |
|| || | |
|| || | |
|| || | |
|| || | |
|| Ron Ton Rfade || | |
3 ||-------] [---------[TON 5.000 s]------------------------------------------------------------( )-------|| | |
|| || | |
|| || | |
|| || | |
|| || | |
|| Rfade Rstep Tstep {SUB pwm :=} || | |
4 ||-------] [--------------]/[--------[TON 100.0 ms]-+---------------------------{ pwm - 8 }----------|| | |
|| | || | |
|| | Rstep || | |
|| +-----------------------------------------( )-------|| | |
|| || | |
|| || | |
|| || | |
|| || | |
|| Rfade [pwm <=] Ron || | |
5 ||-------] [-----------[ 0 ]----+----------------------------------------------------------(R)-------|| | |
|| | || | |
|| | {pwm := } || | |
|| +----------------------------------------------------{ 0 MOV}--|| | |
|| || | |
|| || | |
|| || | |
||------[END]-------------------------------------------------------------------------------------------|| | |
|| || | |
|| || | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ladder.h" | |
/* Plc cycle interval, set this according to LDmicro settings. (micro sec.) */ | |
#define PLC_INTERVAL 10000 | |
void setup() | |
{ | |
PlcSetup(); | |
} | |
void loop() | |
{ | |
if (IsPlcInterval()) | |
{ | |
PlcCycle(); | |
// set PWM output | |
analogWrite(3, U_i_pwm); | |
} | |
} | |
/* Plc Cycle timing function. */ | |
boolean IsPlcInterval() | |
{ | |
static unsigned long last_run; | |
if (micros() - last_run >= PLC_INTERVAL) | |
{ | |
last_run = micros(); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment