|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Did you know...
|
Serial Wombat Analog Follow Channel ModeThe Serial Wombat Analog Follow Channel mode allows the Serial Wombat to output a PWM whose duty cycle is proportional to the public data of another pin. This allows the user to do things like control a motor speed via PWM on command of a rotary encoder, or potentiometer. Instead of a PWM, an offboard D/A or digital potentiometer can also be used.
Simple Message format:
Example:Configure channel 20 to generate a PWM proportional to the voltage being measured by pin 2. 200 20 19 2 0x55 0x55 0x55 0x55 ; Set pin 20 PWM Follow Mode
; Controlled by pin 2
Advanced Message format:Messages 201 and 202 are meant to be used together. They allow PWM Follow mode to scale and offset the data provided by another pin. Message 201 should be immediately followed by message 202. output value = pin * (Scalar / 256) + offset The output values below 0 will be set to 0. Output values above 65535 will be set to 65535.
Example:Configure channel 20 to generate a PWM proportional to the voltage being measured by pin 2. Sample pin 2 every 20 frames. Convert the output by multiplying it by 3.75, and subtracting off 500. 201 20 19 0 20 0x03C0 0x55 ; Set pin 20 PWM Follow Mode
; Sample every 20 frames
; Multiply by 3.75 (0x03C0 / 256)
202 20 19 2 0xFE0C 0x55 0x55 ; Set pin 20 PWM Follow Mode
; Follow pin 2
; Subtract 500 from multiply result
; (two's complement of 500 is 0xFE0C)
Pin Mode Source CodeThe following code is what creates the pin mode for this function inside of the Wombat. You don't need to know this to use the pin mode, but some people find it interesting. See the SDK for some insight into how pin modes work. Hold your mouse over various words and variables for definitions. #include "types.h"#include "utilities.h" #include "global_data.h" #pragma code APPLICATION #pragma romdata APPLICATION_DATA void init_pwm_follow_direct() { uint16 temp16; tp.pwm_follow_direct.commandpin = rxbuffer[3]; temp16 = get_buffer(tp.pwm_follow_direct.commandpin); tp.pwm_follow_direct.offset = 0; tp.pwm_follow_direct.scalar = 256; tp.generic.buffer = 0 ; tp.pwm_follow_direct.sampletime = 0; vset_pwm(temp16); } void init_pwm_follow_direct1() { tp.pwm_follow_direct.commandpin = 255; tp.pwm_follow_direct.sampletime = RXBUFFER16(3); tp.pwm_follow_direct.scalar = RXBUFFER16(5); } void init_pwm_follow_direct2() { //TODO not tested tp.generic.buffer = 0; tp.pwm_follow_direct.commandpin = rxbuffer[3]; ASSIGN_RXBUFFER16(tp.pwm_follow_direct.offset,4); } void update_pwm_follow_direct(void) { if (tp.pwm_follow_direct.commandpin == 255) { return; } if (tp.generic.buffer) { --tp.generic.buffer; } else { tp.generic.buffer = tp.pwm_follow_direct.sampletime; tp2.pwm_follow_direct.temp32.u = get_buffer(tp.pwm_follow_direct.commandpin); tp2.pwm_follow_direct.temp32.u *= tp.pwm_follow_direct.scalar; tp2.pwm_follow_direct.temp32.u >>=8; tp2.pwm_follow_direct.stemp32 = tp2.pwm_follow_direct.temp32.u; tp2.pwm_follow_direct.stemp32 += tp.pwm_follow_direct.offset; if (tp2.pwm_follow_direct.stemp32 > 65535) { vset_pwm(65535); } else if (tp2.pwm_follow_direct.stemp32 < 0) { vset_pwm(0); } else { vset_pwm ((uint16)tp2.pwm_follow_direct.stemp32); } } update_pwm(); } |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright Wombat Interface Products, 2005-2008. All Rights Reserved.