!!!PWM Question!!!
Hello forum , i would like to generate 3 PWM phase-shifted , can somebody guide me to generate them? i started from the PWM in the object exchange, file name ( Dedicated pwm generator) , and i changed the code to make wait for the cog but it's seems on the ocsilloscope on pin1 is ok , the Pin7 is not . my code is in the attachment .
Thank you for your help .
Post Edited (gambrino) : 4/15/2009 2:05:25 PM GMT
Thank you for your help .
Post Edited (gambrino) : 4/15/2009 2:05:25 PM GMT

Comments
to me it is not clear want you want to do
can you post a drawing with all three channels and how they should depend from each other ?
best regards
Stefan
i add to the first post the picture of the 3 signals .
Thanks
Thanks
It is the same as always:
As soon as more information is provided NEW solutions can be suggested
To all other forum members especially the newbies:
As you can see from this example it is EXTREMLY useful to provide quite a lot information
in your posting. The members of THIS forum are ALL patient enough to read 10-50 well formatted lines of text
and who doesn't will just surf to another thread
As the ANN1-democode dedicates a cog to run it anyway you can use for example
the code shown below which requires one cog too.
In your picture the ON/OFF-Ratio for all 3 channels is 1:2
Depending on the maximum frequency you can do this easily in SPIN
For different frequencies simple change the resulting value of Delay
''Phase_shiftet_Pulse_Out CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Bit_Pattern1 = %100 Bit_Pattern2 = %010 Bit_Pattern3 = %001 WaitTicks = 385 'minimum waittime in SPIN OBJ debug : "FullDuplexSerial_Configurable" '"FullDuplexSerial" Var long Delay PUB TestBitPattern DirA[noparse][[/noparse]20..22] := 7 ' set 3 bits as output 1 + 2 + 4 = 7 OutA[noparse][[/noparse]20..22] := 0 Delay := WaitTicks repeat WaitCnt(Delay + Cnt) OutA[noparse][[/noparse]20..22] := Bit_Pattern1 '3 bits in Bit_Pattern fit into the 3 bit definition 20..22 WaitCnt(Delay + Cnt) OutA[noparse][[/noparse]20..22] := Bit_Pattern2 WaitCnt(Delay + Cnt) OutA[noparse][[/noparse]20..22] := Bit_Pattern3In SPIN there is a minimum-value for waitcnt it is 385 this gives a frequency of 16,8 kHz.
If this isn't fast enough you can do the same in ASM
best regards
Stefan
Post Edited (StefanL38) : 4/7/2009 5:30:16 PM GMT
Let me know how this turns out.
Cheers!
Paul Rowntree
{{ trial code to generate 3 phase-shifted outputs p. rowntree April 2009 Use at own risk }} con CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 apin = 8 bpin = 9 cpin = 10 var long High_Cnt long Stack[noparse][[/noparse]20] ' I have no idea if this is large enough long Cog, Success pub Main | f Success := (Cog := cognew( ThreeSpinWaves, @Stack) +1 ) repeat repeat f from 10 to 50 High_Cnt := CalcWaitCnt( f ) ' f is the cycle frequency, how many times to do an A-B-C sequence per second repeat 10 ' apply this speed for 10 seconds waitcnt( clkfreq+cnt ) pub CalcWaitCnt( Hz ) result := clkfreq if Hz <> 0 result := clkfreq/(3*Hz) pub ThreeSpinWaves ' set the three pins to be outputs in this cog dira[noparse][[/noparse] apin ]~~ dira[noparse][[/noparse] bpin ]~~ dira[noparse][[/noparse] cpin ]~~ ' continually output the waves ' changing the value of High_Cnt will change the cycle frequency ' repeat outa[noparse][[/noparse] apin ]~~ waitcnt( High_Cnt+cnt ) outa[noparse][[/noparse] apin ]~ outa[noparse][[/noparse] bpin ]~~ waitcnt( High_Cnt+cnt ) outa[noparse][[/noparse] bpin]~ outa[noparse][[/noparse] cpin ]~~ waitcnt( High_Cnt + cnt ) outa[noparse][[/noparse] cpin ]~Cheers!
Paul Rowntree
Thank you in advance.
Cheers!
OK looked and found this http://obex.parallax.com/objects/414/