OpenVex  0.5.0
Functions
Motor and Servo Control

Functions

signed char pwm_write (unsigned char port, signed char val)
 
signed char pwm_read (unsigned char port)
 

Detailed Description

Function Documentation

◆ pwm_read()

signed char pwm_read ( unsigned char  port)

Read the PWM value for the specified port from the txdata structure.

Parameters
portPWM port to read back.
Returns
Last value written to port using pwm_write().

NOTE: This does not necessarily indicate the current power setting on the motor/servo. It simply reports the latest value written to this port via pwm_write(). See pwm_write() for details.

◆ pwm_write()

signed char pwm_write ( unsigned char  port,
signed char  val 
)

Write a PWM value to the specified port.

Parameters
portPWM port to write.
valPWM power/position values from -127 to 127.
Returns
OV_OK on success, OV_BAD_PARAM if the port or PWM value are invalid.

For motors, 0 means stop. For servos, 0 is the center position.

Changes made through this function will not take effect until controller_submit_data() is called.

On PIC-based controllers:

It will then take between 0 and 18.5 ms before the submitted data reaches the master processor which controls the motors.

To alter a motor/servo setting, the following must occur:

1. call pwm_write().  This only alters the next packet to be submitted.\n
2. call controller_submit_data().  This queues the altered packet for
sending to the master processor.\n
3. The master processor interrupts the user processor every
18.5 ms to send sample data from the RC unit and retrieve
the latest data queued by controller_submit_data().

Hence, motor setting will change between 0 and 18.5 ms after
your code calls controller_submit_data().