Control multiple digital pins

Hello everybody,

Is it possible to generate 40 KHz square waves from multiple digital pins with Arduino (Uno or MEGA)? while be able to adjust a phase shift to each pin? (each pin generates wave at the predefined delay or phase )
What is the maximum pins that can be controlled in this way?
Thanks

That just requires sending a digital HIGH or LOW at the right time to the right pin.

lightt:
What is the maximum pins that can be controlled in this way?

All of them.

Why?

Other than making a jammer (like the idiot yesterday), does any one know why you would want to do this.

Dear KenF,

Does it need direct pin manipulation or can it be done by codes like digitalwright() ?
could you please give some clue for the coding ?
thanks

@op WHY do you want to do this?

Mark

Dear holmes4,

I wan to send them into 8 transducers for beam steering.??
So each transducer needs a certain delayed signal (40khz is fixed)

Can you provide a link to what you are trying to do. You are the second to ask for "beam steering" this week. He was given the reply that yes it can be done (well he did not ask how!).

Is this some type of school project?

Mark

Dear Mark,

Yes it is a type of school project.
It is about to send delayed square wave signals (50% duty cycle, 40KHz) to different transducers to mimic phased-array transducers.
??

OK fine, as it for your education then you only get hints and tips here. But you would do well to post the full question/spec.

First hint - define what you want and do it clearly - no hand waving!

Second hint - how much work do you need the Arduino/AVR ? to do does it need to calc the phase shift using the sin() function?

Third do you need a continuous wave or can you you a pulse

Forth - what's the Receiver?

And my question - to what end are you doing this?

Mark

Thanks for responding Mark,

Please find in attachment the depicted illustration of what i am going to do :

  • there is no need for sin() calculations, just define a certain delay for each square wave at corresponding pin

-Continuous square wave

-Receiver of the signals are 40 KHz transducers

  • there is no need for sin() calculations, just define a certain delay for each square wave at corresponding pin

So how do you intended to steer the beam at run time?

What's running the Rx'er?

And still why/who for?

Mark

So how do you intended to steer the beam at run time?

Steering is at one fixed point, no need to change the steering angle.

What's running the Rx'er?
There is no receiver, I just want to transmit the waves to each pins, at measure the beam by another transducer at the steered point

And still why/who for?
What do you mean why/who for?,cit's an school project with the Ardino

Mark

[/quote]

Hi,
I think we are getting mixed up with transducers and Tx and Rx units.
A transducer is a Tx, it converts electrical to pressure/sound energy. In this case ultrasonic.

Now how are your going to detect these signals, and determine which of the 8 transducers you are detecting the signal from?
What are you using for the transducer?

Tom.... :slight_smile:

Tom, I don't know a lot about phased array but I do know it's nonsensical to ask "which transmitter" The 8 transducers behave as a single transmitter and produce a single waveform in the medium.

Guys,

I think we are deviating from my main problem,
There is no detection here, it is just driving some transducers with delayed signals to make them transmit.

So the only issue here is:

How should I do the port manipulation in ARDUINO MEGA2560 to generate 8 (40 KHZ square wave) from 8 pins such that each pin implemented with a certain delay (order of us).

By now, I know that I cannot dimply do this by library codes like digitalWrite(), because I miss the timing and waves have jittering shape. So the best way as I am concerned is to directly change the bits in hardware.
But I don't know how to do this?!!

Thanks

If you have a signal of 40khz then you have one full cycle every 25 microseconds. This would involve 1 level shift every 12.5 microsecond.

If you have eight of these signals offset by the same angle, you'd need one transition every 1.5625 microseconds.

I think this is a problem. Not least because micros() on the arduino has a granularity of 4. I'm not sure that the arduino is the tool for this project. ( at least without some hardware support ).

Thanks for the response KenF,

But what if I used different timers of the Arduinomega2650 (5 clock timers ) ?
I mean is it possible by manipulating the timer/counter bits? without using micros() code?

If you used port manipulation to output your pin states you could possibly just about do it. The code would basically be just a shift (with the carry put back into the LSB) and then a port write. Even this, though, would probably necessitate you modifying the onboard oscillator to get the timing right.

I think a more practical approach would be to use hardware to generate a delay line. That way you'd only have to feed one of the transducers and the others would just naturally follow. Mind you, by the time you've done that, with a bit of modification, you wouldn't even need to feed the first one with any signal. That could be achieved with hardware too.

"The code would basically be just a shift (with the carry put back into the LSB) and then a port write.."

How can I do this?
Do you have any sample code?

Maybe something like this?
micros() having 3-4uS resolution might be the killer.

byte portArray[] = {0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000,};

currentTime = micros();
if ( (currentTime - previousTime)>=duration){
x=x+1;
if (x==8){x=0;}
PORTD = portArray[x];
previousTime = previousTime + duration;
}