LSM9DS1 "C" pasm high speed SPI driver
Shawna
Posts: 508
in Propeller 1
There are some threads on the forum about fast C spi drivers. I have yet to find one with a library. Does anyone know of one? It looks like the ELEV-8 uses a spin file with a SPI PASM driver in it. I think Jason must have used a wrapper to make that work. The little info I could find on such a wrapper looks like it only works with C++.
I have been playing with inline assembly, but I am not really sure if that is a good route to explore.
I have also played with fcache, but I think that only handles native code.
I have been struggling with deciding which language to pursue. I like spin, but it looks like Parallax is pushing C on the learn site. It almost seems like spin is dead from a support level. I would say it was dead, if it wasn't for the fact that Prop II supporting spin. Can't wait for the prop II by the way. You guys have been doing some neat stuff with it so far.
Anyways do you guys have any suggestions.
Thanks
Shawn A.
I have been playing with inline assembly, but I am not really sure if that is a good route to explore.
I have also played with fcache, but I think that only handles native code.
I have been struggling with deciding which language to pursue. I like spin, but it looks like Parallax is pushing C on the learn site. It almost seems like spin is dead from a support level. I would say it was dead, if it wasn't for the fact that Prop II supporting spin. Can't wait for the prop II by the way. You guys have been doing some neat stuff with it so far.
Anyways do you guys have any suggestions.
Thanks
Shawn A.
Comments
Is there a tutorial on this anywhere?
This post starts my efforts to take a PASM driver for the 360 feedback servo and write a C program to use it. https://forums.parallax.com/discussion/comment/1425089/#Comment_1425089
Hope this helps
Tom
It's a converted C++ library for the propeller. I has both fixed point and floating point that can be enabled.
Mike
To be honest I think you'll hear C programmers complaining about the lack of support for C from Parallax too. You should use whatever language you're comfortable with -- make your own decisions.
Alongside spin2cpp there's a compiler called "fastspin" that supports Spin/PASM, BASIC, and C and lets you mix those languages freely (so C code can call Spin and vice-versa, and both can call BASIC). The C support in fastspin is still early, so it's not a polished solution yet, but it's coming along quickly.
There's a primitive IDE for fastspin called spin2gui (https://github.com/totalspectrum/spin2gui/releases). It's mainly focused on P2 development, but you can select P1 by going to the "Commands > Configure Commands..." menu and selecting "P1 defaults".
Yeah, I have read through that thread a couple of times. Andy kept talking about how he was going to add a tutorial to the learn site. Which I could not find. I did finally see the example of the blinkpasm attached to one of his posts.
Thanks for the link Tom.
Thanks for the link to your library Mike, I will play with it and see if it is faster than the simple libraries driver. I took a brief look at it and it looks like your driver uses I2C.
Eric, I have read about spin2cpp, I will give it a try. Thanks
I wrote a quick program using the simple tools library and it takes 4.5mS to read the raw acc values from the LSM9DS1. I think I am going to get spin code running that I can read the sensor with the spiasm object. I will then time it, and figure out which way to port it over to C. I am kind of hoping to use spin2cpp, but with what little reading I have done so far that thought maybe a bit premature. I am pretty confident that the 4.5mS is ridiculously slow. I think the ELEV-8 stated it was reading all three sensors and filtering the data at around 500Hz. I think the ELEV-8 code was also reading a barometer too, all in the same cog, but not at 500Hz.
Thanks Again
Shawn A.
Mike
Mike
So I just changed the program to LMM mode, LMM reduced the time to 878 uS, which is still not even close to the 500Hz.
If I remember correctly the difference between a pasm driver and the simple tools driver is how the shiftout and shiftin functions are written. I maybe wrong though.
here is the code for the shiftOut:
Mike
Mike
My current goal is to build a balancing bot. Depending on how that goes, and which way my interests take me, I may re-visit building a quad copter. Probably not the quad copter though, I was never able to wrap my head around the Direct Cosine Matrix math.
The best fusion is to use Quaternions to represent the angles. This is also used by quad copters to balance as well.
I am looking at using EM7180 coprocessor unit that claims 2 degree of accuracy. It will do all the math for me and all I have to do is read the Quaternions and calculate the Euler angles.
At least that's my plan right now.
Mike
I had a quad copter flying well with Jason Dorie's old DCM code. But my lack of coding skills and lack of knowledge with the DCM matrices led me to abandon the project and move on.
The EM7180 is a coprocessor board that takes on the work of reading the sensors and all the floating math and presents the answers that you can use.
Mike
Not sure what gave you the impression it was premature, but the original version of spin2cpp was released more than 8 years ago, so the core functionality of converting Spin code to C or C++ code is pretty well tested now. It's been used on some fairly significant projects (like converting Scribbler firmware from Spin to C).
fastspin (the sister program to spin2cpp that can compile Spin code to native binaries) is not quite as mature, but for plain Spin code I think it should work very well -- it's only the newer fastspin features like BASIC and C input support that are still under development.
500Hz would be 2000 microseconds, so even accounting for the Nyquist limit (you really want to sample at twice the frequency) I'm not sure why 878 uS would be "not even close"? Granted, you have other things to do in your program, but couldn't you dedicate a COG to the sampling function?
Yeah, I didn't explain that very well. When I said "not even close" I was thinking about all the other things I want to accomplish in the 2000uS window.
The 878uS was for just reading raw data from ACC. That doesn't include reading the raw gyro readings or filtering the data.
The other tasks could be off loaded to another COG.
The learn LSM9DS1 driver uses the simpletools shiftin and shiftout functions for communication.
-I made copies of Simpletools shiftin and shiftout functions and added them to the LSM9DS1 library
-I modified the new ShiftOut and ShiftIn files so that there are no function calls to other C files. For instance ShiftOut and ShiftIn both call the Simpletools toggle function. I replaced the toggle function
call, with the actual code from the toggle function.
-I hard coded ShiftOut for MSBFIRST and ShiftIn for MSBPRE and removed the other code that selected different modes.
-I added fcache to each file.
Test harness code for reading raw ACC data:
Results:
The new Shiftout and ShiftIn C files with fcache fly! I am very pleased. There is over a 10 time speed gain in CMM mode, with a code size increase of only 60 bytes. There are probably better ways to do this but this should work.
Thanks for all the help guys!
Shawn A
I needed to write a lot of data for screen updates to the HX display module I had and found it was not fast enough without these changes.
Mike