Flasher

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

Moderator: Benj

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Flasher

Postby dedajozo » Sun Jan 03, 2016 5:59 pm

Hello to all,
my name is Josip, I'm from Croatia.
I'm a programmer but m new in chip programming.
I downloaded Flowcode demo version for start.
I tried to make a program to flash two 21w bulb's but not in the same time, first one then other. The pic is 12F629.
Flowcode simulator is running fine and they are flashing as I want.
If it is possible I would like that one of you take a look and tell me your opinion.
File is in attachment.

Thank you in advance.
Attachments
flasherpic12F629.fcfx
(5.46 KiB) Downloaded 157 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8826
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2561 times
Been thanked: 3721 times
Contact:

Re: Flasher

Postby medelec35 » Sun Jan 03, 2016 7:07 pm

Hi Josip,
Welcome to Matrix forums.
Are you planing on using inernal or external oscillator?
To keep hardware simple you could use Precision Internal 4 MHz oscillator factory calibrated to ±1%
Then external resonator or crystal & caps are not required.

In order for your hardware to work you must change your project options (Build menu).
With general tab selected:
Change clock speed to 4000000.
You can type it in or use the drop down list.

With Configure tab selected:
change to the following:
Configuration settings.png
Configuration settings.png (44.69 KiB) Viewed 11742 times

If watchdog timer is left on then without any commands to clear watchdog your chip will keep resetting.

As for driving the bulb, the microcontroller can only drive up to it's supply voltage and sink/source no more than 25mA per pin (up to a total of 250 mA)
So some form of current & voltage buffer is required. E.g a logic voltage FET.
Then you can drive Bulbs that are higher than 5V

There are free online courses in the learning centre.
Courses include electronics and Flowcode programming.
Just click on

Code: Select all

Matrix Online Courses
link

if you get stuck can you follow the link on my signature.
We can also help you further if required.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Sun Jan 03, 2016 8:44 pm

Hello Martin,

thank you for your quick reply.
I will use internal oscillator. I changed settings as you write in your post.
My plan is that microcontroller drive transistor and and then on bulb.
I'm not an electronic as I write in my post I'm software programmer i Java and C++. So possible errors by my side are not exluded :).
I will need to learn much more about microcontollers.
Can you recommend me some book or something?

Thank you again for your help.

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Mon Jan 04, 2016 12:47 pm

Id recommend you the "Create 30 Pic microcontroller projects with Flowcode 6" by Bert van Dam, ISBN: 9781907920301. I bought this book from Elektor and it is nice guide for getting started and it gave me help and learnt new things when migrating from Flowcode v5 to v6.

Most of the projects can be done on simulation only too if you want to think about the pic licence with demo.
These users thanked the author EtsDriver for the post (total 3):
medelec35 (Mon Jan 04, 2016 1:05 pm) • jgu1 (Mon Jan 04, 2016 2:14 pm) • dedajozo (Mon Jan 04, 2016 6:09 pm)
Rating: 15%
 
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Mon Jan 04, 2016 6:11 pm

Thank you EstDriver. I'll try to find that book in my country, but it will be difficult. Also there is not ebay.

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Tue Jan 05, 2016 8:22 am

dedajozo wrote:Thank you EstDriver. I'll try to find that book in my country, but it will be difficult. Also there is not ebay.


Elektor sells some books as e-book/pdf versions, great if your location is hard to reach. I personally like real books more :) Which country are you by the way located?

eBook here
These users thanked the author EtsDriver for the post:
medelec35 (Tue Jan 05, 2016 11:57 am)
Rating: 5%
 
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Tue Jan 05, 2016 9:46 am

I like books to, it is hard to read on the monitor.
I'm in Croatia, near Zagreb, and you?

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Tue Jan 05, 2016 10:42 am

dedajozo wrote:I like books to, it is hard to read on the monitor.
I'm in Croatia, near Zagreb, and you?


Yeah, I'm from Finland. Tought if you would have been living on the eastern big country next to Finland, sending a book there would have been easy from here :D but unfortunately not neighbouring country :/
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Wed Jan 06, 2016 1:14 pm

I tried my program and it works fine.
But a few things are bothering me, when I try my exit it come out positive i mean +, is it possible to make program so outs are giving negative signal - pol. So if I put PNP tranzistor I need negative out from pic.
Anyone have solution?

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Wed Jan 06, 2016 2:29 pm

