Loading...
 
Arduino.

Arduino



29'th April 2009,

I ran my Arduino for the first time a few minutes ago. So far I'm impressed with how easy it was.
I've been using AVRs for almost as long as they've been in existence. I still maintain a code base of tens of thousands of lines on AVRmega-128 assembler for a CSIRO project. We also used several commercial "C" compilers and "winAVR".

I couldn't do everything I need using the Arduino software but when it come to building a simple AVR project I've never seen a setup which is so easy to get running.

If the Arduino IDE isn't suitable you can always erase the bootloader and upload binaries from another development system using the ISP.

Mainly I bought my Arduino to be compatible with gear I'm build at work (QUT) but I've already thought of a private application - a slow USB to TWI/I2C interface. USB 2 TWI already exists (even open sourced) but I want a slow one so it can go a long way without boosters.

This could be done using a bare micro on vera-board or a rats nest but the Arduino is cheap enough that it isn't worth getting my soldering iron hot.

Later - it looks like I'll be using a SAM7 for my USB2TWI project instead (later: no I won't - the SAM7 can't be a TWI slave).

Next day,

One minor annoyance is one of the connectors isn't on the 0.1 inch grid like the others - there was enough slop my connectors to still get it to mate up to prototyping board. They could also have stuck a few more labels on the boards - connector names for example.

When I went to do some more nitty gritty stuff like change the TWI data rate it wasn't obvious how to take to the control registers and such. Fortunately others had been there before me and google found to right forums.

The TWI example was running at 50Khz instead of the standard 100Hhz. I fixed it and can also slow down to 10Khz to get some extra distance.

It is still an easy platform for beginners wanting to do simple stuff. If you need better control of the code win-avr or assembler may be better.

I've order another arduino from spark fun - the USB version. I also ordered the shield kits. Prototyping board is fine for most things but I have one application which needs to be a bit more professional.

Kinda slow.


I don't want to sound too negative but the code produced by the arduino IDE is kind of slow.
Image
The above image of a logic capture of a 3 byte payload being sent to a i2c/twi device. The maximum clock rate you can get with a 8Mhz mega168 is 500Khz. This has nothing to do with the arduino environment it is a limitation of the chip. However you will notice a considerable delay between the end of one transmission and the beginning of the next. This is almost certainly avoidable.

It could caused by the TWI send routine waiting for the transmission to end before continuing.
It should be possible to do useful work while the transmission is in progress and in many cases is it simply a matter of testing the transmit complete flag before sending data but not waiting for the data to be sent.

This slowness won't affect many users but it is causing me some hassles because I want to output data to 3 DACs at 9Hhz (not possible even with better code and 16Mhz micro). I really need to use SPI not TWI.

Image
The above image is the waveform on a data pin caused by the following code.
  digitalWrite(8, HIGH);    // sets the pin hi
  digitalWrite(8, LOW);    // sets the pin low
  digitalWrite(8, HIGH);    // sets the pin hi
  digitalWrite(8, LOW);    // sets the pin low
//     asm("nop\n");
       asm("cbi 0x5,0\n");
       asm("sbi 0x5,0\n");
       asm("cbi 0x5,0\n");
       asm("sbi 0x5,0\n"); 

We have a couple of square waves done the common "arduino" way and a couple done using inline assembler. The speed difference is about 25:1.
Assembler still rules when things have to happening quickly. Fast code can also save a lot of power in low power applications.


12'th May 2009,

Here is some test code I wrote to use the ad6525 TWI quad DAC.
It runs ok on my 16Hmz Duemilanove. The TWI clock is set for 800Khz. This seems to be as fast as it will go.
There is also a "high speed" mode I haven't tried.
This code put out ramps on DAC-A. It doesn't use the full resolution because it is slow and boring.
I fell into a trap because I bought this DAC thinking it had an internal reference but it didn't - only the parts ending with "R" have it.
I'm also using the LDAC pin - this is probably not needed. I strobe it with inline code so it is doesn't waste much time.
My project is a three phase 50hz signal generator and I'd like to update three DACs in sync - I think this can be done via TWI as well (without speed loss).
// Based on Wire Master Writer by Nicholas Zambetti <http://www.zambetti.com>
// Write to ad6525 quad DAC. Eddie Matejowsky. May 2009

