Arduino PWM

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Arduino PWM

Post by mnf »

This might be me - PWM doesn't seem to work on Arduino (I tested Nano)

Using Channel 6 (Pin D3) - PWM::Enable() and PWM::SetdutyCycle(200) - just gives no output on pin.
Using Arduino IDE and pinMode(3, OUTPUT); analogWrite(3, 200); - gives a very nice square wave with 78.4% duty cycle as expected..

Am I doing something wrong - I tried various PWM channels / combinations of speeds.
pwm 2.fcfx
(7.9 KiB) Downloaded 171 times
Martin

How it should look:
LabNation_Screenshot8.png
LabNation_Screenshot8.png (284.74 KiB) Viewed 2146 times

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Arduino PWM

Post by jgu1 »

Hi Martin!

You deserve an answer. :wink: Maybe no help, but here my test.

When I test with your testprogram With cal., your rigth, no PWM out.

I made a test with the PWM component and it work. Maybe stupid question, why use the cal? I know it has something to do with creation component or simulation. I have no experience with this, probably a fault from me :lol:

Br Jorgen
Attachments
PWM_Martin.fcfx
(7.32 KiB) Downloaded 167 times

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Arduino PWM

Post by mnf »

Hi Jorgen,

Many thanks for that - works perfectly... Why did I use CAL - I searched for the PWM component - and it was the first I found.

Had never used PWM before.... Should have used search rather than looking through the component lists....

Martin

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Arduino PWM

Post by jgu1 »

Hi Martin!

Glad I was able to help you and maybe a little repay with a fraction for your always helping. :lol: :lol:

Br. Jorgen.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Arduino PWM

Post by Benj »

Hello,

Glad you've got it working. Sorry for the lack of a reply.

The PWM component uses the CAL component behind the scenes but also calls the ChangePeriod function as part of the Enable macro which is probably the bit you were missing from your CAL program.

Post Reply