SteveChamberlin

Member Since: March 30, 2008

Country: United States

  • Good point. If you unroll the loop a little, you can get intervals of full-speed LED blinking: 62.5ns off, 62.5ns on, blink frequency of 8 MHz. So if there was any doubt, yes the Arduino really can perform a single operation in 1 / 16 millionth of a second!

    Here’s my test program, no assembly language required:

    void setup() 
    {
      pinMode(13, OUTPUT);
    }
    
    void loop() 
    {
      char pb5on = 1 << 5;
      char pb5off = 0;
    
      while (1)
      {
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
        PORTB = pb5on;
        PORTB = pb5off;
      }
    }
    

    And logic analyzer output to show that it really does toggle the LED every 62.5 ns:

    Saleae logic analyzer screenshot

  • You’re right that you can’t toggle an LED at 16 MHz using the Arduino libraries, but that’s not the hardware’s fault. It’s the result of using the Arduino libraries, which as jweather says, are not exactly optimized for speed. digitalWrite() is not a single instruction, but a call to a C function that does lots of checking and setup stuff before it actually sets the pin output. This makes it quite slow. In your example, there are no interrupts and no serial checking, so everything can be blamed squarely on digitalWrite(). :-)

    You overlooked one thing in your analysis, which is that when the program reaches the end of loop(), it must jump back to the beginning of loop(). This involves additional function calls in the Arduino library, and takes a small amount of time, and explains why your LED was in the low state longer than it was high. If you switched the low and high lines of your loop, you’d see that the LED was high longer than it was low. There’s nothing inherently slower about setting a pin low than high.

    I would encourage anyone who needs faster Arduino performance, or is just curious, to look at the source code for the Arduino libraries. Look at what digitalWrite() actually does. Read the Atmel datasheet for the ATMEGA328 chip. Read about direct I/O port manipulation here: http://playground.arduino.cc/Learning/PortManipulation . You don’t necessarily need to write code in assembly language to get fast performance. With a program like:

    void loop()
    {
      while (1)
      {  
        PORTB = 0;
        PORTB = 1;
      }
    }
    

    you should be able to get LED blinking performance much closer to 16 MHz.

  • Important note: this is a 250 mA power supply! As others have mentioned, the PTC fuse limits the output current to no more than 250 mA. It would be great if you could change the item description - calling it “1.5A max current” as shown above is misleading and confusing.

  • Mine died after sitting in a closet for a year. Anyone have experience repairing these? For a while I had to slap the case to make the temperature display turn on, and the air heat up. But now no matter what I do, I just get cold air blowing out, with nothing on the temperature display. Sounds like a loose connection or bad solder joint somewhere, but where?

  • Anyone have a good tutorial for how to solder SMD parts using this hot air station? Do you just point the nozzle at the part and go, or is it necessary to use another heater to preheat the board first, and follow a specific heating/cooling profile? Also can I get away with pre-tinning the pads with normal solder, instead of solder paste? The paste seems like a pain in the butt since it needs to be kept refrigerated, and I don’t want to keep it in the kitchen with my dinner, or pay distributors extra money to overnight ship it in a cool pack.

  • The CCV084 buzzer has a resistance of only 16 ohms– could somebody explain why it’s OK to connect it directly between two digital output pins, without a current-limiting resistor? When the buzzer is on, I would think it would draw 5V / 16 = 312 mA, which would damage the ATmega.

  • Ack! After two days of working nicely with 0x15 bias, I reset the board today, and the LCD appeared way over-dark. I changed the bias back to 0x14 and it looks perfect. What the heck?! I think there must be some temperature-sensing or temperature-dependence going on, so the same init values may produce good-looking results one day but not the next.

  • I found the LCD bias value must be set to 0x15 to get good constrast consistently.
    Using a 3V source, my LCD often worked OK using bias 0x14 like the other examples, but sometimes it would appear gray and faded. The fading would lessen if I touched the panel lightly with my hand for a few seconds, then let go, so maybe it’s a temperature-dependent thing?
    After writing a program to let me interactively adjust Vop, temperature coefficient, and bias, and experimenting with different values, I found that bias 0x15 worked much, much better than 0x14. I’m also using Vop 0xD0 and temperature coeff 0x04, but those don’t seem to matter as much.
    I also noticed an error that’s repeated in many of the examples:
    0x14, //set bias mode to 1:48.
    0x14 is not 1:48 bias. If you read the datasheet on the top of page 16, 0x14 corresponds to a bias of 1:40/1:34. If you want 1:48 bias as the comment says, use 0x13. The 0x15 value I’m using corresponds to 1:24 bias.

  • @Twiddler: Yes, it’s possible to write too fast. Check the write cycle timings in the datasheet. The enable signal can’t be cycled faster than 2MHz. Also after each command sent to the LCD, you have to wait until the busy flag is clear, or delay several microseconds to milliseconds (depending on which command).

  • As a noob designing my first PCB, I found this tutorial incredibly helpful. Restrings? Tenting? It’s all beginning to make sense. My first board is now off to BatchPCB. Awesome job, thank you!

No public wish lists :(