Pretty new to FlowCode, lots of questions!

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Hello all,

As much as I'd like to be breif with this topic, I know it won't be, so I'll just try and begin and leave some unimportant details behind. My school has FlowCode V4 and we have been usuing the software for a few weeks now covering the basics. Things like variables, and using the predefined macros, and making your own. Now, we are moving on to more complicated matters, and interestingly enough, we have been assigned almost a "self-taught" lesson where we are to explore some of the more complex features of FlowCode and apply it to a realworld model.

So far, my actual project involves a microchip (duh), 4 pushbutton (SPST) switches, 2 LED's, an LED IR array, and a 16x1 LCD display. The actual interaction between the items is something I believe I can do (as I've worked through many basic guides), but if I ever get stuck, I may be back. Now before I begin my real prodedure I'm trying to accomplish, I thought I'd ask a few questions about the components.
  • 1) I did some research on a 16x1 display, and all the models I've seen seem to have somewhere in the ballpark of 16 inputs (yes, even the Hitachi one mentioned in the Help menu), whereas FlowCode only shows 6 connections. Perhaps someone can clarify how there can be such a huge gap in connectivity and still be functionality.

    2) FlowCode does have an output for LED Arrays, but its not really what I'm trying to get. I have a LED array (of infrared LED's if that means anything) that contains 36 LEDs and is designed to operate between 12 and 13.8vdc wher the maximum efficiency can be achived at 13.2Vdc. If your still with me, I've basically tied all 36 LEDs together as one output, but its not just one LED and will require a higher voltage. Is there someway in flowcode that I can define an output voltage to the pin containing the output to my LED array?

    3) Tieing into the last question, I notice that under the supported PIC's, there are no high voltage ones, which means that my input voltage will be anywhere from 3.3-5v, and as I mentioned in the last question, I need to get roughly 13v to one of my outputs. Is this something that a non-HV PIC is capable of and is the software capable of coding that in? If the answer to that is no, can I tie a step-up converter onto the output of my LED array's pin to kick the output voltage up to 13v, and still have that work, even if the coding does not reflect this hardware change?
Whew. That was a mouthful. Now if your still with me here, I'll run over basically what the whole unit is trying to do:

Power is applied to the unit, so the LCD display has a little welcome message, some inital variables are set, (if they haven't been already) and the LED's flash a few times. After that, The unit will wait for a input (button press) from either of 2 (of the 4) buttons, while it sits on the main screen. If button 1 (for my explaination purposes) is pressed than the LCD screen will display some text like "activated at x rate" and the LED array needs to flash at a specified rate for a specified amount of time, which I just wrote as x there (roughly from like 5Hz to 20Hz). Both the rate and time will be variables that can be changed. If the other button (button 2) is pressed (from the main screen), the LCD screen will change to say something like "Options" breifly, then will change to say "Frequency - Time" accross the screen. At that time, now only buttons 3&4 are active. Well usless you hit button 2, which will just return you to the main screen. Anyway, the buttons will be placed under the screen so button 3 will coralate to changing the frequnecy, and button 4 will change the time delay. If you press button 3, the display will change to something like "Freq: 5Hz", then button 3 becomes a minus (-) button, and button 4 becomes a plus (+) button. As you press up and down (3 & 4), the display will update acordinaly. With the minimum being like 5Hz and the max at like 20Hz. Once you have it set, you hit button 2 again and it saves this value to a variable. Similaraly, the same kind of thing will happen for the time delay option. Then back on the main screen, hitting button 1 again will initate the LED array's flash sequence at the defined values.

And thats about it.

I know that is A LOT to read, but it took me awhile to write it, and I only wrote this much so as I would try and answer every question you could possibly have before trying to help me accomplish this. Any help of input on anything here would be greatly appreicated. Oh, and I did try and post this in the "FlowCode V4" forum, but my account hasn't been approved for that yet. Thanks again!

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: Pretty new to FlowCode, lots of questions!

Post by Benj »

Hello,

1) I did some research on a 16x1 display, and all the models I've seen seem to have somewhere in the ballpark of 16 inputs (yes, even the Hitachi one mentioned in the Help menu), whereas FlowCode only shows 6 connections. Perhaps someone can clarify how there can be such a huge gap in connectivity and still be functionality.
Most of the pins of the LCD are either not used or tied to voltage rails. Our EB005 datasheet has a schematic which shows you how to connect up a display.
http://www.matrixmultimedia.com/datashe ... 5-30-3.pdf
2) FlowCode does have an output for LED Arrays, but its not really what I'm trying to get. I have a LED array (of infrared LED's if that means anything) that contains 36 LEDs and is designed to operate between 12 and 13.8vdc wher the maximum efficiency can be achived at 13.2Vdc. If your still with me, I've basically tied all 36 LEDs together as one output, but its not just one LED and will require a higher voltage. Is there someway in flowcode that I can define an output voltage to the pin containing the output to my LED array?
You can drive a higher voltage by using a npn transistor or a similar device between the microcontroller and the higher voltage hardware. See this article for more info on powering LEDs.
http://www.matrixmultimedia.com/mmforum ... =26&t=6732
3) Tieing into the last question, I notice that under the supported PIC's, there are no high voltage ones, which means that my input voltage will be anywhere from 3.3-5v, and as I mentioned in the last question, I need to get roughly 13v to one of my outputs. Is this something that a non-HV PIC is capable of and is the software capable of coding that in? If the answer to that is no, can I tie a step-up converter onto the output of my LED array's pin to kick the output voltage up to 13v, and still have that work, even if the coding does not reflect this hardware change?
Answered in Q2. NPN transistor or similar decoupling device can be used to drive higher voltages.

