Analogic ping how Outputs doesn't work

Hello, I am new. I put the analogs pins A0,A1,A2,A3,A4 how OUTPUTS. A0 and A1 function perfectly when I assign them values with the function analogWrite(A0, 0),analogWrite(A1,0) but de A2 and A3 pings with the same function doesn’t work.

I solved this didn’t use pin A2 and A3 and use A4 and A5. But someone Can tell me how I need to do to use A2 and A3. Thank you.

@YuliemAlavez, so is your problem solved then?

No really. I need use the pin A2 and A3 but this doesn’t respont to analogWrite

@YuliemAlavez, analog pins A2 and A3 do not support PWM output. If you read the documentation, it says:

This term is misleading and misused but is widely adopted in the Arduino community. The pins that are set to output an analog value don't actually output an analog voltage but rather produce a PWM signal whose duty cycle can be varied thus varying the total average power of the signal. On the Core, the PWM signals have a resolution of 8 bits and run at a frequency of 500Hz.
Having said that, the user can send analog values to the pins using the function analogWrite().

This feature is only available on the following pins: A0, A1, A4, A5, A6, A7, D0 and D1.

2 Likes

Hi @YuliemAlavez

Pins A2 and A3 do not have PWM output capability on a Core.

Here is the Analog Outputs section of the hardware datasheet:

This term is misleading and misused but is widely adopted in the
Arduino community. The pins that are set to output an analog value don't
actually output an analog voltage but rather produce a PWM signal whose
duty cycle can be varied thus varying the total average power of the
signal. On the Core, the PWM signals have a resolution of 8 bits and run
at a frequency of 500Hz.
Having said that, the user can send analog values to the pins using the function analogWrite().
This feature is only available on the following pins: A0, A1, A4, A5, A6, A7, D0 and D1.

1 Like

Yes it’s true. Thank you.

Yes it’s true. Thank you

1 Like

@bko:
Is it possible to change frequency to any other values instead of 500 Hz?

Hi @hemanthvasista

In theory yes, you could change the timer for the interrupt that makes it 500Hz but there is no public API in Particle to do that. Other pins would be effected since the timers are shared over a group of pins. You would have to dig into the ST32F manual a bit.

A standard servo will not work on other frequencies so you must have some other application in mind. If you want a true analog output, Photon has that.

I know that @peekay123 has a lot of experience with timers on this chip, maybe he can provide an easy way to set the PWM frequency.

1 Like

@hemanthvasista, @bko, using Tone is essentially a variable frequency PWM output. I will be working on an enhanced timer library which will expose more timer capabilities. The fact remains that timers on the STM32 work on a clock “tree” which means output pins are often tied to the same root timer. So changing the PWM frequency on a single PWM pin may also affect other pins tied to the same timer. The new library won’t get around this but will offer as much flexibility as possible. :smile:

2 Likes