SPI and PWM from the same pin at the same time ?!!

i have NRF24 module which communicate through SPI and i need to use all PWM pins on the arduino uno include pin 13 and 9 which is used for SPI, so can i use it as PWM and SPI at the same time?

other question do i have to use optocoupler when i connet ESC for run brushless moter through arduino

so is there any way to convert an digital or analog pin to PWM??

You can use blink-without-delay style programming to create PWM pulses.

It's easier to program any pins for SPI instead of PWM. If you don't know how, and you also cannot find a software SPI library, you better use an Arduino Mega with more PWM outputs.

can i use it as PWM and SPI at the same time?

No you can't because they are totally different.

But I think you really mean can I use the PWM pin for both SPI and PWM at different times.

This is highly unusual but possible, it depends however entirely on the devices you are connecting to the pin.

Also as a presumed beginner it's very likely that you are approaching this from the wrong angle.

Does the NRF24 have a "select" pin? If so it's just possible that you can force it to ignore any PWM signals. Conversely does the PWM device care if it gets some SPI-style signals, or if it does can you "select" that as well.

How about adding a cheap I2C PWM Module? €2,50 free shipping

PCA9685-16-Channel-12-bit-PWM-Servo-Driver-I2C-Interface-for-Arduino-Raspberry

Is the SPI speed of top priority? If not -> just shiftOut the data aka software SPI.

Are two outputs used with the same duty-cycle? For example, you want to dim to leds to the same level when on but control them individual. If yes -> connect anode of both leds to a PWM pin (which sets the brightness) and the cathodes to two digital pins (to turn them on/low)

If the PWM used for something unimportant like a LED? If not, you could use software PWM. For a LED the frequency can be pretty low.

If you can't do one of the above -> use a expansion like the PCA9685.

As you can see, the answer really depends on what you really what to do. Devil is in the details and this is a classic example of a XY problem.

Similar problem here... Using SPI library to interface with an AS5048 sensor, yet not using port 11 (MOSI), what can I do so I can use port 11 for PWM?

Noting.... Sorry.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html.

You would be better off starting your own thread, rather than rejuvenate an unresolved old thread.

What is your project that is using all the pins?

Tom... :slight_smile:

Hi Tom... thanks for the advice.

My project is to connect 2 brushless motors using L6234, these motors are equipped with an absolute encoder each, which I am connecting to using the SPI (CLK, MISO and ports 7 and 8 a Chip Select for the two encoders).

I need all 6 PWM as each motor uses 3. I am modifying the PWM to happen at high freq (higher than the standards 1 kHz).

Is there a way I can modify something to not use port 11 as the MOSI port (no MOSI at all, or change it to another non-PWM port such as 4)?

You can see part of the work Im doing on this video (pwm is at 1kHz in that video, so you actually hear a lot of noise) Brushless BLDC Motor Arduino Proportional Position Control Servo constant torque FOC - YouTube

Hi,
Brushless motors or servos?

Looks good, nice and smooth.

Will the UNO have the capability of all that PWM and encoder reading for 2 servomotors?

Tom... :slight_smile:

Juanpablocanguro:
Is there a way I can modify something to not use port 11 as the MOSI port (no MOSI at all, or change it to another non-PWM port such as 4)?

No, it's fixed in hardware.

You could use software SPI (aka shiftIn()) instead. But note it is slower.

Also note, you can't change the frequency of Timer0 without trowing off all normal timing done with millis() (and even delay()) and everything depending on that.

But do you really need 3 PWM per motor? Just like single phase, I would say you control IN1, IN2, IN3 from a digital pin and use a single PWM on all enables. But for that I know to little of controlling 3 phase motors with the L6234 to say for sure...

But do you really need 3 PWM per motor? Just like single phase, I would say you control IN1, IN2, IN3 from a digital pin and use a single PWM on all enables. But for that I know to little of controlling 3 phase motors with the L6234 to say for sure...

Brushless motors are 3 phase motors, they need the 3 coils to be energized following a sinusoidal wave, out of phase 120 degrees for coils A, B and C. therefore I cannot use PWM on enable line as this would send the same magnitude to all 3 coils.

These are Brushless Motors, that have been equipped with an absolute encoder, thus rendering all the hardware necessary to make a servo motor (if the programming is in place).

so, yes, I have now created a servomotor that uses brushles motors, absolute enconder with no mechanical restriction on turns, and a Proportional control law.

It can also vary the torque (and even create wha tI call "holding torque"), and ultimately be used as a haptic device... I actually have other examples of the same setup simulating a knob, that can be smooth in movement, feel oily (dampening), and even create a "notch" o many steps along its excursion, resembling some sort of mechanical generated notches on a selector.

I guess I will need to try the SHIFTIN approach or move up to the Due. It would just be so awesome to run all this from an Arduino UNO... I love pushing hardware to its limits.

The ultimate achievement: connect both motors together, so that when I move one, the other one copies (with a reduction or amplification factor if desired), yet if the second motor faces a restriction, it can be "felt" on the first motor, and viceversa... then you can replicate a "steer by wire" setup, in which your input on the steering wheel steers the wheels with a factor, and inputs to the wheels communicate back to the driver... all over wires! :smiley:

Hi,
@septillion, the OP is using the UNO as the PWM source for the three phases, the PCB between the servo and the UNO is a H-Bridge array.

L6234 is a THREE PHASE MOTOR DRIVER

The L6234 is a DMOSs triple half-bridge driver with input supply voltage up 52V and output current of 5A.

Tom... :slight_smile:

Going from a Uno to a Due just for more PWM is a bit overkill... If does offer more but yeah... You can also just use an external PWM driver.

Or go for modular and use a uC per motor and let them communicate. Also solves the timer0 problem.

@TomGeorge, yeah, forgot my thinking hat.