very simple question
TC
Posts: 1,019
Hello all
I am still learning spin. I am working with a LCD display that has a led backlight. I can control the backlight from the prop. I am trying to make the backlight flash while there is a problem, but the program must continue while the backlight is flashing. this is what I have so far.
PUB Flash (rate,control)
· repeat while control := 1
··· !outa [noparse][[/noparse]backlight]
··· waitcnt(((CLKFREQ * rate)/ 8) + CNT)
Now the program somewhat works, but it will not end when control = 0, and I cant change control. I am making a blacklight driver. I was thinking of running the backlight driver in a new cog (mostly because I dont understand what the manual is saying about "cognew" yet)
Thanks
TC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!
I am still learning spin. I am working with a LCD display that has a led backlight. I can control the backlight from the prop. I am trying to make the backlight flash while there is a problem, but the program must continue while the backlight is flashing. this is what I have so far.
PUB Flash (rate,control)
· repeat while control := 1
··· !outa [noparse][[/noparse]backlight]
··· waitcnt(((CLKFREQ * rate)/ 8) + CNT)
Now the program somewhat works, but it will not end when control = 0, and I cant change control. I am making a blacklight driver. I was thinking of running the backlight driver in a new cog (mostly because I dont understand what the manual is saying about "cognew" yet)
Thanks
TC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!
Comments
One is to start another cog to do the flashing and to stop that cog when the flashing is done ... you'll need to make sure the backlight is on after stopping the flashing
The other solution is to use one of the counters to flash the light. This requires that you not use the counter for anything else like frequency synthesis.
Along those lines, look at the Frequency Synthesis object from the Propeller Object Exchange. It will do what you want. You just have to call Synth("A",backlight,<frequency Hz>) or Synth("B",backlight,<frequency Hz>) depending on which identical counter you want to use (there's a pair of counters in each cog). When you're done flashing, just clear CTRA := 0 or CTRB := 0 depending on the counter you're using, then make sure the backlight is on by doing OUTA[noparse][[/noparse] backlight ] := 1. Before you call Synth to flash again, be sure to clear the output register bit for the backlight with OUTA[noparse][[/noparse] backlight ] := 0.
Obviously, you will need to have DIRA[noparse][[/noparse] backlight ] set up properly (set to output ... 1).
Thanks
TC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!
I beleive (and please correct me if I am wrong) that control should be a global variable for this method to work (unless Flash method is called whenever 'control' changes outside of a method, but it doesn't really make sense).
Gennady
TC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!
In you case if method is called once with control equal 1, repeat loop will go forever.
Again, that is how I understand it.
Gennady
Post Edited (Mike Green) : 8/13/2007 3:12:19 AM GMT
Note that you need a little more than the original code.
This implementation has Flash stop its own cog implicitly.
You have to do a cognew(Flash(4),@stack) whenever you
want to flash the backlight. When this Flash cog stops itself,
the backlight will turn off. The main program has to turn it on
again.
Post Edited (Mike Green) : 8/13/2007 3:58:30 AM GMT
TC
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
We all make mistakes when we are young………That’s why paste is edible!