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
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!).
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.
??
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
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, 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.
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?!!
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 ).
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.