Port B - Pin 11 voltage decaying instead of square pulse profile

I am trying to achieve high rate pulsing on PortB (pins 8 thru 13) on an Arduino Uno R3.
After giving DigitalWrite a try, decided to go with direct port manipulation.
Ideally, I would like to get up to 10kHz.

So, I write a 6 bits on PortB, with the goal of pulsing pins 9 and 11 at the same time.
First they go High, then they go low.

While troubleshooting the code, noticed that while I am getting a nice square signal/wave on Pin 9, what I get on pin 11 is more like a decaying voltage. I will try to post images showing the signal I am reading on the pins. Any idea why this is happening?

Following is the code;

int prate;
int stepdur;

void setup() {

DDRB = DDRB | B000011; //The Port B Data Direction Register - read/write. This is a safer way of setting Digital Pins 8 and 9 as outputs
                   // without changing the direction of any of the other pins on Port B (Port B: D8 thru D13) 


void loop() {
prate=1000; //Hz per pin

for (int i = 0; i<= 1000; i++) {
  PORTB |= B001111; //this updates PortB by turning on Pins 8,9,10,11
  PORTB &= B110101; // is b110101 This updates PortB by turning off only Pin 9,and 11


DDRB = DDRB | B000011; pins 8 and 9 are outputs, others are inputs :wink:

Oh... ooopppsss... Thanks.
I thought 10 thru 13 could also be designated as outputs. No?
Gotta read the manual I guess. :slight_smile:

DDRB = DDRB | B001111; // 8, 9, 10, 11 are now outputs

Read this:


I thought 10 thru 13 could also be designated as outputs. No?

Yes, they can be... but you didn't. :slight_smile:

Yeah yeah.... I see it now. Hah hah.
I fixed it and it all works. Great.
Thanks a ton for the quick response.
I am a bit of a noob.
Now onto playing with Serial TX/RX.