Flasher

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

Moderator: Benj

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

Flasher

Post by dedajozo »

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 308 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: Flasher

Post by medelec35 »

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
(44.69 KiB) Downloaded 11766 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

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

Re: Flasher

Post by dedajozo »

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
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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.
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

Post by dedajozo »

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

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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
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

Post by dedajozo »

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

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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

Post by dedajozo »

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
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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 17593 times
INVERTED..JPG
INVERTED..JPG (15.47 KiB) Viewed 17593 times
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

Post by dedajozo »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Flasher

Post by Benj »

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

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

Re: Flasher

Post by dedajozo »

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

Post by dedajozo »

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 228 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: Flasher

Post by medelec35 »

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

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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.02 KiB) Downloaded 5183 times
And here is driving a transistor:
DRIVING TRANSISTORS.JPG
DRIVING TRANSISTORS.JPG (35.76 KiB) Viewed 17411 times
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

Post by dedajozo »

Estdriver,

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

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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

Post by dedajozo »

Hello,

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

EtsDriver
Posts: 444
Joined: Tue Apr 15, 2014 4:19 pm
Location: Kajaani, Finland
Has thanked: 345 times
Been thanked: 227 times
Contact:

Re: Flasher

Post by EtsDriver »

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 17293 times
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

Post by dedajozo »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Flasher

Post by Benj »

Hello,

Here is a program you can try.
MacroLED.fcfx
(9.47 KiB) Downloaded 200 times

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

Re: Flasher

Post by dedajozo »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Flasher

Post by Benj »

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 209 times

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

Re: Flasher

Post by dedajozo »

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?

Post Reply