Latching switches?
Latching switches?
Morning all,
As I'm still at the "getting to know flowcade" stage I thought I'd try and expand some of the tutorials in order to understand more of the commands.
So, I'm trying to modify the "input from switches" tutorial so that the push to make switches will latch the LED's in the on state until another switch is closed where it will then be turned off and the second switches LED will light.
I'm at a loss as to how to do this at the moment, any ideas folks?
cheers
Gaz
As I'm still at the "getting to know flowcade" stage I thought I'd try and expand some of the tutorials in order to understand more of the commands.
So, I'm trying to modify the "input from switches" tutorial so that the push to make switches will latch the LED's in the on state until another switch is closed where it will then be turned off and the second switches LED will light.
I'm at a loss as to how to do this at the moment, any ideas folks?
cheers
Gaz
- 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: Latching switches?
Hello Gaz
You might want to look at this.
http://www.matrixmultimedia.com/Learnin ... Flowcourse
It is our free online course on Flowcode and will probably teach you a lot about using the software and programming in general.
You might want to look at this.
http://www.matrixmultimedia.com/Learnin ... Flowcourse
It is our free online course on Flowcode and will probably teach you a lot about using the software and programming in general.
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
- 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: Latching switches?
Bit manipulation of a byte can be done like this.
Bit shifting Left
say you have this 8-bit variable byte = 0b00000001
to bit shift left we could do the following.
byte = byte * 2
or
byte = byte << 1
They both will manipulate the byte to look like this byte = 0b00000010
Bit shifting Left
say you have this 8-bit variable byte = 0b00000001
to bit shift left we could do the following.
byte = byte * 2
or
byte = byte << 1
They both will manipulate the byte to look like this byte = 0b00000010
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: 75
- Joined: Wed Oct 28, 2009 2:37 pm
- Has thanked: 15 times
- Been thanked: 1 time
- Contact:
Re: Latching switches?
In C, you can do bitmanipulation on a port like this: PORTA = PORTA ^ 0x80 to switch bit 7 on portA on and off. But how do you do this operation in Flowcode?Benj wrote:Bit manipulation of a byte can be done like this.
Bit shifting Left
say you have this 8-bit variable byte = 0b00000001
to bit shift left we could do the following.
byte = byte * 2
or
byte = byte << 1
They both will manipulate the byte to look like this byte = 0b00000010
-
- 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: Latching switches?
Hiya Gaz.
Try this.
There is a very simple modification to Tut 06
If you push a switch, then release it, Only the corresponding LED Will light and stay latched. All other LED's will be off.
Al I did was add a decision branch:
If Switches > 0
send Value of Switches to portA
otherwise don't.
Try this.
There is a very simple modification to Tut 06
If you push a switch, then release it, Only the corresponding LED Will light and stay latched. All other LED's will be off.
Al I did was add a decision branch:
If Switches > 0
send Value of Switches to portA
otherwise don't.
- Attachments
-
- TUT_06 Modified FlowcodeV3.fcf
- (7 KiB) Downloaded 614 times
Martin
-
- 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: Latching switches?
Hiya TomasS
The Very simplest way to toggle bits of a port in flowcode is like this: Or you can control individual bits of a byte by:
Bit_Toggle = (Bit_Toggle XOR 0b11111111) AND 1
in a calculation box.
The value of 1 on the right is the bit of the byte you want to toggle.
E.g to toggle bit 3 use Bit_Toggle = (Bit_Toggle XOR 0b11111111) AND 4
The Very simplest way to toggle bits of a port in flowcode is like this: Or you can control individual bits of a byte by:
Bit_Toggle = (Bit_Toggle XOR 0b11111111) AND 1
in a calculation box.
The value of 1 on the right is the bit of the byte you want to toggle.
E.g to toggle bit 3 use Bit_Toggle = (Bit_Toggle XOR 0b11111111) AND 4
Martin
-
- Posts: 75
- Joined: Wed Oct 28, 2009 2:37 pm
- Has thanked: 15 times
- Been thanked: 1 time
- Contact:
Re: Latching switches?
Hi medelec35medelec35 wrote:Hiya TomasS
The Very simplest way to toggle bits of a port in flowcode is like this: Or you can control individual bits of a byte by:
Bit_Toggle = (Bit_Toggle XOR 0b11111111) AND 1
in a calculation box.
The value of 1 on the right is the bit of the byte you want to toggle.
E.g to toggle bit 3 use Bit_Toggle = (Bit_Toggle XOR 0b11111111) AND 4
Thanks for responding. I have tried to use your example, but using Timer0. Simulating it in Flowcode - no problem!, but when I downloaded it into my target, nothing happens. I've tried both on an STK500 and in E-blocks. Same result - no action
I am tryin to replicate the small C-program attached. Perhaps you can see the problem?
BR.
Tomas
-
- 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: Latching switches?
The problem I can see are:
You have selected the whole port and not the single bit as in the picture I have up loaded & you have set port B to 128.
Since ! = Not a single bit, then the 128 will go to 0, then will toggle from 0 to 1
Since you have enabled the whole port then only LSB (bit 0) will toggle.
Looking at C file what you want is to change Port_B = !Port_B
to
Port_B= (Port_B XOR 0b11111111) AND 128
And change
Port_B = 128
to
Port_B = 0
(if your interested in toggling whole port and not just a sing bit, instead of Port_B = !Port_B
use Port_B = ~Port_B)
One last thing. I don't know if it has changed by my importing your AVR file into PIC Flowcode. Your timer interrupt Clock source settings (accessed by double click on interrupt then select properties) is set for 'Transition on T0CKI pin' and should be on internal clock. (that's if AVR setting are similar to PIC)
My advice is run the flowcode simulation for a while, and see if correct LED is flashing.
If it is, but not flashing on your hardware, then problem could be with hardware or configuration settings.
Check the usual like wdt and lvp is disabled etc.
Change code temparary so the LED flashes without using timer interrupt i.e use delay component icons, then if led flashing at correct rate, then change back to timer interrupt.
You have selected the whole port and not the single bit as in the picture I have up loaded & you have set port B to 128.
Since ! = Not a single bit, then the 128 will go to 0, then will toggle from 0 to 1
Since you have enabled the whole port then only LSB (bit 0) will toggle.
Looking at C file what you want is to change Port_B = !Port_B
to
Port_B= (Port_B XOR 0b11111111) AND 128
And change
Port_B = 128
to
Port_B = 0
(if your interested in toggling whole port and not just a sing bit, instead of Port_B = !Port_B
use Port_B = ~Port_B)
One last thing. I don't know if it has changed by my importing your AVR file into PIC Flowcode. Your timer interrupt Clock source settings (accessed by double click on interrupt then select properties) is set for 'Transition on T0CKI pin' and should be on internal clock. (that's if AVR setting are similar to PIC)
My advice is run the flowcode simulation for a while, and see if correct LED is flashing.
If it is, but not flashing on your hardware, then problem could be with hardware or configuration settings.
Check the usual like wdt and lvp is disabled etc.
Change code temparary so the LED flashes without using timer interrupt i.e use delay component icons, then if led flashing at correct rate, then change back to timer interrupt.
Martin
-
- Posts: 75
- Joined: Wed Oct 28, 2009 2:37 pm
- Has thanked: 15 times
- Been thanked: 1 time
- Contact:
Re: Latching switches?
Hello again medelec35
Thanks for you reply. I have tried out your suggestions. Now the LED is flashing as wanted by changing the calculation done inside the macro to Port_B= (Port_B XOR 0b11111111) AND 128. I did forget to select the clock source prescaler to 1:1 for TMR0
Unfortunate I were able to simulate the program in Flowcode before uploading the program to the Forum.
Now I need to get the timing right. That isn't quite as easy as in the C-program uploaded.
BR.
Tomas
Thanks for you reply. I have tried out your suggestions. Now the LED is flashing as wanted by changing the calculation done inside the macro to Port_B= (Port_B XOR 0b11111111) AND 128. I did forget to select the clock source prescaler to 1:1 for TMR0
Unfortunate I were able to simulate the program in Flowcode before uploading the program to the Forum.
Now I need to get the timing right. That isn't quite as easy as in the C-program uploaded.
BR.
Tomas
-
- 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: Latching switches?
Your getting there, LED flashing is better then nothing happening at all.
The problem is the C code you posted, has got important information missing.
E.g timer0 interrupt settings. When you find that information, it would be easy to count from 6 to 250.
Although it says 250 I was a bit puzzled with:
if(++timecount == 1000)
Where is the 250?
It looks like counting from 6 to 1000, not 250?
The problem is the C code you posted, has got important information missing.
E.g timer0 interrupt settings. When you find that information, it would be easy to count from 6 to 250.
Although it says 250 I was a bit puzzled with:
if(++timecount == 1000)
Where is the 250?
It looks like counting from 6 to 1000, not 250?
That's easily done since the simulator will treat the flowchart as if it is set on internal clock, whether its set on internal clock or external pin.TomasS wrote:I did forget to select the clock source prescaler to 1:1 for TMR0
Martin
-
- Posts: 75
- Joined: Wed Oct 28, 2009 2:37 pm
- Has thanked: 15 times
- Been thanked: 1 time
- Contact:
Re: Latching switches?
Precise! No action = headachemedelec35 wrote:Your getting there, LED flashing is better then nothing happening at all.
It's because the xtal-frequency is 4MHz. Then I devide the clock by 8, getting a period of 2μs. Therefore the counter is to start counting from 6, generating an interrupt each 500μs. Timecount is then incremented each 500μs and then toggles the LED 2 times pr. second!medelec35 wrote:The problem is the C code you posted, has got important information missing.
E.g timer0 interrupt settings. When you find that information, it would be easy to count from 6 to 250.
Although it says 250 I was a bit puzzled with:
if(++timecount == 1000)
Where is the 250?
It looks like counting from 6 to 1000, not 250?
That's easily done since the simulator will treat the flowchart as if it is set on internal clock, whether its set on internal clock or external pin.[/quote]TomasS wrote:I did forget to select the clock source prescaler to 1:1 for TMR0
I don't really know if that's an advantage? By running a program that seems to work in the simulation, but a small omission will do that nothing works
Learning by doing...
BR.
Tomas