Simple question for first-time propeller user.
ViktorSigg
Posts: 6
Hi everyone!
I have been lurking these forum since I found out about the propeller MCU a couple of months ago, and recently got one myself (QuickStart board).
I'm new to Spin, but I'm a regular user of PIC MCU's with C and Assambler, so I'm not a newbe with MCU's and coding. Though there is a problem I have bumped in to, and
I would love if someone could give me an answer to this problem of mine.
Now, as you might have guessed, I'm trying to get a simple PWM output on pin 23. But, as you also might have guessed, it doesn't work!
The reason is the red marked code on_led at waitcnt (you can't miss it). It seems that you can't use variables with waitcnt(), which appears a bit weird to me.
If I change the on_led to 100_000 then it uses ~10% pwm output. With other words it works if I change the variable.
I'm sure there is a way, and perhaps someone could enlighten me??
/Viktor
I have been lurking these forum since I found out about the propeller MCU a couple of months ago, and recently got one myself (QuickStart board).
I'm new to Spin, but I'm a regular user of PIC MCU's with C and Assambler, so I'm not a newbe with MCU's and coding. Though there is a problem I have bumped in to, and
I would love if someone could give me an answer to this problem of mine.
{ Flashes a led on pin 23 with a user selected pwm output. } CON _clkmode = xtal1 + pll16x 'Define crystal input multiplier, 5 Mhz x16 = 80 Mhz _xinfreq = 5_000_000 'Crystal input = 5Mhz PUB COG_0 | on_led dira[7]~ 'Direction of pin 7 is input. dira[22]~~ 'Direction of pin 22 is output. dira[23]~~ 'Direction of pin 23 is output. on_led := 0 repeat 'Checks the button if it is active. if ina[7] == 1 outa[22]~~ 'on_led := 100_000 'Blinks the led in the desired pwm frequency. !outa[23] waitcnt([COLOR=#ff0000]on_led[/COLOR] + cnt) !outa[23] waitcnt(900_000 + cnt) 'PRI COG_1 'PRI COG_3 'PRI COG_4
Now, as you might have guessed, I'm trying to get a simple PWM output on pin 23. But, as you also might have guessed, it doesn't work!
The reason is the red marked code on_led at waitcnt (you can't miss it). It seems that you can't use variables with waitcnt(), which appears a bit weird to me.
If I change the on_led to 100_000 then it uses ~10% pwm output. With other words it works if I change the variable.
I'm sure there is a way, and perhaps someone could enlighten me??
/Viktor
Comments
So the waitcnt will wait for the current value of cnt. Which will come around in 40 seconds or so when the counter rolls over.
I believe there are some examples in the Propeller manual about this.
Welcome to the forum by the way. I'm sure you will like the Propeller. It's a bit weird compared to run of the mill PIC and AVRs but has powers and ease of use you will come to appreciate. The folks around here are always ready to help out if need be.
The problem is that the program does not work anyway though, with or without the "on_led 100_000". The only thing that makes it work is when I change the "on_led" to a defined value.
The propeller does not respond to anything at all when the program runs. Atleast it would light up the led at pin 22 when putting pin 7 high, but no response from the board what so ever.
I'm confused and tired, just though someone would know the answer right away before starting digging through all the PDF's. :P
Say what you want, but I must say that the sources of knowlede seems to be rather outspread everywere...
The buttons on the QuickStart are a little bit unusual. They aren't on/off switches but capacitive switches. Check out this demo code.
You actually need to charge them up and then read them as they discharge to see if they have been touched. There were many threads discussing them when the QuickStart first came out.
Yes, that was something I never thought of, and I will sure keep that in mind!
But the waitcnt works if I manually put value 100_000 there, but not with a varable that is set to 100_000. Strange.
Yes, I figured that out, but the input I'm using is a 5V signal output from a VM167 board, that goes through a voltage divider to 3.3V. And that works with other programs I've tested, but not this one. The whole systems stalls direktly when loaded onto board. :S
I think the last post in the thread has a link to instructions on how to use the touchpads as buttons.
My QuickStart servo tester is an example of using touchpads as buttons (and I think it's kind of a cool one).
And from what you say I gather the LED does not come on, i.e. "outa[22]" is not being tweaked.
Which implies that the ina[7] is never becoming 1.
Is that really connected properly?
BTW, You don't really need a voltage divider. As long as you use limit the current through the clamping diodes to 500uA the Prop I/O pins are 5V tolerant. A 3.3K resistor of larger is enough to keep the current at a safe level.
Sorry, seems I was not really clear when I described the symptoms.
When I press F10 with the code that I have described above (without the out-commented line), the board fires up,, and led 23 lights up to 100%. Then it all stalls. It won't respond to input (i.e. lighting up led 22 when input 7 is put high).
I now know a "kind of solution" to the problem. If I declare the "on_led" to 400, it will act more or less normal. Check the code:
This works. BUT, it will only light led 23 for as long as pin 7 is high. It toggles with pin 7, but at least it toggles between ~0 (not visible) and 10%. :P
And, as mentioned, if I use the IF statement thet is commented out, it will stall the program and lighten up pin 23 to 100% as soon as I put pin 7 high.
EDIT: STUPIFIED AGAIN! Syntax error with >= operator... Should be => Poop!
EDIT2: Well you know what? One should not try to learn programming Spin while being tired after a whole day's work. I see now that the If statement is working perfect, just me that is now doing so well anymore... The if statement was under the If statement above, and the result is that the led will turn off as the on command does not happen until I put pin 7 high... sigh! Thanks anyway for the help guys! I learned a lot today. About my incompetence that is. :P
Good to know, thank you!
I must say that the forums seems to be way more friendly than I thought. Thanks to all of you!
By commenting out that "if on_led ..." you have made the "outa[23] := 1" and following waitcnt conditional on the first "if" statement. That indentation matters.
Any way, if on_led is zero when you hit that "waitcnt(on_led + cnt)" it is going to be stuck there until cnt rolls over, about 40 seconds I think.
I would start by taking away all the INA testing and just set on_led to 100_000 or whatever the do the repeat loop and see if the LED toggles.