MPXA4115A picbasic code


Closed Thread
Results 1 to 40 of 104

Hybrid View

  1. #1
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Hi Scalerobotics,

    I liked your smd version (smaller pcb is always a good one!)

    I think I will keep the 20Mhz crystal because I have problems here with the servo read/send signals (passtrough) .The problem is inside adc oversampling convertion routine. I think ot is a liitle bit slow convertion that slows things down and as I only use pulsin and pulsout to read and regenarate servo pulses at tghis point I notice that servo works ok but with speed control (so I can cut the motor) I have no response.
    Last edited by bitmaniac; - 20th July 2009 at 05:47.

  2. #2
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Hi! back again with this unfinished project.
    Well after a lot of experiment I will alter my schematic again.
    Using Darrel code for 14bit convertion I have problems with servo in / out routine. Using pulsin/pulsout to re-generate servo signals although normal servo response ok (a little bit jerky motion) when it comes to use Speed controller to ontrol brushless motor it does not seem to respond at all. If I disable Darrel convertion routine SC workink ok.
    So I am thinking of using a MAX187 12bit ADC (and maybe an op-amp in the future).
    I have already put together a 12f683 + MPX4115 and a MAX187 on a raster and SC seems to work now. I will keep you inform of my future proggress.....
    Last edited by bitmaniac; - 7th September 2009 at 15:11.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink At last !!!

    Hi, Alexandros

    Now we can make good work ... there was no other serious solution than having REAL bits as inputs ... 12 is a minimum.

    Just have to find MAX 187 ... ( 4.096v internal ref is a good thing ! ) ... may be we could try to find another ADC with both LoVref and HiVref pins available ... some more bit to win here !!!

    An LTC1286 could be the one ... with 4.096v ext ref !!!

    The MS5534 was the other solution : a bit expensive, but better resolution !!! ( it's the one used in commercial altitude related devices ... eh ! ). It just needs a 12F683 for 32 khz generation ( HPWM ) ...

    Alain
    Last edited by Acetronics2; - 7th September 2009 at 16:04.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Hi! Alain

    Well max 187 is a very good ADC I think and you can also use External Vref (as I can see from datasheet)

    I tried tie external Vdd to ref pin (according to datasheet you have to leave pin 3 floatting) and change pin 4 cap from 4.7uf to 100nf.
    I tried internal 4.096V ref. but as I did not use op-amp I think I was at the limit of 4.096v so I decide to go roughly with Vdd external but I noticed a jerky ADC reading -/+ 10 values up and down. Maybe this was to a not clear 5v external source (I used an ATX pc supply). I will try again with Speed contrller Bec and let you know.
    I must finish this project....

    (...Alain maybe we can use a 14bit 8pin SPI IC if exists! ....(I want too much eh!?)

    Also about MS5534 you suggest I follow some links you gave me in previous posts but as I have already ordered 5 MPX sensors and as I want a simpler project (just read 200m ALT change) and not even real ALT in meters measurements I think we can just go with an F683 and a 12bit ADC(or 14bit ADC 8 pin if available).
    Last edited by bitmaniac; - 7th September 2009 at 17:58.

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    The MPX4115A is a "Ratiometric" type of device. Which means that the output voltage is proportional to the power supply voltage.
    This is a great feature when using a PIC, because the PIC's A/D converter is also "Ratiometric".
    This way you will always get the same results from the sensor, even if your power supply isn't exactly 5.00V or if it drifts a little, like will happen with a battery operated device.

    If you try to measure a ratiometric device using a fixed voltage reference ... as the VDD voltage changes, your pressure reading will change too. So you've lost that nice stable signal that a ratiometric sensor gives you.

    I don't think you should use a VREF+ at all.<hr>

    Quote Originally Posted by bitmaniac
    Using Darrel code for 14bit convertion I have problems with servo in / out routine. Using pulsin/pulsout to re-generate servo signals although normal servo response ok (a little bit jerky motion) when it comes to use Speed controller to ontrol brushless motor it does not seem to respond at all. If I disable Darrel convertion routine SC workink ok.
    Trying to do all that in software ... no doubt there are problems.

    For 14-bit resolution it takes a minimum of 7.4ms to grab the 256 samples needed.
    If you left PBP's default AD defines intact, it could take up to 25ms.
    Obviously not fast enough to do software timed servos too.

    I agree, an external A/D with higher resolution will probably be best. (without fixed Vref+)

    Added:

    But if you're just going to a 12-bit external A/D.
    You might try the same routines again at the 12-bit resolution. Or even 13-bit.

    At 12-bit resolution it only needs 16 samples, which takes <strike>387us</strike> 465us minimum.
    Plenty of time left for eveything else.
    <br>
    Last edited by Darrel Taylor; - 7th September 2009 at 23:05. Reason: 12/13-bit
    DT

  6. #6
    Join Date
    Jan 2004
    Location
    Thessaloniki , GREECE
    Posts
    61


    Did you find this post helpful? Yes | No

    Default

    Well,
    I put together some stuff on a prototype pcb and servo routines worked ok! ( a little bit of improvement needed!)
    I notice that without an op-amp and using just a max187 12bit ADC with EXTERNAL Vref tied to Vdd I get readings from ADC that plays between 2-3 value (NOT good). If we think that we use 12bit we have a resolution of about -+2meters and if the value plays between 2-3 values the error increase between -+6 meters (not good at all).
    May be the only and better solution is go to 12bit ADC AND an op-amp too!
    Also as a final thought is that maybe I have interference somewhere with the sensor although I used decoupling and filter capacitors according to MPX datasheet.
    The main thing is that servo routines / speed controller arming e.t.c work fine!

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Alexandros

    1) do not forget a LoPass R/C at the sensor output ( Freescale AN's ... )

    2) take care to the ground plane (@ 12 bits it becomes useful !!! )

    2) you can take 8 or 16 samples and calculate the mean value ( this is pompously called ... "Oversampling" , if you take into account the UNMEANINGFUL LSBits of the result . LOL ! )

    or better use a " rolling mean value " ( mean value = 7/8 oldvalue + 1/8 Newvalue i.e. , for 8 samples ) advantage is you access meanvalue after each sampling ...

    I am testing an auto zeroing and resolution enhancement design on my side ... but shhhht !!!

    Alain
    Last edited by Acetronics2; - 8th September 2009 at 19:59.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default Re: MPXA4115A picbasic code

    I need to work at this a little to explain it well. But here is a shot at explaining it generally. I am still looking for the excel spreadsheet I did to make my lookup table ... but in the mean time...

    Using an excel spread sheet, put a formula for calculating altitude from pressure. Add the formula for your pressure sensor to convert its voltage to pressure. Add in the part that converts your A/D reading to a voltage. Once you get to a point where you can say a reading of xxx of your a/d conversion gives you x feet or meters, you can find some evenly spaced a/d readings, and input the corresponding feet or meters into a lookup table. I know this explanation kind of stinks, because you need some examples here. I will try to elaborate on this later.

    Anyway, once you have your lookup table, you need to divide your a/d reading by a number. If you look at my lookup table, you see that I am dividing by 1000 and subtracting 15. This is for a 16 bit A/D result. (In my code, even if you decide to use 12 bit resolution, it is shifted up to 16 bits so it can use the same lookup table). The subtract 15 lets you lower the start of your max altitude. Normal folks might just want to go up to 12,000 feet, or maybe even lower, so they would have a bigger subtraction number, and a different lookup table, that started at a lower altitude.

    You may notice that I am looking up two values. This is because the value from the adc will be between two of the lookup table values. The lookup values in my table are about 400 feet or so apart. To make this somewhat accurate, we need to lookup both readings in the lookup table, find the difference in feet, then take our remainder from divide by 1000 and multiply the fraction to the difference in feet. Then I subtract this from my TempAlt to get a final altitude. For this to work, my lookup table had to be made at Analog to digital steps of 1000. That makes the math a little easier.

    I am pretty sure I used Alain's spreadsheet as a base to calculate my lookup table. You can find his spreadsheet in Post 33 and another one of his previous. Also BitManiac has a spreadsheet in there as well. Here are my values, calculating for even 1000 steps for the A/D value. Table step number is shown, as is feet of altitude, and pressure in Pa.

    <table frame="VOID" rules="NONE" border="0" cellspacing="0" cols="4"> <colgroup><col width="83"><col width="93"><col width="107"><col width="107"></colgroup> <tbody> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20" width="83">A/D Value</td> <td align="CENTER" bgcolor="#E6E6E6" width="93">Table step </td> <td align="CENTER" bgcolor="#E6E6E6" width="107">Feet</td> <td align="CENTER" bgcolor="#E6E6E6" width="107">Pa</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">54000</td> <td align="CENTER" bgcolor="#E6E6E6">39</td> <td align="CENTER" bgcolor="#E6E6E6">-237</td> <td align="CENTER" bgcolor="#E6E6E6">102.2</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">53000</td> <td align="CENTER" bgcolor="#E6E6E6">38</td> <td align="CENTER" bgcolor="#E6E6E6">226</td> <td align="CENTER" bgcolor="#E6E6E6">100.5</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">52000</td> <td align="CENTER" bgcolor="#E6E6E6">37</td> <td align="CENTER" bgcolor="#E6E6E6">696</td> <td align="CENTER" bgcolor="#E6E6E6">98.8</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">51000</td> <td align="CENTER" bgcolor="#E6E6E6">36</td> <td align="CENTER" bgcolor="#E6E6E6">1172</td> <td align="CENTER" bgcolor="#E6E6E6">97.11</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">50000</td> <td align="CENTER" bgcolor="#E6E6E6">35</td> <td align="CENTER" bgcolor="#E6E6E6">1655</td> <td align="CENTER" bgcolor="#E6E6E6">95.41</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">49000</td> <td align="CENTER" bgcolor="#E6E6E6">34</td> <td align="CENTER" bgcolor="#E6E6E6">2145</td> <td align="CENTER" bgcolor="#E6E6E6">93.71</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">48000</td> <td align="CENTER" bgcolor="#E6E6E6">33</td> <td align="CENTER" bgcolor="#E6E6E6">2643</td> <td align="CENTER" bgcolor="#E6E6E6">92.02</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">47000</td> <td align="CENTER" bgcolor="#E6E6E6">32</td> <td align="CENTER" bgcolor="#E6E6E6">3148</td> <td align="CENTER" bgcolor="#E6E6E6">90.32</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">46000</td> <td align="CENTER" bgcolor="#E6E6E6">31</td> <td align="CENTER" bgcolor="#E6E6E6">3660</td> <td align="CENTER" bgcolor="#E6E6E6">88.62</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">45000</td> <td align="CENTER" bgcolor="#E6E6E6">30</td> <td align="CENTER" bgcolor="#E6E6E6">4181</td> <td align="CENTER" bgcolor="#E6E6E6">86.92</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">44000</td> <td align="CENTER" bgcolor="#E6E6E6">29</td> <td align="CENTER" bgcolor="#E6E6E6">4710</td> <td align="CENTER" bgcolor="#E6E6E6">85.23</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">43000</td> <td align="CENTER" bgcolor="#E6E6E6">28</td> <td align="CENTER" bgcolor="#E6E6E6">5247</td> <td align="CENTER" bgcolor="#E6E6E6">83.53</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">42000</td> <td align="CENTER" bgcolor="#E6E6E6">27</td> <td align="CENTER" bgcolor="#E6E6E6">5794</td> <td align="CENTER" bgcolor="#E6E6E6">81.83</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">41000</td> <td align="CENTER" bgcolor="#E6E6E6">26</td> <td align="CENTER" bgcolor="#E6E6E6">6349</td> <td align="CENTER" bgcolor="#E6E6E6">80.14</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">40000</td> <td align="CENTER" bgcolor="#E6E6E6">25</td> <td align="CENTER" bgcolor="#E6E6E6">6915</td> <td align="CENTER" bgcolor="#E6E6E6">78.44</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">39000</td> <td align="CENTER" bgcolor="#E6E6E6">24</td> <td align="CENTER" bgcolor="#E6E6E6">7490</td> <td align="CENTER" bgcolor="#E6E6E6">76.74</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">38000</td> <td align="CENTER" bgcolor="#E6E6E6">23</td> <td align="CENTER" bgcolor="#E6E6E6">8076</td> <td align="CENTER" bgcolor="#E6E6E6">75.04</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">37000</td> <td align="CENTER" bgcolor="#E6E6E6">22</td> <td align="CENTER" bgcolor="#E6E6E6">8672</td> <td align="CENTER" bgcolor="#E6E6E6">73.35</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">36000</td> <td align="CENTER" bgcolor="#E6E6E6">21</td> <td align="CENTER" bgcolor="#E6E6E6">9280</td> <td align="CENTER" bgcolor="#E6E6E6">71.65</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">35000</td> <td align="CENTER" bgcolor="#E6E6E6">20</td> <td align="CENTER" bgcolor="#E6E6E6">9900</td> <td align="CENTER" bgcolor="#E6E6E6">69.95</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">34000</td> <td align="CENTER" bgcolor="#E6E6E6">19</td> <td align="CENTER" bgcolor="#E6E6E6">10532</td> <td align="CENTER" bgcolor="#E6E6E6">68.26</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">33000</td> <td align="CENTER" bgcolor="#E6E6E6">18</td> <td align="CENTER" bgcolor="#E6E6E6">11176</td> <td align="CENTER" bgcolor="#E6E6E6">66.56</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">32000</td> <td align="CENTER" bgcolor="#E6E6E6">17</td> <td align="CENTER" bgcolor="#E6E6E6">11834</td> <td align="CENTER" bgcolor="#E6E6E6">64.86</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">31000</td> <td align="CENTER" bgcolor="#E6E6E6">16</td> <td align="CENTER" bgcolor="#E6E6E6">12507</td> <td align="CENTER" bgcolor="#E6E6E6">63.16</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">30000</td> <td align="CENTER" bgcolor="#E6E6E6">15</td> <td align="CENTER" bgcolor="#E6E6E6">13194</td> <td align="CENTER" bgcolor="#E6E6E6">61.47</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">29000</td> <td align="CENTER" bgcolor="#E6E6E6">14</td> <td align="CENTER" bgcolor="#E6E6E6">13896</td> <td align="CENTER" bgcolor="#E6E6E6">59.77</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">28000</td> <td align="CENTER" bgcolor="#E6E6E6">13</td> <td align="CENTER" bgcolor="#E6E6E6">14615</td> <td align="CENTER" bgcolor="#E6E6E6">58.07</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">27000</td> <td align="CENTER" bgcolor="#E6E6E6">12</td> <td align="CENTER" bgcolor="#E6E6E6">15351</td> <td align="CENTER" bgcolor="#E6E6E6">56.38</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">26000</td> <td align="CENTER" bgcolor="#E6E6E6">11</td> <td align="CENTER" bgcolor="#E6E6E6">16106</td> <td align="CENTER" bgcolor="#E6E6E6">54.68</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">25000</td> <td align="CENTER" bgcolor="#E6E6E6">10</td> <td align="CENTER" bgcolor="#E6E6E6">16879</td> <td align="CENTER" bgcolor="#E6E6E6">52.98</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">24000</td> <td align="CENTER" bgcolor="#E6E6E6">9</td> <td align="CENTER" bgcolor="#E6E6E6">17673</td> <td align="CENTER" bgcolor="#E6E6E6">51.29</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">23000</td> <td align="CENTER" bgcolor="#E6E6E6">8</td> <td align="CENTER" bgcolor="#E6E6E6">18489</td> <td align="CENTER" bgcolor="#E6E6E6">49.59</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">22000</td> <td align="CENTER" bgcolor="#E6E6E6">7</td> <td align="CENTER" bgcolor="#E6E6E6">19327</td> <td align="CENTER" bgcolor="#E6E6E6">47.89</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">21000</td> <td align="CENTER" bgcolor="#E6E6E6">6</td> <td align="CENTER" bgcolor="#E6E6E6">20190</td> <td align="CENTER" bgcolor="#E6E6E6">46.19</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">20000</td> <td align="CENTER" bgcolor="#E6E6E6">5</td> <td align="CENTER" bgcolor="#E6E6E6">21078</td> <td align="CENTER" bgcolor="#E6E6E6">44.5</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">19000</td> <td align="CENTER" bgcolor="#E6E6E6">4</td> <td align="CENTER" bgcolor="#E6E6E6">21995</td> <td align="CENTER" bgcolor="#E6E6E6">42.8</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">18000</td> <td align="CENTER" bgcolor="#E6E6E6">3</td> <td align="CENTER" bgcolor="#E6E6E6">22942</td> <td align="CENTER" bgcolor="#E6E6E6">41.1</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">17000</td> <td align="CENTER" bgcolor="#E6E6E6">2</td> <td align="CENTER" bgcolor="#E6E6E6">23921</td> <td align="CENTER" bgcolor="#E6E6E6">39.41</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">16000</td> <td align="CENTER" bgcolor="#E6E6E6">1</td> <td align="CENTER" bgcolor="#E6E6E6">24934</td> <td align="CENTER" bgcolor="#E6E6E6">37.71</td> </tr> <tr> <td align="CENTER" bgcolor="#E6E6E6" height="20">15000</td> <td align="CENTER" bgcolor="#E6E6E6">0</td> <td align="CENTER" bgcolor="#E6E6E6">25985</td> <td align="CENTER" bgcolor="#E6E6E6">36.01</td> </tr> </tbody> </table>

    I have attached one interesting pdf. It is not the formula I used for my lookup table, but it is interesting.

    Walter
    Attached Images Attached Images
    Last edited by ScaleRobotics; - 4th March 2011 at 14:35.

Similar Threads

  1. sample code for AT45DB642D in Picbasic Pro
    By itsssyam in forum General
    Replies: 0
    Last Post: - 10th March 2010, 06:01
  2. 16f887 44 pin demo board code problem?
    By jessey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 7th December 2008, 14:17
  3. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31
  4. PicBasic code problems with a 16F84A
    By Lauren Barta in forum mel PIC BASIC
    Replies: 3
    Last Post: - 30th May 2006, 22:50
  5. PicBasic Fundamentals
    By Billyc in forum General
    Replies: 9
    Last Post: - 4th May 2004, 10:04

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts