'=============================================================================== ' ' V E R S A T I L E E N G I N E S O U N D U N I T ' ' PROGRAM 1 OF 4 - SPEED DEMAND PROCESSING ' '=============================================================================== ' VERSION 2.0 14th October 2008 © A.F.Bond 2008 ' ' (ONLY FOR USE IN CONJUNCTION WITH v2.0 SOUND GENERATION MODULES) '=============================================================================== ' ' This module manipulates and scales the input signal from a radio control ' receiver prior to generating a 4Khz PWM signal whose duty cycle varies ' in a quasi logarithmic manner with the throttle position. A 25 element lookup ' table defines the control law to take account of the logarithmic nature of ' sound plus the sound generation PIC's fixed processing time overheads which ' occupy an increasingly disproportionate amount of the silent period as the ' engine speed increases. Overall this yields a linear sounding throttle ' response. A bi-directional throttle channel is assumed with neutral/stop based ' on receiving a 1.5mSec pulsewidth. Full ahead therefore relates to a 1mSec ' pulse and full astern to a 2mSec pulse. ' ' The code assumes a negative going pulse as the receiver signal has been ' inverted by an input buffer stage - included for compatibility with 2.4GHz ' sets which have insufficient output voltage swing to drive the PICAXE direct. ' ' The PWM signal from this module is low pass filtered and the dc level that ' results is used as the control voltage for the sound generation module. ' ' NOTE: In the description below be aware that PIN1, PIN2 etc are virtual ' pins and not to be confused with the device's phyical pins, which in PICAXE ' parlance are refered to as 'legs' ' '=============================================================================== 'VARIABLE DEFINITIONS symbol speed=w0 'assign variable to speed demand 'INITIALISATION setfreq m8 'set 8 Mhz operation to yield 5uSec resolution 'MAIN LOOP main: 'get throttle demand from receiver at "PIN3" and assign it to the variable 'speed' pulsin 3,0,speed 'note: 1 to 2 mSec will equate to values for 'speed' in the range 200 to 400 'now scale speed 0 to 100 in fwd and reverse if speed>300 then speed=speed-300 else speed=300-speed end if 'guard against over-range if speed>100 then speed=100 end if 'quantise speed into 25 values for lookup table speed=speed/4 'scale logaritmically for use by PWM command (duty cycle 0 to 100% = 0 to 800) lookup speed,(0,0,126,217,296,365,425,478,524,564,599,629,655,678,698,715,730,743,755,765,774,782,789,795,800),w1 'assert PWM train on "PIN2" pwmout 2,199,w1 goto main '=============================================================================== ' VERSION HISTORY '=============================================================================== 'v1.0 1st October 2008 'first release 'v2.0 14th October 2008 'Logarithmic lookup table function moved from sound generation modules into 'this module.This yielded spare program space in the sound generation modules 'and allowed a longer lookup table to be used without code execution time 'problems as this code only has to run at the transmitter frame rate rather 'than the engine revolution rate. The resulting throttle response of the 'overall system is thereby much smoother. '===============================================================================