1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Writing to database

Discussion in 'Arduino' started by BioniC187, Apr 5, 2013.

  1. BioniC187

    BioniC187 Member

    Joined:
    Aug 9, 2011
    Messages:
    281
    Likes:
    10
    Wow, that is awesome!!

    I'm gonna try to look into pure C coding. And you're totally right that the Arduino IDE hides all that good stuff. I have made a small start, I did the uart initializations by writing directly to the registers. But i use this within the Arduino IDE.

    Had work and stuff, so couldn't get a chance to test fully microtime with C. But i did test stopwatch, and still got varying time values. For the same 1000ms, i got a maximum of 2ms deviation, which isn't what i want. I feel I can be more accurate, until then I won't settle lol

    I was looking into getting the database to add the microsecond timestamp and then I'll check the accuracy of that
     
  2. BioniC187

    BioniC187 Member

    Joined:
    Aug 9, 2011
    Messages:
    281
    Likes:
    10
    Alright, here is the same C program to receive the serial data, but i changed the Arduino code like I said i would. I used a compare timer, and here are the results.
    This is the C program that uses "now" lol. Surprising results coz i read, and even as misterT mentioned, stopwatch is the way to go for such a thing.

    Did a test earlier, but didn't have time to post it, got a bit busy.

    Again, ignore the nonsense, and look at the interval. I set it for 1Hz
    new timing 2.jpg

    Results are currently good. I will try some more tests working the a higher freq, and increasing the bps. Hopefully the results will be good as well :)
     
  3. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    Why all the records are exactly the same? Even all the T1 and T2 values are identical.. do you have a bug in your code?

    EDIT: Sorry, my mistake. The numbers are not identical. The change is only one digit because the timing is so accurate. Hard to spot the changing digit. That is why I first thought they are identical :)
     
    Last edited: Apr 26, 2013
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. BioniC187

    BioniC187 Member

    Joined:
    Aug 9, 2011
    Messages:
    281
    Likes:
    10

    Well, it seems, the pc has reached its limits when it comes to even reasonably accurate microsecond timing of events.
    My pc can't handle anything above 10Hz! the deviation in time between each pulse at 10Hz is too much.

    I've been working, and I've done some code for the arduino to capture the time between events.
    Using the timers, I send the TCNT value to the pc with very accurate results. But I need to trim down the code, to avoid wasting clock pulses on nonsense.

    I'm currently sending data at 115200 and at 1Khz it seems perfect
    :)
     
  6. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    It is the operating systems fault. I think normal windows and linux clocks its task switching at 100Hz. There is too much code between hardware and your custom software that it is impossible to get accurate timing.
     
  7. BioniC187

    BioniC187 Member

    Joined:
    Aug 9, 2011
    Messages:
    281
    Likes:
    10
    Yeah, its so bad at timing its not funny. I have realized i need to use low level code in order to get the timing correct, but that's difficult to accomplish - I've spoken to some programmers already.


    The code I've written for the Arduino, could possibly yield me a result that has the potential to work at 1.5MHz with sending the time between each pulse to the pc over serial.

    I want to make it into a neat little library, I'll post it when I'm done with it

    :)
     
  8. BioniC187

    BioniC187 Member

    Joined:
    Aug 9, 2011
    Messages:
    281
    Likes:
    10
    Sorry, double post
     
    Last edited: Apr 30, 2013
  9. BioniC187

    BioniC187 Member

    Joined:
    Aug 9, 2011
    Messages:
    281
    Likes:
    10
    I'm taking a long time with the library. Between work and me wanting the library to have good functionality, it is time consuming. Will hopefully have it done soon though :)
     

Share This Page