Serial Wombat
a general-purpose digital interface device for hobbyists, engineers and students

 


Home
Overview
Protocol
Documentation
Channel Modes
Direct Control
Controlled Pin
Raw A/D
A/D Averaging
A/D 1st Order Filtering
Matrix Keypad
Servo Control
Analog Direct
Analog Follow
Rotary Encoder
Debouncing
Counter
Hysteresis
Morse Code
Pulse
Unipolar Stepper
LCD Driver 1
LCD Driver 2
HW Pulse Meas.
2D Lookup
SPI Master
HD44780 Generic
Remote Control
DataLogger
Min-Max
Public Data
Timed IO
Getting Started
Connectivity
Pin Mode SDK Beta
Sample Projects
Downloads
Contact Us
Purchase
Forum

Did you know...

 

Serial Wombat Analog Follow Channel Mode

The 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:

Data Sent to the Wombat: 200 Pin # 19 Pin To Follow 0x55 0x55 0x55 0x55
Meaning: Configure Pin message Pin Number to be set to PWM output PWM Follow Mode The Pin Number whose data should be used to indicate PWM duty cycle Unused Unused Unused Unused
This message is echoed back by the Wombat.

 

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.

 

 

Data Sent to the Wombat: 201 Pin # 19 Sample Period High Byte Sample Period Low Byte Scalar Whole Part Scalar Fractional Part 0x55
Meaning: Configure Pin First Advanced message Pin Number to be set to PWM output PWM Follow Mode A 16-bit number indicating the number of frames between reads of the commanding pin This 16 bit number is an improper fraction in terms of 256ths. For instance, a value of 256 (0x0100) would be a scalar of 256/256, or 1. A value of 1024 (0x0400) would be a scalar of 4. A value of 384(0x0180) would be a scalar of 1.5. Unused
This message is echoed back by the Wombat.

 

Data Sent to the Wombat: 202 Pin # 19 Pin to follow Offset High Byte Offset Low Byte 0x55 0x55
Meaning: Configure Pin Second Advanced message Pin Number to be set to PWM output PWM Follow Mode The Pin Number whose data should be used to indicate PWM duty cycle This 2's complement, signed 16-bit number is added to the result of the multiplication to determine the final output PWM. unused Unused
This message is echoed back by the Wombat.

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 Code

The 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.