Flasher
Moderator: Benj
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Flasher
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.
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
-
- 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
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: 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 link
if you get stuck can you follow the link on my signature.
We can also help you further if required.
Martin
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: 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
if you get stuck can you follow the link on my signature.
We can also help you further if required.
Martin
Martin
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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.
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.
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
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.
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!
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
Thank you EstDriver. I'll try to find that book in my country, but it will be difficult. Also there is not ebay.
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
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?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.
eBook here
Ill just keep the good work up!
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
I like books to, it is hard to read on the monitor.
I'm in Croatia, near Zagreb, and you?
I'm in Croatia, near Zagreb, and you?
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
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 but unfortunately not neighbouring country :/dedajozo wrote:I like books to, it is hard to read on the monitor.
I'm in Croatia, near Zagreb, and you?
Ill just keep the good work up!
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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?
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?
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
NOTE: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?
If you change the polarity and use "LED_On" and "LED_Off" macros, you dont need to touch to them. 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)
Ill just keep the good work up!
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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
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
- 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
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
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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.
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
-
- 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
Hi dedajozo,
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.
Don't forget as Ben stated:dedajozo wrote:Led - to chip output.
So when output drops to 0V , Since Anode is connected to +5V and cathode os connected to the output pin then LED should light.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.
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
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
Here are pictures to help understand! And here is driving a transistor:medelec35 wrote:Hi dedajozo,Don't forget as Ben stated:dedajozo wrote:Led - to chip output.So when output drops to 0V , Since Anode is connected to +5V and cathode os connected to the output pin then LED should light.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.
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.
Ill just keep the good work up!
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
Coul you draw some kind of schematic for us to see how your leds are connected?dedajozo wrote:Estdriver,
what do you think will my code work the way it is now with tranzistors?
Ill just keep the good work up!
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
Hello,
in the attachment is shematic that I want to use.
in the attachment is shematic that I want to use.
- Attachments
-
- Untitled.png
- (7.76 KiB) Downloaded 11337 times
-
- Posts: 444
- Joined: Tue Apr 15, 2014 4:19 pm
- Location: Kajaani, Finland
- Has thanked: 345 times
- Been thanked: 227 times
- Contact:
Re: Flasher
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.
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.
Ill just keep the good work up!
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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
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
- 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
Hello,
Here is a program you can try.
Here is a program you can try.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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.
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.
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 45
- Joined: Sun Jan 03, 2016 5:48 pm
- Has thanked: 8 times
- Been thanked: 6 times
- Contact:
Re: Flasher
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?
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?