Go Down

Topic: Development using Arduino... (Read 1 time) previous topic - next topic

Coding Badly


Only two bytes are needed.  Use two bits to indicate the range and the remaining 14 bits to store the value...

0.01 to 9.99 --> value * 100 is stored
10.0 to 99.9 --> value * 10 is stored
no decimal from 100 to 10,000 --> value * 1 is stored

The drawback is the value has to be decoded and you absolutely cannot try to store negative values or values over 16,385 (meaning you need to include the clamps).

This should get you started...

Code: [Select]
union
{
  typedef struct
  {
    uint16_t range:2;
    uint16_t value:14;
  };
  uint16_t storeThis;
}
cracker_t;


As long as you only write to range / value and only read from storeThis you should be OK with strict aliasing rules.

But what about time stamp?

Also, Why does the Arduino Mega not use FTDI? Is there a limitation there?

Coding Badly

Also, Why does the Arduino Mega not use FTDI? Is there a limitation there?


It makes the board more versatile.  You can reconfigure the board to be different USB devices (e.g. the board can be presented to the computer as a keyboard).

CrossRoads

10,000 decimal is only 0x2710, could be stored as an INT.
1000 values only needs 2000 bytes to store.
Then add another INT with # of seconds since start, 65,535 = 1092 minutes = 18 hours. Is that enough?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


It makes the board more versatile.  You can reconfigure the board to be different USB devices (e.g. the board can be presented to the computer as a keyboard).


Does this make the board native USB? So instead of a virtual com port the computer will recognize the board as a USB device? Like when you plug in a digital camera, it'll say "Sony DSCXXX" or when you plug in a phone it'll say the brand and model number?

Can I still use good old FTDI instead?

Quote from: CrossRoads
10,000 decimal is only 0x2710, could be stored as an INT.
1000 values only needs 2000 bytes to store.
Then add another INT with # of seconds since start, 65,535 = 1092 minutes = 18 hours. Is that enough?


Actually, no. I need a RTC, that'll display time and date info on the screen at all times. And at the click of a button the current reading should be stored along with the time and date info. It'll be rolling list, so when the user gets to reading number 1000, it would automatically start again from reading number 1.

CrossRoads

I'd go with external SPI interface part then, either EEPROM or FRAM (ferro-electric RAM; has SRAM access speeds, EEPROM data retention but without the write limitations/byte. Mouser.com has a good variety of them). Store as much as you want per logged event.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

#21
Mar 13, 2013, 03:12 pm Last Edit: Mar 13, 2013, 03:14 pm by CrossRoads Reason: 1
I use FTDI in my projects.  No messing with additional programming of 16U2 part for a USB interface.
I add a socket to plug one of these in and not mess with soldering the TSSOP package down:
http://www.mouser.com/ProductDetail/mikroElektronika/MIKROE-483/?qs=%2fha2pyFadugsEwyLV5fFyIWdPbushEDhRSvnBE0ODG8%3d
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Coding Badly

#22
Mar 14, 2013, 08:16 pm Last Edit: Mar 14, 2013, 08:19 pm by Coding Badly Reason: 1
Does this make the board native USB?


"Native USB"?  That's an odd phrase.

Quote
So instead of a virtual com port the computer will recognize the board as a USB device?


Virtual com ports are a particular type of USB device.  But I understand what you mean.

Quote
Like when you plug in a digital camera, it'll say "Sony DSCXXX" or when you plug in a phone it'll say the brand and model number?


Exactly.  On this forum, MIDI and HID (keyboard or mouse) seem to be the most commonly mentioned USB devices.  It is possible to mimic any USB device (e.g. storage, camera, joystick).

Quote
And at the click of a button the current reading should be stored along with the time and date info.


A range of days with a granularity of one second.  If two bytes is used the range is about 3/4 of a day.  Three bytes gets a range of 194 days.

Two bytes for the value plus at least three bytes for the time-offset with at least 1000 values stored means you have exceeded the available EEPROM.  It's time to shop for a FRAM.

...oh, wait...  Are you going with the 2560 or the 1284?

Go Up