Go Down

### Topic: audio jack in to pwm  (Read 569 times)previous topic - next topic

#### dmitri_gorchev

##### Nov 23, 2020, 03:26 am
Hello all,

I posted earlier looking at code i had already written, but i was wondering if there was a code out that that already does what i need it to do.

So I need to take a analog input (this will be from a headphone jack so .5v peak to peak) and process that in a way way that would give me a pwm output that with a set duty cycle of 10%

That way I get a pwm signal (needs to be greater then 2v) with a set duty cycle, that has audio modulated frequency controlled by an audio input.

I know thats confusing but I really don't know what to do, i'm super bad at coding

#### DVDdoug

#1
##### Nov 23, 2020, 04:57 amLast Edit: Nov 23, 2020, 04:58 am by DVDdoug
The standard solution is to bias the input at 2.5V so you can read the AC waveform.   (The Arduino can't read the negative half of the waveform and it can actually be damaged by negative voltages).   There is a schematic at the bottom of

Quote
that would give me a pwm output that with a set duty cycle of 10%

That way I get a pwm signal (needs to be greater then 2v) with a set duty cycle, that has audio modulated frequency controlled by an audio input.
It's not really clear what you're trying to do...

#### Grumpy_Mike

#2
##### Nov 23, 2020, 03:36 pmLast Edit: Nov 23, 2020, 03:38 pm by Grumpy_Mike
Quote
that would give me a pwm output that with a set duty cycle of 10%
Yes.

Quote
That way I get a pwm signal (needs to be greater then 2v) with a set duty cycle, that has audio modulated frequency controlled by an audio input.
No.

You don't seem to understanf what a PWM signal is. It is always 0 to 5V and what changes is the ratio of the time spent high to the time spent low. This is known as the duty cycle.

Why on Earth do you want a PWM signal with modulated audio on it's duty cycle anyway?

See:- http://www.thebox.myzen.co.uk/Tutorial/PWM.html for what a PWM signal is.

#### dmitri_gorchev

#3
##### Nov 23, 2020, 07:14 pm
can arduino's only give a set voltage pwm signal? need a pwm signal because its controlling a large Tesla coil, and the igbt cant handle more then a 10% duty cycle. audio modulated so i can make my coil sing

#### DVDdoug

#4
##### Nov 23, 2020, 08:42 pm
How does your Tesla coil use PWM?   Does it run at power line frequency (50 or 60Hz)?   For example, you can't dim a regular AC light bulb with PWM.

Quote
can arduino's only give a set voltage pwm signal?
Yes.  PWM switches between 0 and 5V (assuming a regular 5V Arduino).    That's how PWM works...     At 50% (127 or 128) it's 5V half the time and zero half the time for an average of 2.5V.

PWM can be used to "simulate" analog to control the speed of a motor (because the inertia prevents the speed from changing instantly) or it can make an LED appear dim (because it's blinking too fast for our eyes to see).

The PWM frequency is normally fixed.   It can be changed but if that's done it's usually done once during setup() and doesn't change while your program is running.

It is common to change the PWM value 0 - 255 (=0 - 100%) while the program is running.

#### Grumpy_Mike

#5
##### Nov 23, 2020, 09:54 pm
Quote
audio modulated so i can make my coil sing
Well you can't do that with PWM.
While you can change the PWM frequency it is only in terms of large steps, not a continuum.
You don't need an Arduino or any other processor to get a variable frequency fixed width pulse. You just need a voltage controlled oscillator feeding into a monostable, so that would be just two NE555 chips.

Go Up