Sounds like a good project, let us know how your getting on.

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Benj,

Thank you for the quick response, and links. I went ahead ang read over the first PDF regarding the LCD, and have gotten a better idea of how it connects. For now, I'll move on to the more complicated matters, which you did help address in the topic you linked me to. Thought it did answer my questions, it was a bit broad to what I'm trying to do, which brought up some other questions.

First off, this link (http://www.bgmicro.com/LED1007.aspx) is the LED IR array I will be using. As I mentioned, its a set of 36 LEDs and 4 resistors already put together... just waiting for 13v in. From you post, I was able to gather that I will need to use a step-up device, such as a NPN transistor to go from my output to roughly 13v. On that topic, is there a way of knowing, either through FlowCode or just knowledge, how much the output voltage to a LED would be, as I assume the step-up device will have to be prepared arrcordingly to its input voltage, which would essentially be the microchips output voltage to that pin. And on that, perhaps someone such as yourself could direct me to a good microchip? The only one I've ever used before was a 12F683, but it only like 5 input-able pins. And from what I gathered, I'll need 6 (for LCD) + 3 (for 2 LEDs then LED array on one output) + 4 (the 4 buttons) = 13 pins that can be controlled.

Unfortunately I'm not on a computer that has FlowCode right now, so I'm not able to open that file at the end of the LED post you showed me. Perhaps it will have some insight into how todo what I'm looking for... Which is basically: How do I tell the LED array to flash at a given frequency from inside FlowCode? If you did read through my whole first post, on the bottom, I covered what the actual process would be. I mentioned in there, that I would like some sort of on-board editing feature, so it seemed to me like the frequency and time delay can be stored to variables, I just don't know how to apply those to my LED array (from FlowCode) to tell it to flash at the given rate for the given amount of time.

Any leads on that would be again, much appreciated.

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

The link Ben posted shows how a higher voltage e.g 13.2V can be controlled by a microcontroller powered by just 5V
When the o/p pin is at +5V there is base bias to transistor, so it acts like a closed switch.
When the o/p pin is at 0V base bias to transistor is removed, so it acts like an open switch.
Controlling multiple LEDs.jpg
Controlling multiple LEDs.jpg (91.63 KiB) Viewed 19959 times
Controlling multiple LEDs 2.jpg
Controlling multiple LEDs 2.jpg (68.59 KiB) Viewed 19959 times
Important, you must make sure the transistor can comfortably supply enough current the load demands.
Best way to control LEDS is with PWM.
There is also a flowcode example using PWM within Ben's post.

One way you can power the 13.2V and 5V at the same time is to use a 5V voltage regulator supplied from 13.2V to power 5V microcontroller.
There are plenty of 5V power supply circuits around the net using 7805 Voltage regulators.
As for choosing a microcontroller see:
http://www.matrixmultimedia.com/mmforum ... 40&p=22195
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

medelec35,

Thanks for those diagrams. Really quite helpful in comprehending the how it can be connected to a standard PIC. I did do some previous searching regarding "PWM" as it appears to be the way to go when controlling LEDs, but I'm having a tough time grasping the concept (if that makes sense). I downloaded the example from BenJ's first post, but it was quite difficult to follow.

With "PWM" is it possible to have the on-board editing feature I would like? Here's the snippet from my last post again explain what I'm trying to do exactly:
How do I tell the LED array to flash at a given frequency from inside FlowCode? If you did read through my whole first post, on the bottom, I covered what the actual process would be. I mentioned in there, that I would like some sort of on-board editing feature, so it seemed to me like the frequency and time delay can be stored to variables, I just don't know how to apply those to my LED array (from FlowCode) to tell it to flash at the given rate for the given amount of time.
Thanks for the help so far, I'm making some real progress!

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

PWM or Pulse Width Modulation is where the on times are fixed at a frequency. Its how long the on time (or on width) compared to off time that determines how bright LEDs are.
E.g on time occurs every 1ms = 1/1x10-3 = 1KHz and pulse stays on for 0.9ms and off for .1ms, then duty = on time/(on + off time) X 100 = 0.9ms/(0.9ms + 0.1ms) x 100 = 90%
Since LEDs are on for a duty of 90% of the time they would be at 90% brightness for argument sake.

That's what the flowchart does switch LEDs on, wait for a period in time to elapse then switch LED's off, keep repeating cycle.
Its uses timer0 interrupt.
what timer0 interupt does is this case is trigger a macro called PMW_Handle after an an exact time has passed, no matter what code was running at the time. So it does literally interrupt from what it was doing.
PWM1 - PWM4 are fixed values.
Every time PMW_Handle is accessed the variable count is incremented by one. If PWM1 - PMW4 is less than count variable then relevant Port = logic 1 (or 5V). So LED's will be on
If PWM1 - PMW4 is not less than count variable then relevant Port = logic 0 (or 0V). So LED's will be off.
Best way to learn is by loading flowchart. then keep pressing F8 key (single step) and follow actions of flowchart step by step.
When you get more use to flowcode, you could then try the built in PWM component.
They will only work with microcontrollers that have PWM capabilities built in to them. Key word to look out for if doing a search is CCP (Capture/Compare/PWM).
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Well I went ahead and loaded up the PWM demo from the first post, and man is it confusing! I even followed it step by step and I understand how the values are added up and such and how this turns the light on and off, but I just don't get how you can determine an exact frequency. I did, however, get a better grasp on "dutycycle", which, if I understand it correctly, should be as close to 50% as possible if I want flashing LEDs.

To put it into example form. I basically mirrored the guide PWM and made my own with one LED, but it doesn't turn on and off in any noticable pattern. Its almost random. Maybe you can show me simply how to get an LED to flash at a frequency of 2Hz ?(for this example...)

Thanks again.

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

medelec35 wrote:
That's what the flowchart does switch LEDs on, wait for a period in time to elapse then switch LED's off, keep repeating cycle.
Its uses timer0 interrupt.
what timer0 interupt does is this case is trigger a macro called PMW_Handle after an an exact time has passed, no matter what code was running at the time.
So it does literally interrupt from what it was doing.
The LED flash rate is determined by the timer0. If you double click (or right click and select properties), then when new window opens again click properties.
timer0.jpg
timer0.jpg (135.12 KiB) Viewed 19937 times
You can see that the interrupt frequency is 3906.250 Hz (determined by oscillator speed and selectable prescaler rate)
This means no matter what part of flowchart is currently active (e.g 10ms delay) this will be temporary halted, and the
PWM_Handle macro will be accessed every 256 microseconds
........................-6
(1/3906.25= 256x10 )

But the flash rate is so fast, With a high enough duty it looks like LEDS are permanently lit.
Just like the lights in your house, they are switching on/off every 100 times a second, but you do not see that due to persistence of vision.
By varying the duty, all you are doing is changing the overall brightness of the leds since the on times compared with on times (ratio between on/off) vary.
So If you have 50% duty, the overall effect is LEDs are at half their brightness, but they will still will not flash, due to on/off too fast.

PWM is used since overall power consumption is reduced. PWM can also allow LEDs to go brighter than normal without blowing, since they (and transistor) can handle a a much higher peak current then normal for a very short time.

To flash LEDs e.g at 2HZ but keep power consumption down = less heat generated.
What you want to do is have a high duty (70-96% depending on overall brightness required) for 250mS (1/freq/2 = 1/2/2=0.25), then 0% duty for 250ms.
Keep repeating forever.

I will alter the flowchart for you ,so it does just that, and will post it later today.
What you need to bear in mind is there are so many choices of microcontrollers that works with flowcode, and you can use internal or external osc.
E.g. The PWM demo is set up for 16F88 and using the microcontrollers internal oscillator set at 4MHz. ( A C block with osccon = 0x60; sets internal osc to 4MHz)
You will need to let me know if you are using the same device or not.
Last edited by medelec35 on Tue Mar 01, 2011 12:58 pm, edited 1 time in total.
Martin

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

Here is the modified Flowchart.
I have set it up so LED A0 is flashing at 2Hz.
I am still using bit bang PWM method, to light LED, but have altered original to make it a bit easier to follow.
You can change the Duty variable, to any value (0 to 100%).
e.g 25 = 25% = 1/4 brightness
50 = 50% = 1/2 brightness
I personally would not set it to 100% as this is waste of power. 85-90 is a good range.

As for the flashing time:
Value of Count2 sets the flashing frequency.
E.g if you want 2Hz then Count2 = interrupt frequency/flash frequency /2 = 3906.25/2/2 = 976.56 so round down to 976.
Note: Since Count2 is using an integer variable, this means Count2 cannot be any higher than 32767

If you was wondering what Toggle = !Toggle does:
! means 'NOT' for just 1 bit. so NOT 0 = 1 and NOT 1 = 0.
So each time this calculation is accessed, if Toggle was = 0 then its changed to 1
Or if Toggle was = 1 then its changed to 0
So it is toggling.
Attachments
Software_PWM_modified.fcf
Modified to flash at 2Hz
(7 KiB) Downloaded 633 times
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Thank for those explanations, and the reworked document. I've had a busy day today so really haven't had as much time to play around with it as I'd like, so maybe I'm not doing myself justice asking this question, but the only thing that came up was that it doesn't appear like when I click play that its flashing 2 times a second. In fact, in FlowCode, it took at least 20 seconds for the LED to turn from on to off just once.

Now granted I understand the program probably can't simulate at full speed, but it just doesn't seem right as this speed. Is this just an effect caused by the program? Or is it really going at like .01Hz?

On and on microchips, I don't have one selected yet, but it sounds like I need to get one with internal PWM. Feel free to mention your favorites if you use those a lot.

Thanks again.

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

ItWasLuck3 wrote:so maybe I'm not doing myself justice asking this question, but the only thing that came up was that it doesn't appear like when I click play that its flashing 2 times a second. In fact, in FlowCode, it took at least 20 seconds for the LED to turn from on to off just once.

Now granted I understand the program probably can't simulate at full speed, but it just doesn't seem right as this speed. Is this just an effect caused by the program? Or is it really going at like .01Hz?
Hi ItWasLuck3,
The flashing rate is fully dependent on timer0 interrupt. Every time timer0 calls the interrupt macro (once every 256us), Count2 is incremented by 1.
It is only when Count2 variable reaches 976 that LED changes from visually on or off or vice-versa. Even with simulator running at full speed (you can change simulation speed by selecting 'View, 'project Options') It does not access the interrupt no where near as fast as either the real hardware, or a simulator that runs in real time.
I have downloaded and saved the modified flowchart (just to confirm I posted correct version), reprogrammed chip with it, and I can guarantee the LED looks like is flashing at 2Hz. I have not got a scope to confirm the precise flashing rate.
I can think of two options.
1) = by far the best as you will see real hardware running code from flowchart. If you buy EB006 multiprogrammer board and required Eblocks e.g LED, switches, LCD etc. Then its a simple case of plug, program and play.
You Get a 16F88 chip plugged in to programmer, which is what the flowchart is designed to control!

2) There is one simulator I know of that runs in real time (most simulators do not). (like Matrix Multimedia, I'm not affiliated with them at all). You can see it here:
http://digitalelectrosoft.com/
ItWasLuck3 wrote: microchips, I don't have one selected yet, but it sounds like I need to get one with internal PWM. Feel free to mention your favorites if you use those a lot.
The 16F88 is a good device to start with.
The actual choice does depend on you application. e.g. an all singing all dancing device with 40 or so pins is over kill to control just one flashing LED.
To determine correct device for you:
1st work out how many i/p's, o/ps you need taking in to account any peripherals e.g LCD displays, analogue pots, Switches etc.
Then follow links I posted here:
http://www.matrixmultimedia.com/mmforum ... 195#p22195
When you have narrowed down selection, Make sure Flowcode supports device.
Some devices like 16F1827 use the Hi-Tec Complier, so you need to follow the Hi-Tec thread found in articals.
As for internal PWM.
Yes there are much easier to control and I use built in PWM myself, but they do have limitations. E.g:
They used A fix pin labelled CCP1 and if more then one PWM is used,CCP2 as well.
If using a higher speed oscillator, you won't be able to get pwm to work at low frequencies.
E.g with 19.6MHz osc, the lowest frequency PWM will reduce to is 1.2KHz.
Last edited by medelec35 on Mon Feb 28, 2011 4:44 pm, edited 1 time in total.
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Thanks for the response. I want to just quickly mention that even though I'm not responding exactly to what you've said, don't feel like it isn't being used. You're help thus far has been spectacular. It really makes sense to why your a "valued contributor"!

Anyway, now that I'm comprehending the timer0 function, I had a different thought. Instead of doing all that complicated count stuff, couldn't you just set the timer interupt to the frequency level you want (i.e. 250ms = 2Hz, 100ms = 10Hz, etc), then in the "PWM_Handle" macro, just have a simple If statement. "If LED1 is on, turn it off. If LED1 is off, turn it on." Because it will continue looping at the given timer0 interupt, wouldn't that effectively cut out all the other stuff?

Now I'm sorry if your laughing at how dumb of an idea that is, but it was kinda the first thing that popped into my mind when I gras[ed the idea of the "timer0" function.

Oh and quick question, if I use a 8x1 LCD, instead of a 16x1 LCD, will it work? Just as long as I don't make any text longer than 8 lines obviously.

Khalid
Posts: 5
Joined: Fri Feb 11, 2011 5:14 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by Khalid »

Very informative thread. I have seen almost all the posts posted by medelec35 in other threads and found full of informations, friendly and helpful. Thanks medelec35 for your generous contribution to this forum.
Regards

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

Thanks for those kind words..
ItWasLuck3
and
Khalid.

You won’t be able to slow down timer0 enough so each time the interrupt macro is accessed the LED could change state.
Timer0 can be set the lowest, but that is only 15Hz, which is still too fast for your 2Hz application.

The PWM method was used so overall brightness of LED’s can be altered and to reduce overall power dissipated of components.

However, It can be simplified even further, so all you are doing is switch LED Fully on for 250mS, then off for 250ms.

To work out the best timer0 setting (i.e produces most accurate 2Hz).
For 2Hz you need divide by 4. this is because you will require equal on/off times.

Change the prescaler rate and divide each frequency by 4.

E.g with prescaler rate of 1:256 Fre = 15.259. so 15.259/4 = 3.8 = not very accurate.
If you use count>=4 you will get a frequency of about 1.9Hz
The goal is to get a result that produces a number to the nearest whole number.

After going though the lower range, best is prescaler = 1:16 = 244.141Hz


For 2Hz, you need 244.141 /(fre x 2)
= 244.141 / 4 = 61.035 so you use count>=61

Using this figure you should get a frequency spot on to 2Hz.

Hope this makes it clearer, rather than confuses.

Not sure about the LCD display. Sorry.
Attachments
Software_PWM_modified2.fcf
Simulation does not reflect actual flash times.
(6 KiB) Downloaded 405 times
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Hopefully this isn't me being stupid, but evertime I try and run the last flowchart you gave there (the modified2 one), it will never run. Like when I click play, it just sits there. But if a manually click F8 for the progression steps, the blue box will appear, but it just loops infinately in that empty loop box. Is my program acting up, or is that box not supposed to be empty? Or am I doing something wrong?

Besides that, I'm really making head way on my project. In the end, I'm pretty sure I'm going to drop the LCD and probably just use 2 indicator LED's, as I've discovered there is only 2 frequencies I need the LEDs to flash at. However, I'll still have to develop some sort of timing system. Like in your last example (or even the one before that)... I'll go ahead and believe that in real time, its actually 2Hz, but how would I tell it to only run 2Hz for say 10 sec on the push of a button? Obviously the button push could be implemented as a start, but just trying to answer my own question here, could you use another instance of the "timer0" function and tell it to run for 10 sec or whatever was defined. Then, whereever the program is when 10 sec is up, the macro can just be to stop the flashing and jump back to the main program loop?

Thank again.

Edit: I went ahead and downloaded Real Pic Simulator so I could see if it actually was running at 2Hz, but everytime I try and compile one of those examples you gave me, it says this:

Code: Select all

Software_PWM_modified(1): error:  failure

failure

Return code = 1

Flowcode was unable to compile the flowchart's C code due to the following errors:


If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.

FINISHED
And the only C code in the whole thing, is where we defined the interal osc frequency. Whats wrong?

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

Modified2 version I posted was a starting block. You can put any routines within the empty loop box. Although it looks like the program is doing nothing i.e keep going round the empty loop. In reality as explained in a earlier post the timer0 macro is being accessed on a very regular basis. In the case of Modified2 every 4ms. When correct time has elapsed, then LED on port A0 will toggle.
The reason you can't see the outline running is because the simulation speed is set to as fast as possible. If you slow down the simulation speed to say 1000 ('View','project options...')
then you will then see the outline appear and change as the simulator runs.
As for the error, C code is only a standard suggestion.
Are you running windows7? Normally when you compile to hex or chip, then you get a list of what the problem is.
With Windows7, these error messages can be suppressed.
1st dont save flowcharts in Libraries.
If you still don't get a list of the errors, than I have found a workaround (well works for me anyway)
Get a usb memory stick. Within Flowcode, click file, save as. then save on USB stick, then compile.
Finally do save as again but this time a folder on your harddrive e.g C:\Flowcode examples.
Reason for compile failure should now be displayed.

If you have modified the flowchart that I posted, then it does not compile,
1st take a look here:
http://www.matrixmultimedia.com/mmforum ... =26&t=6936

If you are still stuck. Post flowchart on here or send it to me, then I can check what the cause of failure is.
If you have not modified the flowchart, then post the files that have a c and txt extensions.
E.g Software_PWM_modified2.msg.txt (you may or may not see .txt at the end. Depends on your computer settings)
and
Software_PWM_modified2.c (you may or may not see .c at the end. Depends on your computer settings)
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

Well that USB trick worked! Funny why that is, but I'll take it nonetheless. I got the code running in "Real Pic Simulator" and I can see the LED flashing much faster than FlowCode had it. Now I know in RPS, the simulation speed is at like 4000000000, but do you know which value here would be closest to actual time? Or is there some sort of dianotic time featuer in that rpogram? And the only reason I bring those questions up on this FlowCode forum, is because you mentioned it, and perhaps you've used it before.

For now, I think you've got me occupied. Let me keep working in FlowCode and see if I can get to where I want now.

Thanks.

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

ItWasLuck3 wrote:Well that USB trick worked! Funny why that is, but I'll take it nonetheless.
Glad that worked for you. I discovered that trick by accident. Perhaps Matrix Multimedia are working on a fix as we speak?
On support, it is mentioned that an issue occurs if you compile within libraries folder of windows7, so that part was not my idea. But if saved in a different folder, for some reason did not work until saved via USB 1st.
ItWasLuck3 wrote: the simulation speed is at like 4000000000, but do you know which value here would be closest to actual time?
Since Simulator is running in real time, you need both settings same as Flowcode. I.e 4000000.
By the way, there is a scope feature within Real pic sim, so you can determine the flash frequency.
It works OK in windows7, but in my experience, works even better pre win7.
Martin

ItWasLuck3
Posts: 9
Joined: Fri Feb 25, 2011 12:32 am
Has thanked: 1 time
Been thanked: 1 time
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by ItWasLuck3 »

I'm actually still on Windows XP if you'll believe that and it works fine. It is a little jumpy though. In the real pic simulator that is. For example, I ran one of the files you posted, and though it did flash, it was at a pretty irregular rate, but perhaps the programs ability to simulate actually bypasses that of real life. And what I mean by that is that I was able to see every flash of the LED, even super tiny "micro" flashes as I'll call them, which may not be present in real testing.

Edit: And one more thing! When I have the program made, like one of your examples, how would I tell it to only run for say like 10 sec? Would I use another instance of the timer0 function to have it stop, then loop back into the main program loop?

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by Steve »

medelec35 wrote:
ItWasLuck3 wrote:Well that USB trick worked! Funny why that is, but I'll take it nonetheless.
Glad that worked for you. I discovered that trick by accident. Perhaps Matrix Multimedia are working on a fix as we speak?
On support, it is mentioned that an issue occurs if you compile within libraries folder of windows7, so that part was not my idea. But if saved in a different folder, for some reason did not work until saved via USB 1st.
We'll continue to look into why this is occurring, but it's a weird issue that seems to be out of our control. If we were doing anything "special" when saving files, then I'd understand.

mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by mouton63 »

Hello all,
My name is andrew & i would love some help with a very simple program.
I have a single LED & a single momentary push button on my flowcode 5.
the LED is off in normal simulation mode but must switch on (& stay on) when i press the momentary push button.
However, the LED must switch off if i press the push button again, kinda like a single button toggle switch.
I can get the LED to switch on but for the life of me i cannot get the LED to toggle with the push button... :shock:
If possible insert a flowcode example for me?
Application; to silence a buzzer when activated by a port but it must re-sound when a different port is activated.
Any help would be greatly appreciated :D

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: Pretty new to FlowCode, lots of questions!

Post by medelec35 »

Hi Andrew,
If you post your flowchart, I can alter it for you.
Are you using Flowcode V5 Professional, Home or free version?

If you want to try yourself then you can use something like.
Input:
Read input a1

Decision:
If input a1 = 1 then
Calculation: output =! output

Loop:
Delay 5ms
Input:
Read input a1
Loop:
while input a1 =1

Note =! is bitwise Not equal to.
so if output=1 then after output =! output
output = 0
e.t.c.
So it acts like a toggle function
output is just a variable. With V5 it can be a Bool.

Delay is just for switch contact debounce.


Martin
Martin

mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by mouton63 »

Hi Martin,

Thank you so much for your reply :)

I'm using V5 Professional
i have attached my program for toggle between two LED's, however i would like to toggle only one LED.
Thank you i will really appreciate your help.
I will try your method mentioned as well.
Attachments
Toggle switch.JPG
(157.59 KiB) Downloaded 3591 times

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by dazz »

Hi Andrew

Can you sign up to the V5 forum,s click the link in my sig it will take you to the sign up page, Once done can you start a thread there as it will enable more people to help you, also can you post your fcf file as its easier to help if we can run the flowchart

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm
Contact:

Re: Pretty new to FlowCode, lots of questions!

Post by mouton63 »

Hi Daz,

Thanx for the feedback.
i will go register soon.
I have tried to use Martin's idea but i think i might have it wrong... well, i do have it wrong coz its not working! :shock:
see attached fcf file
Martin, Daz,
i have included my fcf file for you.
Attachments
Flowcode1.fcf
(12 KiB) Downloaded 298 times

Post Reply