Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Limit Switch for PCM (http://www.chiefdelphi.com/forums/showthread.php?t=53932)

GeorgeC 11-02-2007 17:43

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?

mluckham 11-02-2007 23:02

Re: Limit Switch for PCM
 
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

Re: Limit Switch for PCM
 
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

Re: Limit Switch for PCM
 
Try this
Code:

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.

Code:

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

Re: Limit Switch for PCM
 
Many thanks for taking the time to post the code

GeorgeC


All times are GMT -5. The time now is 04:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi