Strangw results when using PWM command
I've written a simple program to pulse a LED on GPIO.0 of a 12F675, which worked fine. However I didn't save the file, and so I started from scratch again this morning.. but I'm experiencing some strange behaviour.
This is the main body of the code:
Code:
led var GPIO.0
i var byte
up:
For i = 1 to 254
Pwm GPIO.0,i,1
if i = 254 then goto down
next i
down:
for i = 254 to 1 step-1
pwm GPIO.0,i,1
if i = 1 then goto main
next i
As you can see its a simple FOR/NEXT loop, that, should i reach a set value, goto either up or down section.
However when programmed, the LED ramps up in brightness but then fails to ramp down. I've tried remming out the up section and all that happens is that the LED flashes fast (as if i is not reducing by the step-1 command)
Code:
;up:
For i = 255 to 1 step-1
Pwm GPIO.0,i,1
;if i = 254 then goto down
next i
;down:
;for i = 254 to 1 step-1
;pwm GPIO.0,i,1
;if i = 1 then goto main
;next i
Its as if the PWM command or the step-1 statement is not being observed. And what's bugging me is I know it can be done as it worked before (the chip is now in cornwall so I can't read back the HEX !)
Comments anyone please !
There's ONLY ONE Dr' No's lamp !!!
Hi, Malc
I had just forgotten it was for your famous Dr Who's light ...
so, it could not work properly with such a soft ...
There was a thread you've already started about that ... you didn't find anything usable in it ???
http://www.picbasic.co.uk/forum/show...1754#post21754
I'll try to make a search ...
Alain
Seems the HPWM module of the 16F628a you saw was doing the job ... but may be the "slow PWM" thread from Darrel could help here !!! or use a 12F683 ...
better visual results ...
DEFINE OSCCAL_1K 1
ADCON0 = 0
ANSEL = 0
CMCON = 7
VRCON = 0
TRISIO = %00001000
led var GPIO.0
i var byte
y var word
up:
Pause 200
For i = 0 to 127
y = SIN i
Led = 1
Pauseus (y*y)
Led = 0
Pauseus ( 16129 -(y*y) )
next i
GOTO up
END