dedajozo wrote:I tried my program and it works fine.
But a few things are bothering me, when I try my exit it come out positive i mean +, is it possible to make program so outs are giving negative signal - pol. So if I put PNP tranzistor I need negative out from pic.
Anyone have solution?


NOTE:
If you change the polarity and use "LED_On" and "LED_Off" macros, you dont need to touch to them.
INVERTED3.JPG
(126.26 KiB) Downloaded 5364 times


Another way you just change the code so when you want your light to light up, set output to zero, and when not, set to 1? You can change usually the LED options too to make simulation look like what happens in reality (change the polarity of the LED simulation)

INVERTED2.JPG
INVERTED2.JPG (35.49 KiB) Viewed 11610 times

INVERTED..JPG
INVERTED..JPG (15.47 KiB) Viewed 11610 times
These users thanked the author EtsDriver for the post (total 2):
dedajozo (Wed Jan 06, 2016 6:42 pm) • medelec35 (Wed Jan 13, 2016 11:20 pm)
Rating: 10%
 
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Wed Jan 06, 2016 6:41 pm

EstDriver you are advanced programmer I just started so your terms are quite unknown to me.
In properties menu connection tab I have polarity menu Active high and Active low. Is that negative and positive pole ?
By the way I order myself a book which you suggested.

THX

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

Re: Flasher

Postby Benj » Wed Jan 06, 2016 8:03 pm

Hello,

Most LED configurations will likely be active high just because it is more intuitive. The LED comes on when the pin is outputting a logic 1 and the microcontroller is sourcing the LED drive current. In this configuration the LED anode connects to the microcontroller pin and the cathode connects to ground.

Active low on the other hand is when the LED comes on when the pin is outputting a logic 0 and the microcontroller is sinking the current. In this configuration the LED anode connects to VCC and the cathode connects to the microcontroller pin.

Both configurations will require a current limiting resistor to protect the LED being damaged.

You can calculate your resistor using a calculator like on the link below. 20mA is a common max current for standard LEDs and the Source Voltage will likely be 5V or 3.3V depending on your hardware. The diode forward voltage will vary depending on your LED but 2.1V is a fairly common voltage. Around 300R is a fairly safe resistor value, we use 220R on our E-blocks.

http://led.linear1.org/1led.wiz
These users thanked the author Benj for the post:
dedajozo (Wed Jan 06, 2016 9:20 pm)
Rating: 5%
 

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Wed Jan 06, 2016 9:20 pm

Thx Benj for joining and clear explanation.

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Wed Jan 13, 2016 9:56 pm

Hi again,

I tried to change polarity but when change to active low my program is not working. Led - to chip output.
On active high works normally. Led + to chip output.

It is important that I have negative out from chip.

Code in attachment.

Can somebody check.

Thanks in advance.
Attachments
flasherpic12F629.fcfx
(5.46 KiB) Downloaded 123 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8826
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2561 times
Been thanked: 3721 times
Contact:

Re: Flasher

Postby medelec35 » Wed Jan 13, 2016 11:37 pm

Hi dedajozo,
dedajozo wrote:Led - to chip output.

Don't forget as Ben stated:
Benj wrote:Active low on the other hand is when the LED comes on when the pin is outputting a logic 0 and the microcontroller is sinking the current. In this configuration the LED anode connects to VCC and the cathode connects to the microcontroller pin.

So when output drops to 0V , Since Anode is connected to +5V and cathode os connected to the output pin then LED should light.
If it does not then output pin is probably at +5V

For us to help we need to understand what you are trying to achieve.

Since a microcontroller output will only be between 0 and +5V then it won't go negative with respect to ground.
The only way to get a negative output is to have +5V as common, then when output goes to 0v, its negative with repect to +5V (VCC)
Perhaps if you post a circuit diagram of what your'e trying to achieve rather than descriptive we can help you further.
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Thu Jan 14, 2016 10:32 am

medelec35 wrote:Hi dedajozo,
dedajozo wrote:Led - to chip output.

Don't forget as Ben stated:
Benj wrote:Active low on the other hand is when the LED comes on when the pin is outputting a logic 0 and the microcontroller is sinking the current. In this configuration the LED anode connects to VCC and the cathode connects to the microcontroller pin.

