Pages: 1 ... 3 4 [5] 6 7 ... 30   Go Down
Author Topic: Cosa: An Object-Oriented Platform for Arduino programming  (Read 84090 times)
1 Member and 1 Guest are viewing this topic.
Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried to grab doc.zip but got a "Error: blob is too big" error. Don't know if that's something at my end or Git's end.

Hi Graynomad, seems to be a problem with downloading of single large files on github's end. I tried it on my machine with the same results as you got. The work-around would be to download the whole master zip archive for Cosa and then unzip the documentation.

https://github.com/mikaelpatel/Cosa/archive/master.zip

Or even better git clone and follow updates :-)

Cheers!
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
download the whole master zip archive
Oh, 50MB, maybe some other time, we don't all have unlimited data plans smiley

I have no immediate use for this because I only (well mostly) work with 32-bit CPUs these days, however if you port this to the Due I'll get much keener as we're designing a new version of it and the fresh hardware platform may like a fresh software platform.

I was thinking of doing one myself but I've got my hands full designing hardware and will do for quite some time I think.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, 50MB, maybe some other time, we don't all have unlimited data plans smiley

I have no immediate use for this because I only (well mostly) work with 32-bit CPUs these days, however if you port this to the Due I'll get much keener as we're designing a new version of it and the fresh hardware platform may like a fresh software platform.
Thanks for the observation on the download size. I have cleaned this mess up and got the master zip from github down from 50 M to 343 K ;-).

The documentation and references have been moved to Dropbox. They shouldn't have been in the repository at github from the start. Sorry about that!

You can now read the documentation online http://dl.dropbox.com/u/993383/Cosa/doc/html/index.html and download http://dl.dropbox.com/u/993383/Cosa/doc.zip

Full details on this update is available in the github README. https://github.com/mikaelpatel/Cosa

Cheers!
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some news on the latest improvements:

1. New driver for the Honeywell HMC5883L 3-Axis Digital Compass with interface to all modes and settings. https://github.com/mikaelpatel/Cosa/blob/master/Cosa/TWI/Driver/HMC5883L.hh and http://dl.dropbox.com/u/993383/Cosa/doc/html/d0/d40/classHMC5883L.html

2. Major improvement to the AT24CXX 2-Wire Serial EEPROM driver. Removed block size limitation. Page alignment and block write are now handled within the class. https://github.com/mikaelpatel/Cosa/blob/master/Cosa/TWI/Driver/AT24CXX.hh and http://dl.dropbox.com/u/993383/Cosa/doc/html/d2/db3/classAT24CXX.html

3. Adding support for fast byte swap (16/32-bit) in Cosa/Types.h. https://github.com/mikaelpatel/Cosa/commit/4247d758977075677e0937097503af39ab2d566d

4. New Pin sub-class for pin change interrupt handling; class InterruptPin. Allows interrupt/event handling on changes on any Arduino pin http://dl.dropbox.com/u/993383/Cosa/doc/html/db/d05/classInterruptPin.html.

Don't forget to follow the blog.

Have fun!
« Last Edit: April 07, 2013, 07:33:44 am by kowalski » Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

More news on the latest improvements:

1. New EEPROM class with device abstraction allowing handling of common data types. Default device is the internal EEPROM. https://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/dc/d83/classEEPROM.html. See example sketch CosaEEPROM.ino https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaEEPROM/CosaEEPROM.ino

2. Refactoring of AT24CXX device driver to implement EEPROM::Device. Support for AT24C32, -64, -128, -256 and -512. See example sketch CosaAT24CXX.ino; uses EEMEM attribute even for external EEPROM. https://github.com/mikaelpatel/Cosa/blob/master/examples/TWI/CosaAT24CXX/CosaAT24CXX.ino.

3. Major update to the online documentation https://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/index.html. Improved detailed description of the classes.

4. Evaluation of different methods of coding bitfield access for C/C++ as alternative to the _BV() and bit set/clear macros (Bits.h). https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaBitfields/CosaBitfields.ino. Bit-field struct definitions are useful for larger bit-fields (> 1 bit) and the compiler can produce better code than with shift/and/or-operators.

First version with shift/and/or-operators.
Code:
uint16_t
color16b(uint8_t red, uint8_t green, uint8_t blue)
{
  return ((((red >> 3) & 0x1f) << 11) | (((green >> 2) & 0x3f) << 5) | ((blue >> 3) & 0x1f));
}

