analogWrite wont give me a continuous 3.3V , it chops down at 488Hz

Status
Not open for further replies.

laptophead

Well-known member
I am using a fairly simple DC motor controller. When I use analogWrite (R_Mot_FwdPin, 255); I was expecting a solid "high" but I get a lesser value.
I attached the scope reading of what I am getting.
If I replace that analogWrite with a digitalWrite HIGH, I am still not getting a solid high.

Anyone knows why?

Thanks
 

Attachments

  • ElechouseDriverStudyWithTeensy.ino
    911 bytes · Views: 67
  • analogWrite255.JPG
    analogWrite255.JPG
    90.9 KB · Views: 101
Wow defragster, that did fix it . 256 gave me a clean HIGH.

But then I wrote this;
digitalWrite (R_Mot_FwdPin, HIGH);
delay (2000);
analogWrite (R_Mot_FwdPin, 205);
delay (2000);

And instead of getting 2 sec HIGH and 2 sec of PWM , I get a continuous 205 PWM ,

Any ideas? Thanks
 
Not sure a pin should be expected to jump between DIGITAL and ANALOG - that takes setup changes.

put a pinmode before the digital write and see if that works to show the issue
 
On Arduino Mega, this setup works fine. I am not aware of any Pinmode parameters to define the pin from digital to analog.
Can you point me?

Thanks a lot
 
This is not a Mega of course - the ARM MCU is different in many ways - this is apparently one - the internal pin setup needed to affect the desired output.

This below (top 2 bold lines) is what I was speculating and have just tested to work - I don't know exactly why - there is a lot of code installed with TeensyDuino that might lead to an answer in the 2000+ page MCU manual. It works with just the two analog writes - so jumping back and forth digitalWrite() seems odd and the MCU agrees.

Code:
[B]  pinMode(R_Mot_FwdPin, OUTPUT);
  digitalWrite (R_Mot_FwdPin, HIGH);
[/B]  delay (2000);
  analogWrite (R_Mot_FwdPin, 256);
  delay (2000);
  analogWrite (R_Mot_FwdPin, 205);
  delay (2000);
 
On AVR, that first digitalWrite is actually turning on the input pullup resistor, not actually driving a proper digital high output. It looks like logic high to an oscilloscope or voltmeter, because they have such high impedance.

Teensy tries to emulate most AVR quirks for compatibility, but defaulting all the pins to input mode is one place we don't. Modern chips default their digital pins to a low power disabled mode. This does add the requirement to configure them before use. For that minor extra requirement, you get the huge benefit of unused pins not possibly consuming extra power if they "float" to some random voltage near the logic switching threshold.

Even on AVR, it's good practice to use pinMode before you use digitalRead or digitalWrite.
 
Teensy rocks,

Thanks a lot, I will just stick with the analogWrite 256 and get a HIgh. It is my first time on teensy 3.5, I want to thank the community for the support.

I am re-building the electronics for a police robot. It has about 13 DC motors. I planning to use 2 teensy units, to split the tasks and to get enough PWM outputs.
The general architecture goes like this.
I am receiving RC signals with a interrupt function, I am getting 7 widths super stable, (I am so impressed so far). Next I will plot those as 14 PWM outputs to my motors (each motor needs front and back motion).

Is teensy up to the task? Will it freeze under the load? act slow?
Any pointers are appreciated.

Thank you,
 

Attachments

  • IMG_6533.jpg
    IMG_6533.jpg
    136.5 KB · Views: 63
  • IMG_6485.jpg
    IMG_6485.jpg
    50.3 KB · Views: 88
  • IMG_6563.jpg
    IMG_6563.jpg
    64.9 KB · Views: 55
Status
Not open for further replies.
Back
Top