then i should be getting a steady 3.3 volts for 4 milliseconds. If i put that in an infinite loop then i should be getting a 3.3 volt steady signal. is this assumption correct?
One more question.
If i want to send a signal for 100 or 200 microseconds just once then how would i use it. The timer or sleep methods only have milliseconds.
then i should be getting a steady 3.3 volts for 4 milliseconds. If i put that in an infinite loop then i should be getting a 3.3 volt steady signal. is this assumption correct?
[/quote]
Why don’t you set the digital IO pin to TRUE and be done with it?
Also, I don’t think you understand what you’re seeing on the end of the earlier test you were doing. You can only set a digital IO pin to low or high, which means you get 3.3v or 0v. If you switch that really fast, and vary how long on and how long off, you get the appearance of a reduced voltage. You don’t get a reduced voltage, because at any point in time it is either 3v3 or 0v, there is no 2.2v for instance. What you see if you average it out is you end up with 2.2v. A typical multimeter will only show you 2.2v, not a quickly toggling 3v3 to 0v etc.
You only need to setup a PWM once, unless you want to change the period or the duty cycle. Don’t call SetPulse with the same values in a loop, it doesn’t make sence.
It looks idd like you are looking for OutputCompare instead.
On Time (High time): 300 microseconds
Off Time (0 volts): 100 seconds
The High time power must be whatever i set (say 1 volt or 0.5 volt, etc…). i.e. during high time, the amplitude must not be more than the set 0.5 volt or 1 volt.
then you cannot use a digital output on a Fez. Digital IO outputs 3v3 or 0v. You’ll need to also involve analog electronics and do a voltage divider of some form to reduce that, but it’s going to mean you won’t get the nice sharp on/off steps.
What are you trying to achieve? What has this specific requirement?
You can have an analog output, f.e. from a DA converter and switch the analog voltage with a PWM signal. But it would be good to know why you need that custom voltage.
I need a pulse (on time and off time) ranging from 200 micro second to 20 milli seconds. This will power a laser diode. The power and time will be controlled from a 4.3 inch touch screen.
Please let me know the hardware i need to use to achieve the above requirement. I am a .NET Architect and new to embedded systems.
You can’t power you laser diode directly from an IO pin. You need an external power source. (And maybe even a constant current source). Once you have the source, you can switch it on or off with a FET controlled from a digital PWM output.
Sorry i missed to mention that. I have a DAC that will power the laser diode. All i have to do is to give it a signal with varying power (0-3.3 v) so that the power gets translated into 0-30 watts f.e…
All i need is to generate a pulse with a fixed power,ontime and offtime.
You have a period of 2800*1000 nanoseconds = 2800 microseconds or 2.8 milliseconds.
The period defines the PWM frequency (Freq = 1 / Period), in this case PWM frequency will be 357Hz (1 / 0.0028).
The second number defines the ON time, you want 2 milliseconds, which is 2000 microseconds or 2000 * 1000 nanoseconds.
The OFF time is automatically the time (Period - Hightime). In this case 28001000 - 20001000 = 800*1000 nanoseconds or 800 microseconds as you requested.
Maybe this snippet makes it clear:
int ontimeMicrosec = 2000;
int offtimeMicrosec = 800;
pwm.SetPulse((ontimeMicrosec + offtimeMicrosec ) * 1000, ontimeMicrosec * 1000);
To emphasise, you cannot control voltage from the pwm, other than to have it turn high (3.3V) or low (0V). No other Voltage values can be achieved.
With PWM you can only control duration of the pulses. If you also need to control the output voltage you need to have a separate circuit that outputs desired voltage, then control that constant voltage output with the PWM pulses.
In other words, the PWM can only give you timing control. The voltage level control must be separate.
Can you show us the datasheet of that DAC? Because I think you’re searching for the wrong solution.
Or the ‘DAC’ is just a current source, and you need to feed it a PWM signal. Or the ‘DAC’ is a translator from analog signal to PWM signal for the laser diode. I would be surprised if it really needs a mix of those two…