00000284 <_Z8color16bhhh>:
     284: 66 95       lsr r22
     286: 66 95       lsr r22
     288: 70 e0       ldi r23, 0x00 ; 0
     28a: 95 e0       ldi r25, 0x05 ; 5
     28c: 66 0f       add r22, r22
     28e: 77 1f       adc r23, r23
     290: 9a 95       dec r25
     292: e1 f7       brne .-8       ; 0x28c <_Z8color16bhhh+0x8>
     294: 46 95       lsr r20
     296: 46 95       lsr r20
     298: 46 95       lsr r20
     29a: 50 e0       ldi r21, 0x00 ; 0
     29c: 64 2b       or r22, r20
     29e: 75 2b       or r23, r21
     2a0: 38 2f       mov r19, r24
     2a2: 38 7f       andi r19, 0xF8 ; 248
     2a4: 20 e0       ldi r18, 0x00 ; 0
     2a6: 62 2b       or r22, r18
     2a8: 73 2b       or r23, r19
     2aa: cb 01       movw r24, r22
     2ac: 08 95       ret
Second version with union bit-field data type and struct member access. Note the order of the fields. AVR is little-endian (LSB to MSB) in struct.
Code:
union color16_t {
  uint16_t rgb;
  struct {
    unsigned int blue:5;
    unsigned int green:6;
    unsigned int red:5;
  };
};

uint16_t
color16a(uint8_t red, uint8_t green, uint8_t blue)
{
  color16_t c;
  c.red = red >> 3;
  c.green = green >> 2;
  c.blue = blue >> 3;
  return (c.rgb);
}

000001e8 <_Z8color16ahhh>:
     1e8: 70 e0       ldi r23, 0x00 ; 0
     1ea: 75 95       asr r23
     1ec: 67 95       ror r22
     1ee: 75 95       asr r23
     1f0: 67 95       ror r22
     1f2: 26 2f       mov r18, r22
     1f4: 26 95       lsr r18
     1f6: 26 95       lsr r18
     1f8: 26 95       lsr r18
     1fa: 27 70       andi r18, 0x07 ; 7
     1fc: 98 2f       mov r25, r24
     1fe: 98 7f       andi r25, 0xF8 ; 248
     200: 50 e0       ldi r21, 0x00 ; 0
     202: 83 e0       ldi r24, 0x03 ; 3
     204: 55 95       asr r21
     206: 47 95       ror r20
     208: 8a 95       dec r24
     20a: e1 f7       brne .-8       ; 0x204 <_Z8color16ahhh+0x1c>
     20c: 4f 71       andi r20, 0x1F ; 31
     20e: 62 95       swap r22
     210: 66 0f       add r22, r22
     212: 60 7e       andi r22, 0xE0 ; 224
     214: 86 2f       mov r24, r22
     216: 84 2b       or r24, r20
     218: 92 2b       or r25, r18
     21a: 08 95       ret

5. Refactoring of Canvas::color16_t handling to union with bit-field struct after the sandboxing. https://github.com/mikaelpatel/Cosa/commit/6f2e541e00856d88183509603e780a0ba85983b2

Don't forget to follow the blog. http://cosa-arduino.blogspot.se/

Have fun!
« Last Edit: April 07, 2013, 04:48:43 pm by kowalski » Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A new Cosa blog posting is now available. It presents the Cosa support for internal and external EEPROM.

http://cosa-arduino.blogspot.se/2013/04/object-oriented-eeprom-device-driver.html

Cheers!
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Amazing amount of work here kowalski. I haven't looked too deep yet but it seems well documented as well.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 1
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
have you planed to make a power "vcc" class, with by example
 int vcc = readVcc(); // with code below
 setlowbat(VccMin, &functiontocall); // function to call when vcc down to VccMin

example code :
Code:
long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);  //ATTINY85
//  ADMUX = _BV(MUX5) | _BV(MUX0);                                          //ATTINY84
//  ADMUX = ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);  //ATMEGA328 168
// ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR)| (0<<MUX5) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);  // ATMEGA1280 2560
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

guillaume.
« Last Edit: April 11, 2013, 01:30:17 pm by guiguid » Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

