Hello,
I don't know how I can control/tune the value of the amplitude in the applied PWM as follows:
from pyb import Pin, Timer
p = Pin('X1') # X1 has TIM2, CH1
tim = Timer(2, freq=1000)
ch = tim.channel(1, Timer.PWM, pin=p)
ch.pulse_width_percent(50)
Amplitude/PWM
-
- Posts: 463
- Joined: Wed Apr 08, 2015 5:19 am
Re: Amplitude/PWM
Digital pins are either on (+3.3V) or off (0V). That's what "digital" means. PWM just modulates the duty cycle of the square wave that results from switching a digital pin on and off at a certain interval. The amplitude of the square wave, i.e the difference between the on and off level stays the same always.
But you can easily change the voltage level using resistors.
But you can easily change the voltage level using resistors.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Amplitude/PWM
@meldiwin The point of PWM is to create a signal whose average value is proportional to a supplied number. It assumes that the signal is applied to a hardware device which responds to that average. This could be a low pass filter, or something like a DC motor. So if you set the pulse width to 50% the average amplitude is 50% and the motor runs at half speed. Assuming that the motor would run at full speed if it were supplied with 3.3V.
If your motor required 12V to run at full speed then you'd need some electronics to boost the 0-3.3V levels to 0-12V, and probably to supply higher currents.
So you need to clarify what you mean by the "amplitude" of a PWM waveform. Its digital levels or its mean analog percentage of full scale.
If your motor required 12V to run at full speed then you'd need some electronics to boost the 0-3.3V levels to 0-12V, and probably to supply higher currents.
So you need to clarify what you mean by the "amplitude" of a PWM waveform. Its digital levels or its mean analog percentage of full scale.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Amplitude/PWM
Thanks for replies:
Actually I am supposed to send a voltage square signal ranging from 0.5 to 2.5 V ( voltage amplitude) with low/high frequencies. In that case I dont know whether I have to send 60.6% for having two volts, or I have to go to the other solution using resistors?.
Actually I am supposed to send a voltage square signal ranging from 0.5 to 2.5 V ( voltage amplitude) with low/high frequencies. In that case I dont know whether I have to send 60.6% for having two volts, or I have to go to the other solution using resistors?.
- Attachments
-
- squaresignal.png (11.09 KiB) Viewed 4765 times
Re: Amplitude/PWM
For this square signal, it supposed to be dynamic values of amplitude and frequencies which submitted to my systems at different time, so I dont think that using resistors alone could help. I am expecting that I can directly send 1V, 1.5,2V maximum 3V from the pyboard to my system, can I do that?.
Re: Amplitude/PWM
You can do that with the DAC, but not with generic GPIO pins.
Re: Amplitude/PWM
You can also use am RC circuit like this article shows https://www.instructables.com/id/Arduin ... analog-DC/
Just don't expect to sink any serious current.
Just don't expect to sink any serious current.
Re: Amplitude/PWM
You can modulate the DAC output with the PWM.
1. Connect a resistor, say 10k to the DAC pin. The other end will be your output.
2. Connect a MOSFET, say 2N700p - S to GND, G to PWM and D to output end of resistor.
When the PWM is high the MOSFET will be on and drive output to 0V. When PWM is low the output will be equal to the DAC output (between 0 and 3.3V) as long as you have a high impedance load.
Use (100-D.C.)% due to the inversion by the MOSFET.
1. Connect a resistor, say 10k to the DAC pin. The other end will be your output.
2. Connect a MOSFET, say 2N700p - S to GND, G to PWM and D to output end of resistor.
When the PWM is high the MOSFET will be on and drive output to 0V. When PWM is low the output will be equal to the DAC output (between 0 and 3.3V) as long as you have a high impedance load.
Use (100-D.C.)% due to the inversion by the MOSFET.