Shop OBEX P1 Docs P2 Docs Learn Events
VirtualPeripheral for PWM Input? — Parallax Forums

VirtualPeripheral for PWM Input?

WiryWiry Posts: 1
edited 2005-11-28 17:38 in General Discussion
I'm considering using the Javelin for reading two PWM signals of an X-Y-acceleration-sensor and controlling 2 servos. It seems easy to control the servos by instantiating 2 PWMs as PWMs are VirtualPeripherals and run in teh background. Unfortunately I didn't find a subclass of VirtualPeripheral for reading PWM.
Is it possible to extend VirtualPeripheral and implement a standard-method which is run in the background?
The API docs don't say how to build custom VirtualPeripherals.

cheers
Gunther

Comments

  • Rich MaysRich Mays Posts: 4
    edited 2005-11-28 16:31
    I would also like an answer to this person's question. Is there a way to derive your own VP from the base class?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-28 17:38
    You can not create new VP's that run in the background.

    All you can do is use the existent ones. You can however write

    your code as state machines, that are called frequently from the mainloop.

    If a state machine must wait for some event, it tests for that·event and returns

    immediately if that event has not occured. To a certain level that gives you the

    same behaviour as background tasks.

    Pwm input could be done by testing for edges and counting the time between

    those edges.·Would work only for·a low frequency pwm signal though.

    regards peter
Sign In or Register to comment.