• 0
Sign in to follow this  
VCSEL

Chipkit Max32 analogWrite pins

Question

Hello:

I am trying to better understand the functionality of the Chipkit Max32 board with respect to the analogWrite command. I have been testing pins A4, A5, 21, 23, 44 and 45 using the anlogWrite function.  I am testing each pin separately, i.e. one at a time. I have the pin connected to ground through a 180Ohm resistor and monitoring the voltage across the resistor using an oscilloscope.  I am using the following code changing the pin number in the analogWrite for each pin:

void setup() {
Serial.begin(9600);
}

void loop() {
for (int i=0;i<256;i++){
  analogWrite(4,i);
 delay(5000);
 Serial.print(i);
 Serial.println(""); }
}

I am using the delay(5000) command to give me enough time to monitor and measure the oscilloscope value and the Serial.print function to know where I am in the code execution.

When I test the A4 and A5 pins, I measure 0V, regardless of the value written with the analogWrite.  When I test the 21, 23, 44 and 45 pins the voltage is 0 until a value of 127 is reached. above 127 the voltage is 3.3V., constant.

Do I need to initialize any other values for the analogWrite to function properly?  

Thank You 

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Hi VCSEL,

I apologize for not getting back to you sooner.

The reason the pins 21, 23, 44, and 45 are not responding to the analogWrite function is because they are not pins capable of analog outputs (they can only do digital output). You would instead need to use the PWM capable pins (listed here in the reference manual) which are pins 3, 5, 6, 9, or 10 (nicely underlined on the silk screen).

As for the two analog pins, all of the analog pins A0-A11 are just analog inputs, not outputs. They can do digital output (which explains the behavior you're seeing, once it gets above the halfway point it "turns on"). You have to use the PWM pins to get actual analog output.

Let me know if you have any more questions.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Hi:

Thanks for the reply.  Your comment about the underline helped. The pin numbers on my board are close to the socket and I had completely missed them, but your comment made it all clear.  My circuit is working as designed. Thanks for the help!

Share this post


Link to post
Share on other sites
  • 0

Might require pin assignment and variable designation in assembly.

I have had to do this on some of PIC legacy micro-controllers.

Best, M

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this