PropBasic - shiftin/shiftout "speed" parm 5 - definition requested
pmrobert
Posts: 675
In a statement "shiftout spi_tx, spi_clk, msbfirst, %11101\5, so_speed" I can plug values into so_speed and increasing numbers definitely speed up the SPI transaction in an ascending manner to a certain point where the MCP3208 ADC chip doesn't respond. I'm not particularly fluent in PASM and see that changing that fifth parameter changes a couple of waitcnts in the emitted code. I've searched far and wide but am unable to find a definitive description of what unit this parameter is in. I can use up to 33 in a cog mode code task and 5 in the same task but running LMM mode; this matches Bean's statement elsewhere that LMM is 5-6 times slower than the equivalent cog mode code. Can anyone help me?
-Mike
-Mike
Comments
Then again, it could be table driven, 0 meaning lowest speed and going up from there.
and with value 5:
The PropBasic code is:
My scope, the timing measurements I've placed in there and, I think, the PASM code tells me it increases the SPI clock and data rate. I'm just curious what multiplier/divider this parm is in relation to what base. Hope that makes sense...
Thank you -Mike
Anyway, I came up with a preliminary equation: baudrate = (clkfreq/1600)*speed. Note that this is clipped for n = 1 as we can only fit 511 into a literal parameter (533.3 required @80MHz). Other values are OK. Going towards higher numbers it's clipped as well (most likely in the code generator), 20 cycles seems to be the lower limit here (around speed = 26). HTH
Note that this equation works for 80MHz, it reacts to changes (40MHz has half the cycle count) so there may be some work required in that department (too lazy to check, 50k*speed seems to fit the bill). But this should work for you.
PS: My daughter was looking over my shoulder and said something about a black cat...
Thanks again,
-Mike
ShiftIn and ShiftOut have different instructions inside the loop, so the minimum is different for each of them.
If I remember correctly the default speed is 100KHz and gets scaled from there until the minimum is hit. So speed "2" would be about 200KHz etc.
Bean
-Mike