A PWM signal generated by a PC

Thread Starter

Martino Chiro

Joined May 1, 2015
128
I needo to generate a (very slow) 0 -5V ramp signal in 30 seconds.
How can i get a PWM signal from a PC, suitable to be filtered and get the wanted ramp signal ?
Thank you for any help,
MartinoChiro
 

Picbuster

Joined Dec 2, 2013
1,058
Make a counter eq up to 999 and then reset to zero. This is your operating window.
start a second counter @ 0 and stop it when x% of 1000 is reached. x<=100%( it will start @ zero again)
second counter is output window.
The clock at the counter will define the pwm repetition rate.
Extreme simple program.
Picbuster
 

crutschow

Joined Mar 14, 2008
38,526
You could generate a wav file with the desired PWM ramp modulation.
The audio card then only has to handle the PWM carrier frequency.
Anyone know a good way to do that?

You could, of course, record the desired PWM signal from an external PWM generator circuit.
 

crutschow

Joined Mar 14, 2008
38,526
What frequency?
For a 30 second ramp it could be low, well within the audio band.
I would try a few hundred Hertz.
That way the PWM signal will still look like a reasonable PWM square-wave (assuming a 20kHz upper frequency limit on the audio output).
 

Picbuster

Joined Dec 2, 2013
1,058
Hello Picbuster,
how can i use the RTS (Request ti Send) in a serial port ?
two ways:
simple one open the serial port (or the emulator) and use depending on compiler port(n).rts=On; // (n) portnumber
when using the old VB6 use MSComm1.RTSEnable = True ' or = False

more difficult
Look at address from the serial port ( or emulation for USB) find the status register and select the RTS bit and set high or low.

Picbuster.
 

crutschow

Joined Mar 14, 2008
38,526
two ways:
simple one open the serial port (or the emulator) and use depending on compiler port(n).rts=On; // (n) portnumber
when using the old VB6 use MSComm1.RTSEnable = True ' or = False

more difficult
Look at address from the serial port ( or emulation for USB) find the status register and select the RTS bit and set high or low.
So that will generate a PWM signal?
 

Reloadron

Joined Jan 15, 2015
7,891
I needo to generate a (very slow) 0 -5V ramp signal in 30 seconds.
How can i get a PWM signal from a PC, suitable to be filtered and get the wanted ramp signal ?
Thank you for any help,
MartinoChiro
You went from a saw tooth waveform to PWM? Which do you want? I doubt you will get a 5 volt signal from the audio out of a sound card. You want to ramp up from 0 to 5 volts over a 30 second period, then what? Remain at 5 volts or return to zero? If return to zero over what period? Return to zero would be triangular waveform.

Ron
 

Colin55

Joined Aug 27, 2015
519
This whole thing is so vague and so improbable, that we are wasting our time on the request.
It would be better to go and start feeding the 10 million starving Africans.
 

Picbuster

Joined Dec 2, 2013
1,058
Pls find a simple example of pwm on pc

Place the following in a PC timer interrupt routine eq 1 mS.
//--------------------- PWM ----------------------------------------------------
PWM_Set.PWM_Gate++;

if (PWM_Set.PWM_Gate>1000) // define window 1000
{
PWM_Set.PWM_Gate = 0;
}

if (PWM_Set.PWM_Gate<PWM_Set.PWM_Output) // PWM_Set.PWM_Output = value wanted
{
RTS_Pin = On;
}
else
{
RTS_Pin = Off;
}
//------------------------------------------------------------------------------

make a loop in main updating PWM_Set.PWM_Output++; as function of wanted time span.
Picbuster
 

Reloadron

Joined Jan 15, 2015
7,891
The code sample was written in C. It would be similar to the code used to program a micro processor. I am not real sure it would work and here is why. I tried this years ago using the Comm (RS 232) Port. The main problem was the comm port relies on Task Switching of the operating system of the PC. Typically 11 to 16 mSec. The best rate I could get was 100 Hz which is slow. When I increased my clock (timer speed) I ended up with severe jitter and a useless signal. So good luck trying to use the RTS pin or the DTR pin for a PWM output. Additionally during a few of my experiments the actual RS 232 port outputs swung between -11 and 11 Volts. When I used a USB to RS232 converter my converter was about -5 volts to 5 volts for RTS or DTR Enable being True or False. Anyway, you can try this using C but I do not see it working for the reasons mentioned.

You have not answered anyone's questions as to exactly what your goal is?

Ron
 

Thread Starter

Martino Chiro

Joined May 1, 2015
128
Thank You Reloadron,
interesting answer.
I'd like to get a slow ramp signal from 0V to 5V in 30sec, then return to 0V :
or istantaneously and the repeat the slow ramp to 5V
or with a slow down ramp, from 5V to 0V in 30 seconds.
The last one is preferred.
And then the cycle repeats itself.
 

Sensacell

Joined Jun 19, 2012
3,785
Basically, windows task scheduling makes timing at this level a hopeless mess.
If you want to move forward with finding a solution, dish the dirt on what you are doing, probably get some clever ideas in a jiffy.
 

wayneh

Joined Sep 9, 2010
18,108
I'm with @crutschow. I don't see why you can't use the audio port. It would be trivial to program a sound file to send whatever waveform you want. If the voltage isn't quite right, just add a buffer in between, maybe a simple comparator. But depending on the downstream filtering you mentioned, you may not need that.
 
Top