TAQOZ - ADC using Smart Pin - run in new cog
twm47099
Posts: 867
I had previously been able (with a lot of help) to use a Smart Pin as an ADC to read a voltage from a potentiometer. The program is at this link:
forums.parallax.com/discussion/comment/1461499/#Comment_1461499
I have tried to do the same with TAQOZ. My code is:
I think that I don't have to put ADC_PIN on the stack for WRPIN, WXPIN, and WYPIN since I used the PIN word to select the pin to use as a smart pin. However, I have tried a version with ADC_PIN before each of those lines. That also didn't work. I'm also not sure if waitcnt is the best way to stall the program while the smart pin collects the bits.
Help will be greatly appreciated.
Tom
forums.parallax.com/discussion/comment/1461499/#Comment_1461499
I have tried to do the same with TAQOZ. My code is:
--- ------------------------------------------------------ --- **** adcsp.fth --- UsePin 22 as smart pin in ADC mode --- ------------------------------------------------------ --- Define Constants --- ADC_MODE from spin2 program that worked %0000_0000_000_100011_0000000_00_01111_0 := ADC_MODE 22 := ADC_PIN 4096 := ADC_CYCLES : adcsp ( -- ) ADC_PIN PIN F ' set pin dir = 0 ADC_MODE WRPIN ADC_CYCLES WXPIN 0 WYPIN L ' set pin dir = 1 cnt@ ADC_CYCLES + WAITCNT ' wait ADC_CYCLES RDPIN . CRLF @PIN . CRLF ;It doesn't work. I get 0 for RDPIN regardless of the voltage setting.
I think that I don't have to put ADC_PIN on the stack for WRPIN, WXPIN, and WYPIN since I used the PIN word to select the pin to use as a smart pin. However, I have tried a version with ADC_PIN before each of those lines. That also didn't work. I'm also not sure if waitcnt is the best way to stall the program while the smart pin collects the bits.
Help will be greatly appreciated.
Tom
Comments
But now when I try to run the program I get a mess: In this case (TAQOZ v 1.1) it just prints out the SD directory and a string of nonsense characters.
Without the boot SD (TAQOZ v1.0) it shows the following which looks like an empty directory
Note for these two prinouts I had changed the last line of ADCSP to: The value RDPIN puts on the stack is 2009 (it doesn't change regardless of where the pot is set. However, it does change depending on the value of the constant ADC_CYCLES.
BTW, the reason the binary number fails is simply because there are too many characters in the number that end up overflowing the word buffer but symbols are fine normally. The next version ROM increases this buffer size.
Thanks for the help. I've got to make some cheat sheets for the different languages, so I stop making silly mistakes.
Here's the code that works. It will continuously measure the voltage and print the raw value. Press the number 1 to stop.
Next step will be to run it in a newcog. I think I need to use a variable to send the adc value between cogs. Is that correct?
I want to try some of the other Smart Pin modes to add to this one and the ones in your Intro to TAQOZ document.
Thanks again,
Tom
I've been able to modify the above program to run in a new cog and print the data to the terminal in the original cog.
The modifications are shown below.
After both definitions adcsp and adcdata are loaded, I type: and then adcdata to run the program.
I tried to put into the definition of adcdata, but that did not work. Is it possible to have to start a newcog and function in a definition and use a variable that can be accessed in any cog?
I recall reading in Starting Forth that putting a decimal in a number makes it a double precision number (or something like that), can you explain how this works in TAQOZ?
In some Forths they do this but TAQOZ just allows any symbol to be mixed in which also includes commas. Interestingly I was just thinking about which method I might use to enter double numbers but the decimal point is used as position indicator in 32-bit integers that can be read by software to determine scaling. The print routine automatically handles 64-bit numbers and using <D> before any print will cause it to grab the upper 32-bits to be handled internally after which this internal high word is reset to zero again.
There are however very few double precision operators in TAQOZ, mainly the UM* and UM// and perhaps the */ that uses both of these operators but returns a 32-bit result. I just had a need for it when I wanted to calculate the counter value from the clock rate with: The double number is the 0 $10 where the $1.0000.0000 I suppose is scaled up by 4 bits for some extra precision. It would be nice to be able to enter this as a double number, especially for decimal numbers.
Meaning reading the ADC port and output it again to DAC port.
(The "hello world" of the DSP guys.)
Unfortunately the speed was quite slow. In
the osci screenshot you may see the yellow input at 300 Hz and below the output.
At 1 khz I got nearly a rectangle signal.
Below my source code. I was using only one input and one output.
What did I wrong? Or is this already the upper limit of the Prop2 with Taqoz?
Same effect even with no terminal output, running only one cog for signal processing.
Regards
Markus
Markus,
That was an early version.
The link below & following posts give some better info. One thing is the value in ADC_CLYCLES. That is the number of cycles to get a reading, The higher the number, the longer the ADC measurement takes. There is a post (somewhere) which correlates the number of cycles with the number of bits per ADC value. I believe I was looking at 12 bit ADC data. I wasn't looking for speed.
Also the calibration constants were made empirically for my set up. the better way is to get the ADC values for ground and Vio and set them into CALMIN and CALMAX.
forums.parallax.com/discussion/comment/1461428/#Comment_1461428
hope this helps
Tom
https://forums.parallax.com/discussion/169602/characterizing-p2-eval-analog-performance
See the chart P2-EVAL-ENOB.jpg
That was for the A version of the P2. I don't know if there should be any difference with the new chips.
Tom
many thanks for the hints.
Its really hard actually to find the right info, specially regarding the quite
complex smartpin story.
I should suggest the name "COMPLEXPIN" instead ;-)
I will try to do more research in the next days, hoping to get at least a 10 kHz talkthrough example.
Markus
finally I found out with my talkthrough experiments, that the DAC command is extreme slow, or better said is using a very slow DAC mode.
I found some assembler code in your dropbox (see below), which was promising 300 k*samples and more, and tried to translate it into
Taqoz. Unfortunately this code is using an interrupt, and as far as I have seen
Taqoz isn't supporting any interrupts (?, maybe I am wrong).
Maybe words like DAC8FLASH, DAC8 , DAC16 and DAC12 would be nice.
So as less resolution as faster.
And maybe some similar for the ADC conversion, like ADC8, ADC12, ADC16 or so.
Thanks
Markus
just thinking ...
could you use the streamer to get the ADC data into HUB and the streamer of another COG to get them to DAC ?
sure in one COG you will only have one streamer available
and you would have to sync them somehow
but it would not cost you a full COG for the LOOP
It's called smart pin because you have to be smart to use it. :-)
you have got it :-)))