So when output drops to 0V , Since Anode is connected to +5V and cathode os connected to the output pin then LED should light.
If it does not then output pin is probably at +5V

For us to help we need to understand what you are trying to achieve.

Since a microcontroller output will only be between 0 and +5V then it won't go negative with respect to ground.
The only way to get a negative output is to have +5V as common, then when output goes to 0v, its negative with repect to +5V (VCC)
Perhaps if you post a circuit diagram of what your'e trying to achieve rather than descriptive we can help you further.


Here are pictures to help understand!
ACTIVE LOWHIGH.JPG
(55.03 KiB) Downloaded 5183 times


And here is driving a transistor:
DRIVING TRANSISTORS.JPG
DRIVING TRANSISTORS.JPG (35.77 KiB) Viewed 11428 times
These users thanked the author EtsDriver for the post (total 4):
medelec35 (Thu Jan 14, 2016 10:42 am) • Benj (Thu Jan 14, 2016 10:51 am) • kersing (Thu Jan 14, 2016 7:01 pm) • dedajozo (Fri Jan 15, 2016 7:58 am)
Rating: 20%
 
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Fri Jan 15, 2016 8:00 am

Estdriver,

what do you think will my code work the way it is now with tranzistors?

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Fri Jan 15, 2016 10:20 am

dedajozo wrote:Estdriver,

what do you think will my code work the way it is now with tranzistors?


Coul you draw some kind of schematic for us to see how your leds are connected?
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Mon Jan 18, 2016 7:00 pm

Hello,

in the attachment is shematic that I want to use.
Attachments
Untitled.png
Untitled.png (7.76 KiB) Viewed 11313 times

EtsDriver
Valued Contributor
Valued Contributor
Posts: 437
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 348 times
Been thanked: 228 times
Contact:

Re: Flasher

Postby EtsDriver » Mon Jan 18, 2016 8:49 pm

Hi!

Your LED's should light up when up set output to low logic state, and should go out when output is driven to output high logic state.

By using PNP transistors the way the circuit works will be same, when driven low, PNP transistor output will activate, and when driven high, output will go out.

PNP.JPG
PNP.JPG (27.86 KiB) Viewed 11310 times
These users thanked the author EtsDriver for the post (total 2):
dedajozo (Mon Jan 18, 2016 10:03 pm) • medelec35 (Mon Jan 18, 2016 10:55 pm)
Rating: 10%
 
Ill just keep the good work up!

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Mon Jan 18, 2016 9:59 pm

Thx Est,

I'll try tomorrow, did you see my flowcode project? What do you think will it work that way?

Thank again. I got book that you recommend,it seams good, only I need to order myself Flowcode pic kit pro.

THX

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

Re: Flasher

Postby Benj » Mon Feb 29, 2016 11:33 am

Hello,

Here is a program you can try.

MacroLED.fcfx
(9.47 KiB) Downloaded 109 times

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Mon Feb 29, 2016 2:42 pm

Hello Benj,

thanks for quick reply, but I did'nt ment that.
I ment switch decision not switch as control button.
The thing is that I have few macros and every macro is called by buton, but only one macro need to work, that means that the other one is off.
So when you select one macro the other one ends and oposite.

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

Re: Flasher

Postby Benj » Mon Feb 29, 2016 5:52 pm

Hello,

You are best off having the while 1 loop in the main macro and having logic in the main to allow you to choose which macro you need to call.

The switch icon will work off a variable the same as the decision icon but allowing for more execution branches.

You could check sw 1 and if it is pressed then call macro 1, if switch 2 is pressed then call macro 2.

If you need to switch off the outputs then switch everything off in the main and then only switch what you need on in the macro.

It's hard to tell exactly what your trying to do.

My guess is that you only want one switch to be active and able to light the LED at a time. If a second switch is pressed then this should do nothing until the first switch is released.

Here is another go.
MacroLED-1.fcfx
(9.32 KiB) Downloaded 112 times

dedajozo
Posts: 45
Joined: Sun Jan 03, 2016 5:48 pm
Has thanked: 8 times
Been thanked: 6 times
Contact:

Re: Flasher

Postby dedajozo » Mon Feb 29, 2016 6:21 pm

Thx Benj,

but is it possible to do that with the switch decision? If I want to put 6 macros.
Or is it possible to turn switch of when another is on?