guiguid, that is a nice idea! Below is a snippet of an example sketch how to do the monitoring
Code:
class VCC : public Periodic {
private:
  uint16_t m_threshold;
  uint16_t m_vcc;
  virtual void run()
  {
    m_vcc = AnalogPin::bandgap();
    if (m_vcc > m_threshold) return;
    on_low_voltage();
  }
public:
  VCC(uint16_t mv, uint16_t ms = 1024) :
    Periodic(ms),
    m_threshold(mv),
    m_vcc(0)
  {}
  virtual void on_low_voltage()
  {
    trace << Watchdog::get_millis() / 1000 << ':' << m_vcc << PSTR(" mV\n");
  }
};

VCC lowPower(4900);
The callback, the virtual function on_low_voltage(), is called when the threshold is exceeded. The default implementation will print the measurement. Sub-class VCC and override the virtual function to implement your own action.

Please see the full the sketch https://github.com/mikaelpatel/Cosa/blob/master/examples/Sandbox/CosaVCC/CosaVCC.ino

In a later update of Cosa I might bring the VCC class into the library.

Cheers!

« Last Edit: April 13, 2013, 06:07:46 am by kowalski » Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Amazing amount of work here kowalski. I haven't looked too deep yet but it seems well documented as well.
Rob, thanks for the encouragement!

Yes, Cosa is a lot of work but also a lot of fun. I did some changes to the documentation so hopefully you can get an overview easier. There are many components, drivers, etc, in Cosa, so some extra help navigating is needed. Please see the "Related Pages" tab http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/pages.html

Cheers!
Logged

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A new Cosa blog posting is now available. It presents some of the Cosa support for 1-Wire devices (with/without parasite powering), the DS18B20 driver, battery monitoring and sending sensor data using the Cosa Virtual Wire Interface (VWI).

http://cosa-arduino.blogspot.se/2013/04/a-virtual-wire-digital-thermometer.html

Cheers!

Big THANKS to guiguid for great suggestions and testing a lot of this code.
 
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

More good work.

I assume the 1-wire is handled with bit-banging the signal(s), any idea how much CPU time that takes?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

More good work.
I assume the 1-wire is handled with bit-banging the signal(s), any idea how much CPU time that takes?
______
Rob
Thanks!

Yes, the Cosa 1-Wire driver does bit-bang the protocol as most micro-controller implementations. I think Wiki explains the protocol very well http://en.wikipedia.org/wiki/1-Wire. There are all the numbers.

The reset or presence signal is the big waste in CPU-cycles if using a simple delay loop. Each bit in the protocol is short (shortest a 5 us pulse, 75 us per bit) so an alternative solution such as timer interrupt sampler is not really possible. UART would be possible.

Reading the temperature from DS18B20 is in the order of 2 ms (reset plus 1 byte command, 8 byte address, 1 byte command followed by read of 7 byte, 960 + 17*75 =  2235 us). Most of this time is delay loops. Typically interrupt handling is allowed between bit read/writes. The actual conversion takes 750 ms at full resolution. During this period the processor can do something else or take a nap.

To answer your question; typically less than 1% at 1 second sample rate (per device).

Cheers!
« Last Edit: April 15, 2013, 08:25:31 am by kowalski » Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8501
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, thanks for that. I'm trying to decide if it's worth putting an I2C to 1-wire bridge chip on a new design, I think I will as that also gives active pullup.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Sweden
Offline Offline
Sr. Member
****
Karma: 11
Posts: 450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, thanks for that. I'm trying to decide if it's worth putting an I2C to 1-wire bridge chip on a new design, I think I will as that also gives active pullup.
______
Rob
I had a look at the DS2482-100 Single-Channel 1-Wire Master, I²C to 1-Wire Bridge Device. Interesting challenge to get the OWI device driver to run over the Cosa TWI, i.e. make the Cosa OWI driver hide the fact that a bridge was used and allow code written as an OWI::Driver to run unchanged.

Actually reading the sensor data from a DS18B20 will take a large number of TWI commands (1-Wire search is even worse). The sequencing is a challenge if to avoid polling the status register in a busy-loop over the TWI driver. This could actually increase the CPU load instead of decreasing it. Though there are a number of advantages with this chip I should add.

Cheers!


Logged

Pages: 1 ... 3 4 [5] 6 7 ... 30   Go Up
Jump to: