Does anyone know the overhead of the spin language?
DRMorrison
Posts: 81
Hello all,
I'm not sure if this is the right question, so read on and let me know.
I found a couple of ADCs in my parts bin, and thought to get one up and running. I found the data sheet and looked at the timing for the serial communications. It looked pretty straight
forward, so I wrote a few lines of spin. The code is listed below, and so is the data sheet timing for the MAX187, 12 bit ADC.
The data sheet for the ADC states a clock speed of 2.5MHz maximum. This gives a period of 400ns. The clock that I should generate is 50% duty cycle, so the ON time is 200ns,
and the OFF is the same. The Propeller is running at 80MHz, so the period is 12.5MHz. So to have the clock on for 200ns, I need 16 system clocks high, and 16 system clocks low.
This would look like this: waitcnt(16 + cnt).
However, this does not work. As seen in the code below, the smallest value I can seem to use is 400 counts. Anything smaller doesn't work--the program hangs just as it enters the repeat loop.
My question is this: Why such a large discrepancy? I know that spin is an interpreted language, so is this why? Would asm be a better alternative in this case?
Daniel
"I know that I don't know as much as you do, so now I know more than you do--wait! now you know too."
I'm not sure if this is the right question, so read on and let me know.
I found a couple of ADCs in my parts bin, and thought to get one up and running. I found the data sheet and looked at the timing for the serial communications. It looked pretty straight
forward, so I wrote a few lines of spin. The code is listed below, and so is the data sheet timing for the MAX187, 12 bit ADC.
The data sheet for the ADC states a clock speed of 2.5MHz maximum. This gives a period of 400ns. The clock that I should generate is 50% duty cycle, so the ON time is 200ns,
and the OFF is the same. The Propeller is running at 80MHz, so the period is 12.5MHz. So to have the clock on for 200ns, I need 16 system clocks high, and 16 system clocks low.
This would look like this: waitcnt(16 + cnt).
However, this does not work. As seen in the code below, the smallest value I can seem to use is 400 counts. Anything smaller doesn't work--the program hangs just as it enters the repeat loop.
My question is this: Why such a large discrepancy? I know that spin is an interpreted language, so is this why? Would asm be a better alternative in this case?
Daniel
[SIZE=3]PUB Measure outa[cs]~ 'start conversion waitpeq(|< Dout, |< Dout, 0) 'wait for data available repeat 12 'shift 12 data bits into variable !outa[clk] 'rising edge of clk signal ADC_Value += ina[Dout] 'insert data into variable waitcnt(400 + cnt) 'about 5µs at 80MHz system clock !outa[clk] ADC_Value <<= 1 waitcnt(400 + cnt) ADC_Value += ina[Dout] 'get that last bit, LSB outa[cs]~~ ADC_Value &= $FFF 'strip everything above bit 12[/SIZE]
"I know that I don't know as much as you do, so now I know more than you do--wait! now you know too."
Comments
EDIT: I found that on page 219...
"In fact, the interpreter takes 381 cycles of final overhead when the command is written in the form waitcnt(offset + cnt)."
Should have done more research.
Daniel