Ctrmode ?
I have been doing a lot of reading and playing with sample codes( Spin language), but I’m missing something.
I believe the code I need will only be a dozens lines, so I keep reading and trying.I want to control the speed of a motor( in Propeller Assembly language with spin language at the begining) input (1 up to 4KHz and duty cycle 50%).I don't know in this case what is better to choose CTRMODE : %0001X for clock generation or CTRMODE : %0010X NCO ????
NB: i don't need to generate a PWM signal, the synth.spin in library working perfectly to my needs.
Thank you in Advance
Post Edited (anita1984) : 11/9/2008 5:11:06 PM GMT
I believe the code I need will only be a dozens lines, so I keep reading and trying.I want to control the speed of a motor( in Propeller Assembly language with spin language at the begining) input (1 up to 4KHz and duty cycle 50%).I don't know in this case what is better to choose CTRMODE : %0001X for clock generation or CTRMODE : %0010X NCO ????
NB: i don't need to generate a PWM signal, the synth.spin in library working perfectly to my needs.
Thank you in Advance
Post Edited (anita1984) : 11/9/2008 5:11:06 PM GMT

Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
CON _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 VAR long ctr, frq PUB Go | freq SynthFreq(1,1_500) CTRA := ctr FRQA := frq DIRA~~ repeat waitcnt(0) PRI SynthFreq(Pin, Freq) | s, d Freq := Freq #> 0 <# 128_000_000 if Freq < 500_000 ctr := constant(%00100 << 26) s := 1 else ctr := constant(%00010 << 26) d := >|((Freq - 1) / 1_000_000) s := 4 - d ctr |= d << 23 frq := fraction(Freq, CLKFREQ, s) ctr |= Pin PRI fraction(a, b, shift) : f if shift > 0 a <<= shift if shift < 0 b <<= -shift repeat 32 f <<= 1 if a => b a -= b f++ a <<= 1I am trying to convert it to Assembly propeller language , but i found alot of difficult
Thank you for you answer
Post Edited (anita1984) : 11/10/2008 8:55:15 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
But if you are looking on how to do it to teach yourself,· or you intend to do more complex things in assembly (either with the counter, or not), you would use a modified version of the program listed on page 7. It would be modified to look like:
''Demonstration of NCO counter mode CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB go cognew(@entry, @parameter) 'start assembly cog repeat DAT org entry mov dira, diraval 'set APIN to output mov ctra, ctraval 'establish counter A mode and APIN mov frqa, period 'set counter to flip 1,500 times per second :loop jmp #:loop 'loop for next cycle diraval long |< 1 'APIN=1 ctraval long %00100 << 26 + 1 'NCO/PWM APIN=1 period long 80530 '1.5kHzThe value 80530 was obtained by using AN001 equation 1, setting fHz = 1500 and system frequency to 80,000,000 and solving for FRQA.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Post Edited (Paul Baker (Parallax)) : 11/17/2008 4:45:50 PM GMT
I am doing some counter work and reviewed the AN001 and did some searching and came across this post. In your example above, I see you calculated a period, but it isn't used in the code you posted. Did you mean to include a loop with waitcnt and the period?
I am trying to use the AN001 page 7 example. I have an assembly routine for an LCD I am working on. The routine has different commands for sending commands or data to the display. One of the commands I am setting up is for the LED back light. I would like to use a counter to control the back light. With this method the counter can be set and the code can go on and do other work. I am searching out examples and posts and the AN001 so I can learn more about the counters. How many years have I been using the chip I haven't done counters yet? There is no excuse.
Anyway, I looked at page seven of AN001 and tried implementing it in assembly. The pin for the back light is passed to the routine so I can't declare it in the defined data of the DAT section like you did.
Here is what I have. blPin is brought over from copying in parameters. blPin is the pin value, not the pin mask. Prior to this piece of code the pins are set to outputs or inputs.
mov ctraval,#%00100 'Load in the NCO/PWM configuration shl ctraval,#26 'Move it to the proper position add ctraval,blPin 'Add in the pin value mov ctra, ctraval 'Load the counter register mov frqa, #1 'Load the frequency registerIn the command section of the code I have this.
neg phsa, paramA 'Update the counter with the new valueparamA would range from 0 to 100. So far I think something is wrong. When the code is run and paramA is 0, the LED is on. When paramA is 100 the LED is on and the same intensity. To be sure it was not the passing of paramA I replaced it with #0 and #100 and the LED is still on in both cases. I was expecting that with #0 the LED would be off and #100 the LED would be full on.
Perhaps clarifying what I am doing in my code can help anita1984 too for an example of what to put in his code. I am trying to set the counter to PWM the LED to a certain intensity. My goal is to set the counter, leave and forget about it unless the intensity needs to change.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto fo SunSPOT, BitScope
www.tdswieter.com
I still don't understand the posted example you made Paul. Should the waitcnt and duty be in the code?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, uOLED-IOC, eProto for SunSPOT, BitScope
www.tdswieter.com