HELP WITH A PROGRAM
HELP WITH A PROGRAM
Hi all,
I wondered if anyone would be able to help me with a program I have which is essentially a counter using a 8 bit led and 2 switches. I have attached the program brief below. I have been stuck with this program for a while as I am struggling to understand how the LEDS can be stopped and then restarted when the switch is pressed from the same LEDs. I have had a go at the program but I am not happy with the result,
Anyway, I would appreciate it if you could look at the attachment and give any help, advice (or even example solutions which would be perfect).
Thanks once again.
I wondered if anyone would be able to help me with a program I have which is essentially a counter using a 8 bit led and 2 switches. I have attached the program brief below. I have been stuck with this program for a while as I am struggling to understand how the LEDS can be stopped and then restarted when the switch is pressed from the same LEDs. I have had a go at the program but I am not happy with the result,
Anyway, I would appreciate it if you could look at the attachment and give any help, advice (or even example solutions which would be perfect).
Thanks once again.
- Attachments
-
- Program counter.JPG (52.58 KiB) Viewed 14277 times
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: HELP WITH A PROGRAM
You could start by posting what you have created. We do not supply ready answers for courseware as that will not teach you anything...
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
Re: HELP WITH A PROGRAM
Yes you are right I should have attached my work!
My program uses 4 switches, as I couldn't work out how to do it with 2. I'm not sure if my program does what it says on the brief, as I'm still a little bit confused to what it is asking in terms of how the program should work. My program still doesn't work fully.
Attached is my program,
Thanks a lot
My program uses 4 switches, as I couldn't work out how to do it with 2. I'm not sure if my program does what it says on the brief, as I'm still a little bit confused to what it is asking in terms of how the program should work. My program still doesn't work fully.
Attached is my program,
Thanks a lot
- Attachments
-
- ex 7 prog 8 nv.fcfx
- (20.24 KiB) Downloaded 331 times
Re: HELP WITH A PROGRAM
Hi all,
I have done a few tweaks to the delay times for the program, so it runs smoothly. I just wondered how you can run two decision icon loops at the same time? As at the moment, the MSB LEDs count down and then the LSB LEDs count up and vice versa, but I believe this needs to happen in parallel. I am very new to flow code but I imagine there is a way of doing this.
Thanks
I have done a few tweaks to the delay times for the program, so it runs smoothly. I just wondered how you can run two decision icon loops at the same time? As at the moment, the MSB LEDs count down and then the LSB LEDs count up and vice versa, but I believe this needs to happen in parallel. I am very new to flow code but I imagine there is a way of doing this.
Thanks
- Attachments
-
- ex 7 prog 8 final using 4 switches.fcfx
- (20.51 KiB) Downloaded 329 times
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: HELP WITH A PROGRAM
How about using one loop with two decision trees? Have a variable set to true if a count down is required and false if not and a condition to check if that part of the code needs to run, same for count up.Jacob1 wrote:I just wondered how you can run two decision icon loops at the same time?
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
Re: HELP WITH A PROGRAM
The program does not seem to work? I'm not sure how the encoder works and when the simulation is played two LEDs light up.STibor wrote:sheep_counteer_2.fcfxHello!
I used an internal rotary encoder component.
Re: HELP WITH A PROGRAM
I have had to use 4 switches for my program which does now work. But could you explain a bit further what you mean by setting a variable true and how to do a condition check? Would it be possible for you to create a example of what you mean which might be easier for me to understand.kersing wrote:How about using one loop with two decision trees? Have a variable set to true if a count down is required and false if not and a condition to check if that part of the code needs to run, same for count up.Jacob1 wrote:I just wondered how you can run two decision icon loops at the same time?
Thanks
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: HELP WITH A PROGRAM
Hi Jacob1,
It looks like you're reading Introduction To Microprogramming - The complete course.
Have you been jumping straight into all the exercises, without reading from page 39 onwards first?
The idea is to complete the exercises only after reading the relevant parts of the course.
If you can't complete the exercises then more reading will be required first.
Only then ask if really stuck.
Take a look in the Learning centre
There are Flowcode Training Videos and other useful resources.
Another good place to visit is Flowcode V7 Wiki.
Martin
It looks like you're reading Introduction To Microprogramming - The complete course.
Have you been jumping straight into all the exercises, without reading from page 39 onwards first?
The idea is to complete the exercises only after reading the relevant parts of the course.
If you can't complete the exercises then more reading will be required first.
Only then ask if really stuck.
Take a look in the Learning centre
There are Flowcode Training Videos and other useful resources.
Another good place to visit is Flowcode V7 Wiki.
Martin
Martin
- STibor
- Posts: 263
- Joined: Fri Dec 16, 2011 3:20 pm
- Has thanked: 116 times
- Been thanked: 113 times
- Contact:
Re: HELP WITH A PROGRAM
Maybe I do not understand the question.Jacob1 wrote:The program does not seem to work? I'm not sure how the encoder works and when the simulation is played two LEDs light up.STibor wrote:sheep_counteer_2.fcfxHello!
I used an internal rotary encoder component.
https://youtu.be/wyFQ1l6FkWI
Re: HELP WITH A PROGRAM
The program you have sent is missing those two buttons above shown on the YouTube video, which is why maybe it is not working but I'm not sure.STibor wrote:Maybe I do not understand the question.Jacob1 wrote:The program does not seem to work? I'm not sure how the encoder works and when the simulation is played two LEDs light up.STibor wrote:sheep_counteer_2.fcfxHello!
I used an internal rotary encoder component.
https://youtu.be/wyFQ1l6FkWI
- STibor
- Posts: 263
- Joined: Fri Dec 16, 2011 3:20 pm
- Has thanked: 116 times
- Been thanked: 113 times
- Contact:
Re: HELP WITH A PROGRAM
Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
- Attachments
-
- sheep_counteer_3_fc6.fcfx
- (13.89 KiB) Downloaded 279 times
Re: HELP WITH A PROGRAM
When the switches are pressed no LEDs light up. I think it is opening it wrong on my laptop for some reason, I'm guessing as I can see it works on your You tube video fine. I've screenshotted the simulation, do I need to change anything or is ready to be simulated?STibor wrote:Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
Thanks for your help
Jacob
- Attachments
-
- Program simulation.JPG (106.32 KiB) Viewed 14156 times
Last edited by Jacob1 on Sun Dec 31, 2017 6:11 pm, edited 2 times in total.
Re: HELP WITH A PROGRAM
Hi,medelec35 wrote:Hi Jacob1,
It looks like you're reading Introduction To Microprogramming - The complete course.
Have you been jumping straight into all the exercises, without reading from page 39 onwards first?
The idea is to complete the exercises only after reading the relevant parts of the course.
If you can't complete the exercises then more reading will be required first.
Only then ask if really stuck.
Take a look in the Learning centre
There are Flowcode Training Videos and other useful resources.
Another good place to visit is Flowcode V7 Wiki.
Martin
I have been reading the Flow code 6 tutorials, which is the same as the content from page 39 onwards from the complete course booklet you stated. In my opinion, the tutorial content or the content from page 39 onwards from the complete course booklet doesn't cover all the program exercises that you have to complete. So it would be useful if they were more tailored to the exercises and if they were Flowcode 7 content not Flowcode 6. But that's just my opinion of the course booklet and I have been able to get most of the programs to work on simulation and with the micro controller itself, so I must be learning something!
Thanks for the links you have given me, I have managed to get the program to work but with 4 switches.
Jacob
- STibor
- Posts: 263
- Joined: Fri Dec 16, 2011 3:20 pm
- Has thanked: 116 times
- Been thanked: 113 times
- Contact:
Re: HELP WITH A PROGRAM
I think you do not fully test switch logic.Jacob1 wrote:When the switches are pressed no LEDs light up. I think it is opening it wrong on my laptop for some reason, I'm guessing as I can see it works on your You tube video fine. I've screenshotted the simulation, do I need to change anything or is ready to be simulated?STibor wrote:Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
Thanks for your help
Jacob
Example:
The sheep goes from right to left.
Initial value, left and right are 0 logical values.
4/1, right side switch logic value = 1, left side logical value = 0 (sheep activates right sensor)
4/2, right side switch logic value = 1, left logical value = 1 (sheep activates both sensors)
4/3, right side switch logic value = 0, left page logic value = 1 (sheep activates left sensor)
4/4, right side switch logic value = 0, left logical value = 0 (sheep on left side, end of cycle, increase of left counter, number display, etc.)
Re: HELP WITH A PROGRAM
STibor wrote:I think you do not fully test switch logic.Jacob1 wrote:When the switches are pressed no LEDs light up. I think it is opening it wrong on my laptop for some reason, I'm guessing as I can see it works on your You tube video fine. I've screenshotted the simulation, do I need to change anything or is ready to be simulated?STibor wrote:Opened in Flowcode v7, there are two pushbuttons.
Port A0 and PortA1 connected. I upload a Flowcode v6-v7 compatible program.
Thanks for your help
Jacob
Example:
The sheep goes from right to left.
Initial value, left and right are 0 logical values.
4/1, right side switch logic value = 1, left side logical value = 0 (sheep activates right sensor)
4/2, right side switch logic value = 1, left logical value = 1 (sheep activates both sensors)
4/3, right side switch logic value = 0, left page logic value = 1 (sheep activates left sensor)
4/4, right side switch logic value = 0, left logical value = 0 (sheep on left side, end of cycle, increase of left counter, number display, etc.)
Your right I wasn't testing it properly! I get how it works now, so from right to left both switches need to be pressed but then sensor 1 is turned off first as it has passed it, clever Out of curiosity, what does the encoder do in the program? Could you briefly explain how the program works as all the text is not in English?
Thank you for your help,
Jacob
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: HELP WITH A PROGRAM
Hi Jacob,
I have created a flowchart that uses loops, Switch component (2 branches) and decision icons.
In order to follow flowchart you need to know how the Switch component: works.
You also need to know how to do bitwise e.g etc.
Logic manipulation using etc.
Also and .
So you show you understand bit wise can you explain how I got to split the number of sheep in each pen on the left and right side of port B: Note only used one variable called to store and display the results,
As you can see, if the Left hand Paddock contains 5 = 4 + 1, then Right hand Paddock contains 1
Martin
I have created a flowchart that uses loops, Switch component (2 branches) and decision icons.
In order to follow flowchart you need to know how the Switch component: works.
You also need to know how to do bitwise e.g
Code: Select all
& |
Logic manipulation using
Code: Select all
&& ||
Also
Code: Select all
>>
Code: Select all
<<
So you show you understand bit wise can you explain how I got to split the number of sheep in each pen on the left and right side of port B: Note only used one variable called
Code: Select all
LefthandPaddock
As you can see, if the Left hand Paddock contains 5 = 4 + 1, then Right hand Paddock contains 1
Martin
- Attachments
-
- ex 7 prog 8 nv1.fcfx
- (22.2 KiB) Downloaded 214 times
Martin
Re: HELP WITH A PROGRAM
medelec35 wrote:Hi Jacob,
I have created a flowchart that uses loops, Switch component (2 branches) and decision icons.
In order to follow flowchart you need to know how the Switch component:Switch Comonent.pngworks.
You also need to know how to do bitwise e.getc.Code: Select all
& |
Logic manipulation usingetc.Code: Select all
&& ||
AlsoandCode: Select all
>>
.Code: Select all
<<
So you show you understand bit wise can you explain how I got to split the number of sheep in each pen on the left and right side of port B:Binary seperaton.png
Note only used one variable calledto store and display the results,Code: Select all
LefthandPaddock
As you can see, if the Left hand Paddock contains 5 = 4 + 1, then Right hand Paddock contains 1
Martin
Thanks for your example!
I will need to do some reading on logic manipulation and bitwise, is there a specific link I can go to for this is should I try the Flowcode wiki?
Thanks for your help once again
Jacob
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: HELP WITH A PROGRAM
You're welcome.
Also from page 75 of the course goes into bitwise operations a bit excuse the pun lol.
prev sensor variable is just to store the input value before it changes.
Its just use for comparing current input with the previous input.
that way you know which direction the sheep is going.
To make it easier for you, just single step by pressing F8.
change the switches and watch the variables within Simulation debugger change.
You can also watch the variables change value when simulation is running, but the simulation speed must not be on Normal!
Are you able to workout how the output works?
if you need anymore reading, one place to look is here.Jacob1 wrote:I have done some research regarding bite wise functions and logical but I am still unsure about how the program actually works. Especially for the prev sensor variable and the last output icon.
Also from page 75 of the course goes into bitwise operations a bit excuse the pun lol.
prev sensor variable is just to store the input value before it changes.
Its just use for comparing current input with the previous input.
that way you know which direction the sheep is going.
To make it easier for you, just single step by pressing F8.
change the switches and watch the variables within Simulation debugger change.
You can also watch the variables change value when simulation is running, but the simulation speed must not be on Normal!
Are you able to workout how the output works?
Martin
Re: HELP WITH A PROGRAM
Yeah the step into is great button!
I get why the prev sensors is used now, as it will stay in the loop until both switches have been turned on and one has been turned off, as this then means the while statement is false?
However, I'm a bit unsure as to why when both switches have been turned on and then when one is turned off the switch icon loop is chosen? Is this because the switch icon uses the old sensor or prev sensor as you've named it.
E.g When switch A0 is turned off it chooses the first switch loop, I thought these loops were only chosen when a switch is on?
As the switch loops will be 1,2,4,8,16,32..... and the loop is selected when the corresponding switch is chosen in binary.
Just still a little bit confused about the statements inside the loops etc
Thanks for your help
Jacob
I get why the prev sensors is used now, as it will stay in the loop until both switches have been turned on and one has been turned off, as this then means the while statement is false?
However, I'm a bit unsure as to why when both switches have been turned on and then when one is turned off the switch icon loop is chosen? Is this because the switch icon uses the old sensor or prev sensor as you've named it.
E.g When switch A0 is turned off it chooses the first switch loop, I thought these loops were only chosen when a switch is on?
As the switch loops will be 1,2,4,8,16,32..... and the loop is selected when the corresponding switch is chosen in binary.
Just still a little bit confused about the statements inside the loops etc
Thanks for your help
Jacob
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: HELP WITH A PROGRAM
I created the logic for changing LefthandPaddock value.
for decreasing LefthandPaddock (sheep going from left to right):
It's required to wait for 0 0 as it states the sheep can change their mind.
to increase LefthandPaddock:
so 1 1 is ignored.
The switch icon is for testing the logic conditions.
Have another look and see if you can see the above logic working as you step into the code?
Do you understand how the switch component function works?
Do you agree with the logic I used?
for decreasing LefthandPaddock (sheep going from left to right):
Code: Select all
A1 A0
1 0
0 1
0 0
to increase LefthandPaddock:
Code: Select all
A1 A0
0 1
1 0
0 0
The switch icon is for testing the logic conditions.
Have another look and see if you can see the above logic working as you step into the code?
Do you understand how the switch component function works?
Do you agree with the logic I used?
Martin
Re: HELP WITH A PROGRAM
medelec35 wrote:I created the logic for changing LefthandPaddock value.
for decreasing LefthandPaddock (sheep going from left to right):It's required to wait for 0 0 as it states the sheep can change their mind.Code: Select all
A1 A0 1 0 0 1 0 0
to increase LefthandPaddock:so 1 1 is ignored.Code: Select all
A1 A0 0 1 1 0 0 0
The switch icon is for testing the logic conditions.
Have another look and see if you can see the above logic working as you step into the code?
Do you understand how the switch component function works?
Do you agree with the logic I used?
Yeah im getting it now. As the switch uses the old sensor as its variable, which is only ever 1 or 2 so it selects that loop. In terms of the logic I belive you are right, but on mine the sim bugger shows this as 1,2,3 as in the binary value.
E.g left to right =
when A1 pressed
Sensor Oldsensor
2 2
When A0 pressed
Sensor Old sensor
3 2
When A1 pressed off
Sensor Old sensor
1 2
This brings me onto my next question, what does this statement mean "(Oldsensor <> Sensors) && (Sensors < 3)", especially <>?
So now the old sensor is 2 so the switch with number 2 is followed, the loop is followed causing:
Sensor Old sensor
1 1
When A0 is turned off the sensor total is now 0 so the while statement is false, as sensor has to be greater than 0 for it to continue
So now countdown can take place if the count variable is greater than 0
In terms of the final output icon, from left to right I believe the second bracket apply s which is (6 - Countvar & 15), this is how ive understood it:
6 = 0000 0110
15= 0000 1111
Count var = -1
E.g 6 = 6 -1 will be 5
So 6 - 5 AND 15
will be 0000 0001 AND 0000 1111
Total = 0000 0001 which is the first LED light up, this will continue for each cycle
Thanks!
Jacob
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: HELP WITH A PROGRAM
SoJacob1 wrote:This brings me onto my next question, what does this statement mean "(Oldsensor <> Sensors) && (Sensors < 3)", especially <>?
> greater than
< less than
<> not equals to
Which is the same as
You can use either method as the results should be the same!!=
So
Code: Select all
Oldsensor <> Sensors
Code: Select all
&& (Sensors < 3)
Putting it all together:
Value is only TRUE (1 in value) when value of (Oldsensor AND Sensors) are different AND the value of Sensors is less than 3.
Hope this helps to make it more clear?
Martin
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: HELP WITH A PROGRAM
Hi Jacob,
suppose there was 2 sheep in the left paddock.
Can you explain how the output will show the values of both left and right paddocks?
So basically can you explain how works.
You only partially explained in your last post.
Martin
suppose there was 2 sheep in the left paddock.
Can you explain how the output will show the values of both left and right paddocks?
So basically can you explain how
Code: Select all
(LefthandPaddock << 4 & 240) | (6 - LefthandPaddock & 15)
You only partially explained in your last post.
Martin
Martin