PWM Making..

Hi
I used arduino ske. to develop atmega32
by this github info:

by flashing .hex file that compiled to temp file
like this :
C:\Users\Arashsoft\AppData\Local\Temp\arduino_build_95211\sketch_jan06c.ino

But the problem is PWM waves doesn't work
they work like a digital pulse

here is the code:

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:


  int i =0;

  while(i<1022)
  {
    i++;
    analogWrite(13,i);
    delay(20);
  }
}

and setting :

the output just flashing not fading

like this

0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,,1000,1000,1000,1000,0,0,0,0,0,0,0,0

Do not cross-post. Other post removed.

Can you clarify what this means:

arashsoft:
0,0,0,0,0,0,0,,0,0,0,0,0,0,0,0,,1000,1000,1000,1000,0,0,0,0,0,0,0,0

means? Where are you getting those numbers from, and what to they represent?

If you look at the MightyCore pinout diagram for the Bobuino variant:


You can see that pin 13 does not support PWM on the ATmega32. It's only PWM on ATmega1284. The PWM pins on ATmega32 are 7, 8, 9, 30, and 31.

pert:
If you look at the MightyCore pinout diagram for the Bobuino variant:
GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535


You can see that pin 13 does not support PWM on the ATmega32. It's only PWM on ATmega1284. The PWM pins on ATmega32 are 7, 8, 9, 30, and 31.

OH OH

You mean PD5 PD6 PD7 .....

in Bobuino Pinout

Thanks
///////////////////////////
But i Used PD6

Still have problem

Some thing like Blinking happend

not Fading

By the way

Let me share my wiring :

I even Check hex file with proteus it is not PWM

It is sth like Blinking

Here is the film that how it works:

https://ufile.io/uur40

OR

Watch ONLINE

Watch Online

BJHenry:
Can you clarify what this means:means? Where are you getting those numbers from, and what to they represent?

I read BY another arduino Reading
and Showing in Serial

it was sth like this

I mean it works like blink not fading...

arashsoft:
OH OH

You mean PD5 PD6 PD7 .....

in Bobuino Pinout

Here on the Arduino Forum (and any other Arduino-specific site), you can assume when someone specifies a pin number on a microcontroller that they are talking about the Arduino pin number.

arashsoft:
But i Used PD6

Sorry, I meant pins 7, 8, 30, 31 (PB3, PD5, PD4, PD7). PD6 doesn't have PWM either on the ATmega32.

pert:
Here on the Arduino Forum (and any other Arduino-specific site), you can assume when someone specifies a pin number on a microcontroller that they are talking about the Arduino pin number.
Sorry, I meant pins 7, 8, 30, 31 (PB3, PD5, PD4, PD7). PD6 doesn't have PWM either on the ATmega32.

For god sake .... it is the 34th that i tried

It works on Proteus

Thanks

but i have a question

if the code is :

analogWrite(30,200);

and in another arduino i used A2 to Read

int a = analogRead(A2);
Serial.println(a);

in the serial i will receive some numbers near 200

is my text correct?

will I receive ?

199
198
200
201

some number near 200

Despite the name, analogWrite does not provide an analog output on the ATmega32. It provides a PWM output, which is the pin going from high to low very fast over and over again. What you're controlling with analogWrite is how long the pin is high on each cycle. More information on PWM here:

You can turn PWM into an analog output with an RC filter.

Also, keep in mind that analogWrite on the ATmega32 is 10 bits (0-1023) while analogRead is 8 bits (0-255). So even if you do turn it into an analog output, writing a 200 will not cause you to read a 200.

pert:
Despite the name, analogWrite does not provide an analog output on the ATmega32. It provides a PWM output, which is the pin going from high to low very fast over and over again. What you're controlling with analogWrite is how long the pin is high on each cycle. More information on PWM here:
https://www.arduino.cc/en/Tutorial/PWM
You can turn PWM into an analog output with an RC filter.

Also, keep in mind that analogWrite on the ATmega32 is 10 bits (0-1023) while analogRead is 8 bits (0-255). So even if you do turn it into an analog output, writing a 200 will not cause you to read a 200.

OHHHHHH

Do you mean in arduino(ex:uno) we have RC filter Ready that works auto

but here i should provide this..

WTF

So you mean If i write x(in 10 bit)

i will read Y(in 8 bit)

which is

Y= (255*x)/1023

Thanks.....

pert:
Also, keep in mind that analogWrite on the ATmega32 is 10 bits (0-1023) while analogRead is 8 bits (0-255).

Isn't that back asswards?

arashsoft:
Do you mean in arduino(ex:uno) we have RC filter Ready that works auto

No. There's no RC filter on the Uno. The pins are connected directly to the headers with no filters. analogWrite on an Uno also outputs a PWM signal. When used with an LED, it looks like an analog voltage, but it's actually the LED turning on and off faster than your eyes can see. The brightness is controlled by how long the LED is on in each cycle.

Willpatel_Kendmirez:
Isn't that back asswards?

Correct. I swapped the two. analogRead is 10 bits, analogWrite is 8 bits. Thanks for pointing that out.

arashsoft:
So you mean If i write x(in 10 bit)

i will read Y(in 8 bit)

which is

Y= (255*x)/1023

You got it! There's some endless debate here about whether it should be 1023 or 1024 but let's not get into that.

But
Look :

in uno :

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
 pinMode(9, OUTPUT);
}

void loop()
{
  // put your main code here, to run repeatedly:
analogWrite(9,200);
int a =analogRead(11);
Serial.println(a);

delay(20);
}

in serial I read 300

(300 as you said because of Resolution ( 8 bit Write 10 bit Read)

but in Atmega32 and another arduino (arduino for reading analog);

But in here the result is not ok

Let me

Make it clear

I write my project in simple way

There are 2 atmega

4 input
1 output

I want to convert 4 input statue to one output signal

Input 1 is A
Input 2 is B
Input 3 is C
......
Output is O

If (A==1)
analogwrite(O,30)

else
If (B==1)
analogwrite(O,60)
......
else
analogwrite(O,0)

/////

The input num is 20 really

I just give an simple example about what i should do

Proccesing 20 input
Write statue in one(max 3 ) analogsignal
**
20 is statue A
40 is statue B
....
**
Read statue by another atmega16
By analyzing that one(max3) analogwave

0<x<9 Nothing
10<x<22 A
30<x<42 B
........

There is no rc filter on the uno. When doing analogRead on pwn signal, you should get ~0 and ~5v. But, you may see values close to what youd expecg with an RC filter due to parasitic capacitance and the like...

Did you remember to burn bootloader on the atmega32 to make it run at 8MHz instead of 1MHz like a virgin atmega does? (Be sure to select internal oscillator if not using crystal) - if its outputting pwm at 1/8th the frequency youd be more likely to see the on/off via analogRead on a different arduino monitoring it.