can't get pwmout to work on 14M

zovirl

New Member
I'm having trouble getting pwmout to work on my 14M. I have an LED hooked up to out 2. I know it works because a simple 'high 2' makes it light up. However, I can't get it to light up to any pwmout command. I've tried 'pwmout 2, 99, 200' (50%), 'pwmout 2, 199, 800' (slower, 100%) plus several others and the LED stays dark.

I tried doing PWM manually and it works:
Code:
main:
  high led
  low led
  goto main
I'm stuck, I'm not sure what to try next. Any ideas?
 

eclectic

Moderator
Zovirl.

Please read Manual 1 page 70 then manual 2 page 115.

The 14M pwmout pin is physical LEG 5,
which is normally an input.

e.
 

zovirl

New Member
Thanks Eclectic, that certainly got me closer. I have my LED connected to leg 5 now. 'high portc 5' makes it light up so I know that's working. However, I still can't get pwmout to light the LED. I've tried several combinations:

Code:
pwmout 2, 99, 200
Code:
pwmout portc 5, 99, 200
Code:
high portc 5
pwmout 2, 99, 200
Code:
dirsc = %00111111
pwmout 2, 99, 200
I feel like I'm missing one last basic piece. The 1st manual's Appendix A has lots of details on how to use the portc pins as digital in, out, and analog in, but the section on using portc for pwm is very terse:
C5 can be used with the pwmout command, but will make this pin an output.
Pins C2-5 (hpwm A-D) can all be used with the hpwm command, but will also
make the corresponding pins outputs.
 

inglewoodpete

Senior Member
zovirl: You are missing 1 valuable piece of information. Have a close look at Page 70 (Appendix C) of Manual 1 (Introduction).

Output C5 is the same pin as Input 2. You are addressing the wrong pin with the PwmOut command. Try PWMOut c5, 99, 200 (I don't have a 14M to test this on)

Edit: Hmm. I'm having doubts about this solution too. What does the simulator do with the various commands you have tried? It may give a lead as to what pin is the real PWM pin.
 
Last edited:

eclectic

Moderator
Zovirl.
I've just tried these on a 14M.
Try program 1, then try program 2

Code:
'prog 1
'main:
'pwmout 2,100,200
'stop

'prog 2
main:
for w0 = 1 to 400
pwmout 2,100,w0
pause 10
next

for w0 = 400 to 1 step -1
pwmout 2,100, w0
pause 10
next
goto main
e
 

BCJKiwi

Senior Member
Have following code functioning on a 14M at 8Mhz - modulates LED brightness with change in ambient light level by adjusting the LED supply voltage via PWM;
Code:
' Vary LED Brightness
ReadADC LDR,b0
' Monitor ADC values during setup - Anderson K107 LCD Chip
' If pin4 = 1 then sertxd(" ADC = ",#b0,"?n") ' Pin4 is high only on testing
' Pause 500
' Goto Main
EndIf
' Vary LED Intensity depending on ambient brightness
If    b0 > 225 then pwmout 2,249,1000 '100% duty cycle
 ElseIf b0 > 200 then pwmout 2,249,900 ' 90% duty cycle
 ElseIf b0 > 175 then pwmout 2,249,800 ' 80% duty cycle
 ElseIf b0 > 150 then pwmout 2,249,700 ' 70% duty cycle
 ElseIf b0 > 125 then pwmout 2,249,600 ' 60% duty cycle
 ElseIf b0 > 100 then pwmout 2,249,500 ' 50% duty cycle
 ElseIf b0 >  75 then pwmout 2,249,400 ' 40% duty cycle
 ElseIf b0 >  50 then pwmout 2,249,300 ' 30% duty cycle
 ElseIf b0 >  25 then pwmout 2,249,200 ' 20% duty cycle
 ElseIf b0 <  26 then pwmout 2,249,100  ' 10% duty cycle
EndIf
 

zovirl

New Member
I got it working! Thank you so much everyone. The last piece I was missing was the 'stop' at the end of the program. This doesn't work:

Code:
pwmout 2, 99, 200
But this one works:
Code:
pwmout 2, 99, 200
stop
Obviously time for me to go back and read up on picaxe BASIC.
 

hippy

Technical Support
Staff member
The last piece I was missing was the 'stop' at the end of the program
Without anything at the end, the program grinds to a halt, like getting home and going to bed with no intention of ever waking up again, ever. There's an implied 'End' at the end of every program even if it's not written there.

'Stop' isn't quite so severe as 'End', and allows things to keep ticking along. It's the same as using -

-- Label:
-- GOTO Label

or

-- DO : LOOP
 
Top