PINSTART(PinField, Mode, Xval, Yval) Syntax question
Bob Drury
Posts: 236
in Propeller 2
PINSTART performs :
DIR=0, then WRPIN=Mode, WXPIN=Xval, WYPIN=Yval, then DIR=1
if you run the following instead of PINSTART:
pinclear(pinfield)
wrpin(pinfield,mode)
wxpin(pinfield,xval)
wypin(pinfield,yval)
What will set DIR = 1 . The following code seems to work, but where is DIR = 1 set? or does it not matter?
Regards and Thanks
Bob (WRD)
var long ap ' analog pin long urlo ' user output range, low long urhi ' user output range, high long aout ' analog out value (in user range) long setup ' true when pin setup long codetest ' mode loaded CON _clkfreq = 200_000_000 ' set system clock delay = _clkfreq / 1_000 CON pinfield = 25 'only pin25 set analogout mode = P_DAC_DITHER_PWM | P_DAC_990R_3V | P_OE '3.3v analog out xval = 256 '256 max unsigned 16 bit $FFFF yval = 0 ' 0 min unsigned CON analogOutPinP25 = 25 { 0 } 'P25 20k Load Resistor analogOutP25_LO = 0 'Lo range analog out ' scaled range for pot analogOutP25_HI = 3300 'Hi range analog out '16 bit dac ou 0-256 VAR long analogOutValueP25 PUB main() |t , ReturnHexValueP25 start(analogOutPinP25,analogOutP25_LO, analogOutP25_HI) 'call analog.start(Pin,lo,Hi) repeat repeat analogOutValueP25 from 0 to 3300 ReturnHexValueP25 := write(analogOutValueP25) debug(udec(analogOutValueP25)) waitms(50) pub start(pin, lo, hi) '' Setup pin for analog output '' -- lo and hi define user range (e.g. 0 and 3300 for millivolts) stop() pin &= $3F ' limit to one pin wrpin(pinfield,mode) 'anlaog out enabled wxpin(pinfield,xval) 'max val 256 wypin(pinfield,yval) 'min val 0 codetest := P_DAC_DITHER_PWM | P_DAC_990R_3V | P_OE waitms(1000) longmove(@ap, @pin, 3) ' save setup setup := true pub stop() '' Disable analog smart pin if previously configured if (setup) pinclear(ap) ' disable smart pin longfill(@ap, 0, 5) ' mark disabled pub write(value) : result '' Convert value to 16-bit level and write to DAC '' -- value is in user-defined lo..hi range aout := urlo #> value <# urhi ' constrain to user range result := (aout - urlo) * $FFFF / (urhi - urlo) + urlo ' convert to 16-bit dac value wypin(ap, result) pub level() : result '' Return last user level written to analog output return aout
Comments
pinl(pinfield)
would do it. Another option is inlined assembly.The code I don't believe sets DIR = 1 , but it still outputs the correct analogue out signal as measured by my fluke meter.
Doesn't really matter but something I noticed.
Regards and Thanks
Bob (WRD)
The P2 documentation snippet below for the DAC PWM smart pin mode mentions that Y[15:0] is still captured even with DIR=0. Presumably this is why it appears to be working even without setting DIR=1 after you initialize this mode. Although the IN pin data bit is not functional in this state, so synchronous updates would not work, only async updates would work when you write the data, which could affect the quality of your dithered DAC output.
DAC 16-Bit With PWM dither (%00011 and DAC_MODE)
Oh, I misunderstood the question ... The DAC is driven because of P_OE. The smartpin most likely isn't dithering without DIR set. It'll just be outputting the upper 8 bits to the DAC bus.
From the interpreter source:
As you can see, the pin/pin-group is driven low (output state) which enables the smart pin configured by the pinstart() functions.
You can use pinhigh() or pinlow() -- either sets the dection bit(s) to 1. The smart pin(s) will not be enabled until that happens.