View previous topic :: View next topic |
Author |
Message |
mmc01
Joined: 16 Jun 2010 Posts: 31
|
How to calculate degree of angle from MEMSIC2125 with CCS? |
Posted: Tue Jun 19, 2012 10:29 am |
|
|
I measurement pulse width with CCS Example code EX_CCPMP.C.
http://www.parallax.com/dl/docs/prod/acc/memsickit.pdf
The result of sensor like this.
4757 us
5906 us
6187 us
6142 us
5995 us
6251 us
6227 us
6227 us
6060 us
5887 us
5551 us
5026 us
4733 us
4166 us
3796 us
3750 us
3746 us
3763 us
I don't know how to calculate degree of angle with these values. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Tue Jun 19, 2012 1:42 pm |
|
|
The answer lies in reading the dotPDF documentation that you show a link to. Within those 10 pages is the answer, though you'll have to convert the BASIC code to C( not THAT hard to do).
If you want to send me 3 of those modules, I'll be more than happy to spend an hour and cut the code....
If YOU do the work, YOU gain the knowledge of what to do and why.In the end, YOU will be a better programmer. |
|
|
mmc01
Joined: 16 Jun 2010 Posts: 31
|
|
Posted: Tue Jun 19, 2012 11:48 pm |
|
|
I don't understand about formula. Basic Stamp have to use */ 204 for convert read pulse output to uSecs . I think in PIC the uSec I'm not want to convert. but when I use the formula like in datasheet it's not be correct result.
xRaw = xRaw */ Scale
xGForce = ((xRaw / 10) - 500) * 8
if I calculate like this
xGForce = ((4757 / 10) - 500) * 8
but the result xGForce is -194.4 .I think the result is not correct because it is - degree and 194.4 is more than degree |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 20, 2012 1:55 pm |
|
|
What is your PIC ? What is the oscillator frequency for your PIC ?
This thread has a PULSIN function for CCS. It's similar to PULSIN for the
BasicStamp. You should try it:
http://www.ccsinfo.com/forum/viewtopic.php?t=42353
Then post the usec numbers that you get. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed Jun 20, 2012 3:23 pm |
|
|
You also have to figure out how to recode the */ operator that is unique to Stamp BASIC( as far as I know). Called 'multiply middle', it's used in the calcuations. I've never heard of it let alone used it and I have a drawer full of 'stamps'.
As well the /10 on the next line I believe refers to the 10 milliseconds of the total pulse width of the reading (the sum of T1 and T2).
You would be wise to grab a pencil and paper and do the math to see what Parallax is doing 'with the numbers'. Once you figure that out, then convert ito CCS C code.
Yes, it may be a bit of a challenge, but once you figure it out, you'll probably say 'well that was easy'..... |
|
|
|