Limit Switch for PCM

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?

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.

Thanks That’s got me on the right track.

Nice to hear from someone who talks in EasyC

Regards

GeorgeC

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 ) ;



Many thanks for taking the time to post the code

GeorgeC