Re: PWM IC?
Postat: 26 juni 2010, 22:54:43
@sodjan Mjo jag kan hålla med om att jag vart lite ospecifik innan... Jo det går men känns lite waste att kasta bort en cog per pwm kanal
Svenskt forum för elektroniksnack.
https://elektronikforumet.com/forum/
Kod: Markera allt
unsigned int PWM[4],cntr=0;
while(1)
{
if(cntr==PWM[0]) LED_0=0;
if(cntr==PWM[1]) LED_1=0;
if(cntr==PWM[2]) LED_2=0;
if(cntr==PWM[3]) LED_3=0;
cntr++;
if(cntr==256)
{
cntr=0;
led_0=1;
led_1=1;
led_2=1;
led_3=1;
}
}
Skulle väl se ut så här någonting i SPIN.victor_passe skrev:Nu kan jag inte SPIN men typ såhär:
Kod: Markera allt
CON
PINMASK_LEDS = %1111 ' Pin 3..0
VAR
long stack[32] ' Ändras till lämplig storlek.
byte channel[4]
PUB Start
cognew(DimLeds,@stack)
PUB SetDim(x,value)
channel[x] := value
PRI DimLeds | cntr
dira |= PINMASK_LEDS
cntr:=0
repeat ' repeat forever and ever ...
if(cntr=>channel[0])
outa[0]:=0
if(cntr=>channel[1])
outa[1]:=0
if(cntr=>channel[2])
outa[2]:=0
if(cntr=>channel[3])
outa[3]:=0
cntr++
if(cntr==256)
cntr:=0
outa[0]:=1
outa[1]:=1
outa[2]:=1
outa[3]:=1
Kod: Markera allt
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
dl : "DimLeds"
rr : "RealRandom"
PUB Main | ran_led,ran_1,ran_2,i
dl.Start
rr.Start
repeat
ran_led := rr.Random // 4
ran_1 := rr.Random // 256
ran_2 := rr.Random // 256
repeat i from ran_1 to ran_2
dl.SetDim(ran_led,i)
waitcnt(160_000+cnt)