Again... PWM with LED on E-block

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
hvandervinne
Posts: 5
Joined: Wed Sep 28, 2016 10:42 am
Contact:

Again... PWM with LED on E-block

Post by hvandervinne »

Hello,

I am very new with programming within FlowCode (and my English is not my native language, as you can read) and I know I am asking a question which has been asked before (multiple times). However, I do not seem to find an answer suitable for my problem. I want to control the brightness of a LED on the e-block type EB-004, using an input via a different board (and a can-databus which connects the two boards) to switch the led on.
I have a program that will turn on the corresponding led on the EB004, when I press a switch on the EB007 switch board, which is connected to a separate 16F877-controller board. Now I want to turn on this LED, but only on 'half the brightness'. I understand I have to use PWM, but I can't get it to work. I altered the original, working program, but I must be doing something wrong, obviously. I have tried to copy the settings from an example-program, and also tried several different delays, but it is not working as I expected. I am using FlowCode V6. My current program is attached.

Please help me.

Regards
Hans
Attachments
opdracht 1 node 2 met pwm.fcfx
(9.76 KiB) Downloaded 256 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Again... PWM with LED on E-block

Post by medelec35 »

Hi Hans,
Assuming that you are receiving data from CAN so yes branch is accessed.
You have a calculation box with

Code: Select all

Duty = 1
Which is used to set PWM duty.
Since rollover on the Pwm component is 255 then if you divide 255 by 100 that with give you a multiplier of 2.55 to use.
For very approximately 1/2 brightness you should have a PWM of about 50% not less than 1%
So for a PWM Duty of approximately 50%, Duty variable should be 50 * 2.55 = 127.5
So try

Code: Select all

Duty = 127


Martin
Martin

hvandervinne
Posts: 5
Joined: Wed Sep 28, 2016 10:42 am
Contact:

Re: Again... PWM with LED on E-block

Post by hvandervinne »

Hi Martin,

Thanks for your quick reply. I read about the duty-value in other posts and changed the value several times. I tried 50 and 100, but I cannot see any difference in brightness, so I think I am (also) doing something else wrong.
I am not sure how the chip will react to the code, that, I try to set the pwm-duty, and after that, I have an output, putting the variable 'input_1' to port B.

Could this be my problem?

Regards
Hans

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: Again... PWM with LED on E-block

Post by Benj »

Hello Hans,

There is a bug on the PWM in v6 for certain PIC devices. The fix is available from here.

http://www.matrixtsl.com/mmforums/viewt ... 59&t=17458

Hopefully this should solve the problem you're having.

hvandervinne
Posts: 5
Joined: Wed Sep 28, 2016 10:42 am
Contact:

Re: Again... PWM with LED on E-block

Post by hvandervinne »

Thanks, guys, for helping me.
But I do not have a solution yet. I retried different duty-settings and also saved the PIC_CAL_PWM.c in the correct folder, but I see no difference.
I hope you have another idea. The program I attached in the original post, should it work correctly? Or am I making one or more mistakes.........?

Regards
Hans

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Again... PWM with LED on E-block

Post by medelec35 »

Have you tried a 1 sec flasher to make sure your hardware is running at the correct speed?
What you can do is put the flasher loop before the PWM is enabled then the led connected to the PWM pin will do the flashing to make sure LED with limiting resistor is all working.
Also if flash test is working ok you can disable or delete it then temporary change the the decision box from

Code: Select all

data_ontvangen <> 0
to

Code: Select all

1
Martin
Martin

hvandervinne
Posts: 5
Joined: Wed Sep 28, 2016 10:42 am
Contact:

Re: Again... PWM with LED on E-block

Post by hvandervinne »

Hi Martin and the others,

See the attached code. The LED's are flashing three times for about a second on (and about a second off), so I think that is working okay. However, when I press a switch on the other PIC-microboard, the LED will turn on at full strength. It is not dimmed, as I expected. Are there any more ideas?

Regards
Hans
Attachments
opdracht 1 node 2 met pwm.fcfx
(9.99 KiB) Downloaded 265 times

hvandervinne
Posts: 5
Joined: Wed Sep 28, 2016 10:42 am
Contact:

Re: Again... PWM with LED on E-block

Post by hvandervinne »

Hi all,

I am still working on my pwm-problem.
Attached is a screenshot of the program. In there, you can see the dashboard and systems panel as well. Do I need to make a connection of some kind between the CAN-module and the PWM-module?
The program turns the leds on and off for three times, each time for about a second on and a second off. I also installed the new PIC_CAL_PWM.c-file, but the leds still light up at full strength, despite the pwm-code.
Do you have any suggestions? I hope to receive some tips to solve this pwm-issue.

Also, I made a video of the both boards, but I am not able to post it. Either too large or extension not allowed. I can send it via WeTransfer, if you like.

Regards
Hans
Attachments
opdracht 1 node 2 met pwm.zip
(71.77 KiB) Downloaded 280 times

Post Reply