Tiny delay in digitalWrite causing some timing issues

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
magician13134
 
Posts: 1119
Joined: Wed Jun 13, 2007 9:17 am

Tiny delay in digitalWrite causing some timing issues

Post by magician13134 »

Hello everyone, I'm tweaking some code on a small project that I'm working to try to get it better than it is now. It's very simple, just an ATTiny85 using 5 IO pins to control LEDs. I wrote, compiled and uploaded the code in the Arduino environment so I'm simply using DigitalWrite to control them. However, when I want to flash them all at once, I just do five DigitalWrite commands in a row to turn them all off or all on, but you can actually see the LEDs turning off one by one, it's not quite instantaneous and it irks me. I was just wondering if there was a way to tell all of the pins to turn on or off in one command?

Also, speeding up the clock is not an option, it is a very power-conscious project. Thank you for any help.

User avatar
westfw
 
Posts: 2010
Joined: Fri Apr 27, 2007 1:01 pm

Re: Tiny delay in digitalWrite causing some timing issues

Post by westfw »

If you use direct port writes, you can turn a whole port worth of bits at one time (and on a tiny85, all the pins there are are on a single port...) It would look something like:
PORTB = 0x3F; // set all outputs HIGH.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”