Litle Problem with OUTA[17..23]
Anubisbot
Posts: 112
Hi , i still work on my PWM Object, and it works so far fine, but i tried to change mz spin so that only 8 pin will be used, and insted of a long i want to use a byte.
Here is the working code:
and here is what i try to do but it wont work my way...
I dont get it.. What do i miss...
Anubisbot
Here is the working code:
CON TableSize = 100 VAR ' Holds the value the output should take at each instant in time. long pwm_state[noparse][[/noparse]TableSize] long cogStack[noparse][[/noparse]30] PUB Start | i SetPWM(17,100) SetPWM(18,0) SetPWM(16,0) SetPWM(19,0) waitcnt( 5_000 + cnt ) coginit (3,pwm_loop,@cogStack) return PRI pwm_loop | t ' start the time value at zero ' PWM Loop dira[noparse][[/noparse]9] := 1 ' Make pin 0, pin 1, and pin 2 all outputs dira[noparse][[/noparse]19] := 1 dira[noparse][[/noparse]18] := 1 dira[noparse][[/noparse]16] := 1 dira[noparse][[/noparse]17] := 1 t := 0 repeat outa := pwm_state[noparse][[/noparse]t] ' Set states of all 3 pwm pins simultaneously t+ = 1 ' Change to the next state if t == TableSize ' If t goes off the edge of the table NOTE change t := 0 ' start over at beginning
and here is what i try to do but it wont work my way...
CON TableSize = 100 VAR ' Holds the value the output should take at each instant in time. byte pwm_state[noparse][[/noparse]TableSize] long cogStack[noparse][[/noparse]30] PUB Start | i SetPWM(17,100) SetPWM(18,0) SetPWM(16,0) SetPWM(19,0) waitcnt( 5_000 + cnt ) coginit (3,pwm_loop,@cogStack) return PRI pwm_loop | t ' start the time value at zero ' PWM Loop dira[noparse][[/noparse]23..17]~~ t := 0 repeat outa[noparse][[/noparse]23..17] := pwm_state[noparse][[/noparse]t]' Set states of all 3 pwm pins simultaneously t+ = 1 ' Change to the next state if t == TableSize ' If t goes off the edge of the table NOTE change t := 0 ' start over at beginning
I dont get it.. What do i miss...
Anubisbot
Comments
2) When you do "outa[noparse][[/noparse]23..17] := ...", you are assigning a 7-bit value (from %0000000 to %1111111) which would work fine except that your SetPWM routine assumes that you have a 32-bit value.
3) You could make this work by using "outa[noparse][[/noparse]23..17] := pwm_state[noparse][[/noparse] t ] >> 17"
4) Do remember that outa[noparse][[/noparse]23..17] and outa[noparse][[/noparse]17..23] are not the same. The bits are reversed in the second case.
Thank you for the fast help.. This Forum and their users are great.
Anubisbot