Log in

View Full Version : Limit Switch for PCM


GeorgeC
11-02-2007, 17:43
Can anyone help with an easyC mindbender?

I've used all of my available spike relay controllers and programming limit switches using them in easyC was straightforward.

Now i need to control a motor using PWM and a limit switch but I can't think of how to code in a limit switch.

What I want to do is program something like if limit==0 then PWM1 ==<127. However in easyC I can't see the actual variable to assign my values to.

I guess that PWM outputs are to program drive motors which don't usually need limit switches.

Anyone got any ideas?

mluckham
11-02-2007, 23:02
Create your own variable to hold the value of the limit switch (connected to a Digital Input, of course).

Then you can do something like:

switchstate = DigitalInput(10); // read DI 10 limit switch
if (switchstate == 1)
pwm = 127;
else
pwm = something else;

PWMOutput(2, pwm); // output pwm value to PWM2


You are correct, the EasyC functions provided for PWM output do not include support for limit switches.

GeorgeC
12-02-2007, 14:08
Thanks That's got me on the right track.

Nice to hear from someone who talks in EasyC

Regards

GeorgeC

Kingofl337
12-02-2007, 15:06
Try this

if ( GetDigitalInput ( 1 ) && Input > 127 )
{
Input = 127 ;
}
else if ( GetDigitalInput ( 2 ) && Input < 127 )
{
Input = 127 ;
}


If you are using an OI to PWM Block

Then delete it and add this.


Input = GetOIAInput ( 1 , 1 ) ;
if ( GetDigitalInput ( 1 ) && Input > 127 )
{
Input = 127 ;
}
else if ( GetDigitalInput ( 2 ) && Input < 127 )
{
Input = 127 ;
}
SetPWM ( 1 , Input ) ;

GeorgeC
16-02-2007, 13:21
Many thanks for taking the time to post the code

GeorgeC