# l298-jogger6.hal
# 2007 05 02 this has encoder input
#
# 2007 05 02 tjp only chg the output pin9 to outputpin14 and chg port invocation to input ( default, just dont say 'out' )
# add the 2nd slow thread for update
# chjg name to 'pdmthrd' which will be fastest but is not the 'fast' thrd used for quick updates
# pdmthrd is sized for best response at low speed ( tho is coggy )
# make a new thrd 'fast' for thing to do often
#
# modified to use pport at 9c00 cfgd as output, and pins used are p2 & p? uz thats hooked up on my 'trainer'
# this file is PDM Pulse Density Modulation, and works a lot better than PWM for my low speed control needs
# PDM has smaller deadband for me ( i can get closer ot 0 w/o stalling motor and withmroe torque)
# PDM has a fuller range of values (more pot positions actually make a difference )
# this file is PDM by a mistake... i didnt set ANY of the pwmgen params!
# PDM is just a stock pulse that happens more or less often... like a frequency generated with a fixed 1 shot
# what determines the width if the 1 shot?
# (09:09:54) jepler: tomp: the pdm period is determined by the frequency of the thread where make-pulses is executed
# (09:10:10) jepler: tomp: so if it's in a 50us base-period, then the active/inactive periods will be around 50us +- latency
#
# 2007 05 01 works! i can see the led dim & brighten & the appropo led lights with pos or neg value
# 2007 05 01 add hdwr pin out for enable to pport p4
# hal file for pport that jogs xslide thru pwmgen & l298 pcb
# it 'calls' an xml file that describes the gui for pyvcp
# file is "l298jogrgui.xml,
# has knob to select D% ( -1.0 to +1.0 )
# has btn to enable pwm output
# has LED to indicate enable/disable
#
# pport at 9c00 from pci card
# this uses HAL and PyVCP only, no EMC
# --------------------------COMPONENTS---------------------------------------------------
# parport driver as input (default)
loadrt hal_parport cfg="9c00"
# pwmgen of type 2 (up / down mode ) to drive the l298 h bridge ( use PDM )
loadrt pwmgen output_type=2
# hal-encoder, no home swx, just force the 0 reference posn with a btn ( oh add an input for the btn... got one ready :)
loadrt encoder num_chan=1
# pyvcp gui
loadusr -Wn l298jogr6 pyvcp -c l298jogr6 l298jogrgui6.xml
# --------------------------THREADS-------------------------------------------------------
# rt threads, period in nS
loadrt threads name1=pdmthrd period1=500000 name2=slow period2=1000000 name3=fast period3=20000
# --------------------------PARAMETERS---------------------------------------------------
setp encoder.0.x4-mode 1
setp encoder.0.position-scale 1000
# --------------------------FUNCTIONS----------------------------------------------------
# add rt f(x) to threads
addf parport.0.read fast
addf encoder.update-counters fast
addf parport.0.write slow
addf pwmgen.update slow
addf encoder.capture-position slow
addf pwmgen.make-pulses pdmthrd
# --------------------------CONNECTIONS--------------------------------------------------
# connect gui knob output to the pwmgen input
newsig Xvel-cmd float
net Xvel-cmd pwmgen.0.value l298jogr6.dutyPsycho
# connect gui enable swx to this 'amp'
newsig Xenable bit
net Xenable pwmgen.0.enable parport.0.pin-14-out l298jogr6.pwmGenEna l298jogr6.enaNdk8r
# connect pwmgen up/dn pins to parport pins
# pwmgen-up to pport-p02 so i can use the led on my trainer to see pwm on led
newsig pwmgenUpSgl bit
net pwmgenUpSgl pwmgen.0.up parport.0.pin-16-out
# pwmgen-down to pport-p03 so i can use the led on my trainer to see pwm on led
newsig pwmgenDnSgl bit
net pwmgenDnSgl pwmgen.0.down parport.0.pin-17-out
# connect phys encoder to pport and hal-encoder
newsig XEncA bit
net XEncA encoder.0.phase-A parport.0.pin-12-in
newsig XEncB bit
net XEncB encoder.0.phase-B parport.0.pin-13-in
# connect hdwr reset btn and gui reset btn to the hal-encoder to allow setting '0'
# NB later allow use of 'probe' to auto set 0!
newsig XEncRst bit
#net XEncRst encoder.0.reset parport.0.pin-11-in-not l298jogr6.guiSetRef
net XEncRst encoder.0.reset l298jogr6.guiSetRef
# connect the scaled encoder position to the gui DRO
newsig valu4dro float
net valu4dro encoder.0.position l298jogr6.droDisplayValu
start
waitusr l298jogr6