Welcome! Log In Create A New Profile

Advanced

M42 on pwm pin only outputs 5V or 0V

Posted by heyisaacsback 
M42 on pwm pin only outputs 5V or 0V
April 11, 2016 03:12PM
I've been trying to use my prusa i3 printer with Marlin to move around a laser, switching it on and off using the command: M42 D11 SXX. The laser has TTL communication and should be able to support a pwm input. My board is an MKS Base (a single-board ramps 1.4 setup) and D11 is a pwm pin that is exposed to control servos.

The issue is that although I'm able to switch the pin between output between 0 and 5V using M42 D11 S0 and M42 D11 S255, respectively, I can't get any values in between. Anything from S0 to S128 yields 0V and S128 to S255 gives me 5V.

What's going on here? Why is D11 acting like a plain digital output? I've tried the above on pins D12, A11, A12, and D2 (For D2 I disabled a max endstop, it's pullup resistor, and removed it from the sensitive pins list). I even edited out the "digitalwrite" line of M42 in Marlin's main.cpp. Always the same behavior. Is this a bug with M42? Is pwm disabled on my board for some reason? Am I crazy?

Thanks in advance.
Re: M42 on pwm pin only outputs 5V or 0V
April 12, 2016 07:31AM
Maybe the timer for that pin is already used in an interrupt.

Edit: Yes, it's used for the stepper interrupt.

Edited 1 time(s). Last edit at 04/12/2016 07:34AM by Wurstnase.


Triffid Hunter's Calibration Guide --> X <-- Drill for new Monitor Most important Gcode.
Re: M42 on pwm pin only outputs 5V or 0V
April 12, 2016 12:16PM
Ah okay, thanks Wurstnase. So I can't use D11 or D12 because Timer1 is being used for driving the steppers. What about D2 (unused x max endstop)? I believe this is on timer3. I also have an unused extruder (D10) but the connection is through a power transistor. If I'm desperate, could I solder a lead to the gate of this transistor and leave the source/drain floating? Thanks!
Re: M42 on pwm pin only outputs 5V or 0V
April 12, 2016 12:40PM
You can use any pin, which is not configured and used by a timer. Afaik there are at minimum two timers. OC1A for stepper and a second one for other tasks like ADC and co. Maybe a third one for advanced stepping algorithm.
I would not use D10.


Triffid Hunter's Calibration Guide --> X <-- Drill for new Monitor Most important Gcode.
Sorry, only registered users may post in this forum.

Click here to login