Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpPrograms › ( additional ) Software PWM

Page Index Toggle Pages: 1
( additional ) Software PWM (Read 4415 times)
06/09/08 at 15:57:41

thomsen   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 13
*
 
Hi all,
i need more pwm-outputs, is it posible to create a pwm signal by the wiring software?
I know that it should be possibe, but is it fast enought ?

Regards Thomas
 
IP Logged
 
Reply #1 - 06/09/08 at 16:04:54

Titus   Offline
Full Member
Wiring Soccer Robot!
Amsterdam

Posts: 176
***
 
I think it would be fast enough
digitalWrite(pin, HIGH);
delayMicroseconds(1);
digitalWrite(pin, LOW);

the only question is, how can you create a routine, that converts a input(0-1023) to a high low high low sequence?

Barragan?

P.S. typo in topic name:P
 

Check www.TeamVossius.nl for our Autonomous soccer robots!
IP Logged
 
Reply #2 - 06/11/08 at 18:02:09

Vaccumdiode2   Offline
Full Member
chicago, IL USA

Posts: 120
***
 
hello,
            I think you need a second delay after you drop it low.  In the delay you could use variables and by changing the delay you would change the pulse width.  

int width=1;
int inpin = 0;
int analogin=0;

void loop() {

analogin = analogRead(inpin);  // read the value of analog pin 0

width=analogin / 100;  // convert value from 1 to 1024 to 1 to 10

if (nalogin <= 99){
width=1
}
digitalWrite(pin, HIGH);
delayMicroseconds(width);
digitalWrite(pin, LOW);
delayMicroseconds(width);
}

You will have to run some tests to see what ion factor you want to use.  But this looks like a good place to start.  I'm Not sure what the PWM frequencey is.  I hope some could post it, it would be helpful to everyone.

Remember this is my thoughts on it and I could be wrong.

Vaccumdiode

 
IP Logged
 
Reply #3 - 06/12/08 at 15:38:27

thomsen   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 13
*
 
I have it working ...  Cheesy

Was no problem, i din't make much calulation and it works ok for me  Grin

Code:
void programm5() {

analogin = analogRead(1);

if (analogin <= 100){
digitalWrite(kanal1, LOW);
} else if (analogin <= 100 && analogin <=200){
digitalWrite(kanal1, HIGH);
delayMicroseconds(1000);
digitalWrite(kanal1, LOW);
delayMicroseconds(9000);
} else if (analogin <= 200 && analogin <=300){
digitalWrite(kanal1, HIGH);
delayMicroseconds(2000);
digitalWrite(kanal1, LOW);
delayMicroseconds(8000);
} else if (analogin <= 300 && analogin <=400){
digitalWrite(kanal1, HIGH);
delayMicroseconds(3000);
digitalWrite(kanal1, LOW);
delayMicroseconds(8000);
} else if (analogin <= 400 && analogin <=500){
digitalWrite(kanal1, HIGH);
delayMicroseconds(4000);
digitalWrite(kanal1, LOW);
delayMicroseconds(6000);
} else if (analogin <= 500 && analogin <=600){
digitalWrite(kanal1, HIGH);
delayMicroseconds(5000);
digitalWrite(kanal1, LOW);
delayMicroseconds(5000);
} else if (analogin <= 600 && analogin <=700){
digitalWrite(kanal1, HIGH);
delayMicroseconds(6000);
digitalWrite(kanal1, LOW);
delayMicroseconds(4000);
} else if (analogin <= 600 && analogin <=700){
digitalWrite(kanal1, HIGH);
delayMicroseconds(7000);
digitalWrite(kanal1, LOW);
delayMicroseconds(3000);
} else if (analogin <= 800 && analogin <=900){
digitalWrite(kanal1, HIGH);
delayMicroseconds(8000);
digitalWrite(kanal1, LOW);
delayMicroseconds(1000);
} else {
digitalWrite(kanal1, HIGH);
}
}

 




Thanx and greets Thomas
 
IP Logged
 
Page Index Toggle Pages: 1