#include <avr/io.h>
#include <Wire.h>
#define CPU_FREQ 16000000L  /* 8 Mhz */
#define TWI_FREQ 800000L /* ??kHz */
#define PRESCALER_10KHZ 1
int ledPin = 13;                // LED connected to digital pin 13
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  pinMode(8, OUTPUT);      // sets the digital pin as output
  cbi(TWSR, TWPS1);
  cbi(TWSR, TWPS0);
  TWBR = ((CPU_FREQ / TWI_FREQ) - 16) / 2 / PRESCALER_10KHZ;
//  delay(10);
  Wire.beginTransmission(0x8); // transmit to device #xx
  Wire.send(0x28);           // sends cmd byte  
  Wire.send(0);              // sends one byte  
  Wire.send(0x0);              // sends one byte 
  Wire.endTransmission();    // stop transmitting
 
  Wire.beginTransmission(0x8); // transmit to device #xx
  Wire.send(0x20);           // sends cmd byte  
  Wire.send(0);              // sends one byte  
  Wire.send(0xf);              // sends one byte 
  Wire.endTransmission();    // stop transmitting
//  delay(10);
}

int y;
void loop()  
{
  asm("cbi 0x5,0\n");  // strobe LDAC
  asm("sbi 0x5,0\n");
  Wire.beginTransmission(0x8);  // transmit to device #xx
  Wire.send(0x18);              // sends one byte  
  Wire.send(y>>8);              // sends one byte  
  Wire.send(y);                 // sends one byte  
  Wire.endTransmission();       // stop transmitting
  y=y+100;
}


17-june-2009,

The universe is being difficult again.
I now have a whole family of arduinos. I decided to standardize on 5 Volt mega-328 for my network.
The arduino IDE works ok for basic stuff but much of what I want to do I've already done for a commercial project. This code is largely in assembler and some GCC (winavr). In particular I already have my own bootloader/monitor which amongst other things allows firmware upload via TWI.

So I want to reprogram the FLASH with my own code (ie not the arduido boot loader).
This is where it gets frustrating.
I have two programmers and have now installed about five different lots of ISP software and none support the mega-328.
In the past I've manged to fudge things but the 328 looks like it may be fundamentally different from other types in some way.

It appears avrdude may support it but no windows versions as far as I could see (found it see below). Switching to linux would be a pain because my IDEs are windows based and I will have to modify and dedug my code for the new processors as I've only written it to run on mega128 and mega8.

The 328 is fairly new so the next version of any of the ISP programs is likely to support it - but I want it now or sooner.

17-june-2009 3am,

I did get avrdude to run. There is a .net GUI plus the avrdude.exe prog needed. Links can be found here...
http://www.geocities.jp/arduino_diecimila/bootloader/index_en.html
I did not attempt the bitbang mode which is featured on the page.

In short it does support the 328 but it seems unable to open the printer or USB port on my computer.

http://www.ladyada.net/make/minipov2/make.html

Later,

I still can't get it to work even after running "install_giveio.bat". I've ordered a USB Pocket AVR Programmer from SF.
It turns out avrdude was already installed as part of winavr.

eddie


Created by eddie. Last Modification: Friday 19 of June, 2009 16:39:37 AEST by eddie.

Main Index

Switch Theme

Shoutbox

System Administrator, 13:56 AEST, Sun 07 of Aug, 2016: upgrading to tiki 15.2
eddie, 19:31 AEST, Sat 06 of Aug, 2016: This website is now served from Brisbane - in a Binarylane cloud.
System Administrator, 16:07 AEDT, Wed 06 of Mar, 2013: More f'n spam. No more anon posting from now on.
Anonymous, 18:44 AEDT, Mon 04 of Mar, 2013: deleted
Anonymous, 08:36 AEDT, Sun 03 of Mar, 2013: Very nice site!

Last-Visited Pages

Online Users

52 online users