PWMOUT and 18X problem

ashleyps

New Member
I am using a pic18x with a CAT4101 Led driver to control 3 Cree 3W Led, but I can´t find any kind of light using the PWMout command, I have tried any combination from 0-255 for period, and 0-1023 for duty but I can't obtain any light from the led.
I have also tried with Pulsout command to check the circuit and work fine, I get diferent brightness from the led.
 

kevrus

New Member
Looking at the datasheet, thePWM control is on pin1 of the cat4101 (labelled EN/PWM). As it works with 'pulsout', then it looks like the problem could be your code/connection configuration. Have you got the cat4101 connected to the correct pin on the 18x as not all pins support the PWMOUT command. Use output 3 which is physical leg 9.
Could you post your code?


It does say in the datasheet that EN/PWM needs to be low for to least 5mS, but if you tried all values of PWM then you should have covered that
 

hippy

Ex-Staff (retired)
From the datasheet - Accurate linear dimming is compatible with PWM frequencies from 100Hz to 5kHz for PWM duty cycle down to 1%. PWM frequencies up to 50kHz can be supported for duty cycles greater than 10%.

Could be a circuit error, poor selection of PWM frequency or duty or perhaps you are updating the PWM too frequently ?

It would help if you can post your circuit and program.
 

ashleyps

New Member




and I have tried with this code changing the period value manually

Code:
symbol led = b0
for led = 1 to 1023
pwmout 3 , 99 , led
pause 5
next
With this code leds turn on dimming from 0% to 100%
Code:
symbol led = B0
Main: 
for led = 1 to 255
pulsout 3, led
pause 5
next
goto main
 
Last edited:

BCJKiwi

Senior Member
Only one observation;

There is a restricted range for pwm on the device - 100Hz to 5kHz for 1% duty and up to 50kHz for over 10% duty.

Suggest the minimum Picaxe PWM rate be tried which is 4kHz (at standard clock speed).

This means pwmout 3, 249, led with led ranging for 10 to 1000 for duty of 1 to 100%

Also recommend the use of pwmduty (on a 28X1) rather than pwmout as pwmduty just changes the duty whereas pwmout retsarts the whole pwm system in the chip.
 

sghioto

Senior Member
ashleyps,

I believe the code should be:
Code:
symbol led = w0                    ' need word variable to handle number above 255
main:    for led = 1 to 996        ' duty cycle should not exceed  4 X the period
          pwmout 3 , 249 , led    ' need lower frequency per specs of the Cat4101
          pause 5                     '  "Accurate linear dimming is compatible with PWM
          next led                        frequencies from 100Hz to 5kHz for PWM duty cycle
          goto main                      down to 1% "  ( from data sheet )
Steve G.
 

ashleyps

New Member
Hi BCJKiwi, I have tried this code
Code:
symbol led = b0
for led = 1 to 1000
pwmout 3 , 249 , led
pause 5
next
and sghioto,
I have tried
Code:
symbol led = w0                    ' need word variable to handle number above 255
main:    for led = 1 to 996        ' duty cycle should not exceed  4 X the period
          pwmout 3 , 249 , led    ' need lower frequency per specs of the Cat4101
          pause 5                     '  "Accurate linear dimming is compatible with PWM
          next led                      '  frequencies from 100Hz to 5kHz for PWM duty cycle
          goto main                     ' down to 1% "  ( from data sheet )
But nothing happen... :confused:
 
Last edited:

sghioto

Senior Member
ashleyps,

Sounds like the minimum PWM of 4KHZ is too fast for the CAT4101 though the specs say different. If using the "pulsout" command works as you say, then the PWM frequency with a 5ms pause ( also considering the delay time to execute the code ) might be 150Hz.

Steve G.

Maybe you should eliminate the "pause 5" command.
Code:
symbol led = w0                    
main:     for led = 10 to 996        
            pwmout 3 , 249 , led                                   
            next led                      
            goto main
 
Last edited:

ashleyps

New Member
sghioto,
Thanks for your help, but I don't know what happen because the led are dead, I have tried all the code posted for you and nothing work. :confused:
 

sghioto

Senior Member
ashleyps,

That's too bad. I don't have a CAT4101 to verify the code myself. So again the LEDs work if you "pulsout" the chip but do not work using PWM, is this correct? If "pulsout" works how short a "pause" command can you use. Meaning, will it work using a "pause 1" .

Steve G.
 

BeanieBots

Moderator
Disconnect the Cat4101 from the PWM output and just connect a simple LED/resistor to it. That will at least confirm if your PWM signal is working.
If it is then, must be frequency issue with the Cat4101 which can be got around by underclocking the PICAXE.
If it isn't, then something wrong with wiring or PICAXE.
 

premelec

Senior Member
I agree BB in the right direction and would add just put an LED and resistor on that PWMOUT pin to V- and test it BEFORE you disconnect the CAT# - if you don't get a signal shown on the LED then leave it connected and remove the connection to the CAT chip - see if the LED shows then - possibly there is low impedance at the CAT chips PWM input - anyway time to isolate the problem... does the PULSOUT still work? good luck!
 

BCJKiwi

Senior Member
Since the part should run at up to 50kHz pwm for duties above 10%, it should not be an issue of the minimum Picaxe pwm being too fast (at least down to 10% duty).

Do you have a 28x1 to try with the pwmduty command?

Do you have the decoupling cap installed? (shown on the sample circuit but not on your circuit).
 

vk6bgn

New Member
Ashleyps, Sounds like the minimum PWM of 4KHZ is too fast.....
If the PWM 4KHz. is to fast, maybe try putting this right after the PWM 3, 249, Led
It should slow things down a bit.

POKE $12, $05 'provides a pre-scale of 1:4 (1000Hz)
or
POKE $12, $06 'provides a pre-scale of 1:16 (250Hz)


If everything else tests OK, maybe this is worth a try?

Merry Christmas from Outback Australia :)
 

ashleyps

New Member
BeanieBots and premelec,
Good idea, I have tested with just a led/resistor and don't work, it's confirm is not a CAT4101/Frequency problem, I'm going to check tomorow using a PICAXE-18 Starter Pack AXE002 to discard wiring issue.
 

ashleyps

New Member
I have tried with the PICAXE-18 Starter Pack AXE002, and the pwm doesn't work, I'm using a computer power supply with 5.02V
 

sghioto

Senior Member
ashleyps,

The PWM only works using the 18X in that series. Are you sure the chip on the breadboard was a 18X ? The number on the chip should be PIC16F88 .

Steve G.
 
Last edited:

ashleyps

New Member
ashleyps,

The PWM only works using the 18X in that series. Are you sure the chip on the breadboard was a 18X ? The number on the chip should be PIC16F88 .

Steve G.
The exactly number on the chip is PIC16F88-I/P and 07282A5 in the second line.

I also have tried to download a code to the chip using 18 and 18A setup and always get an error, only 18X setup work fine.
 

BeanieBots

Moderator
BeanieBots and premelec,
Good idea, I have tested with just a led/resistor and don't work, it's confirm is not a CAT4101/Frequency problem, I'm going to check tomorow using a PICAXE-18 Starter Pack AXE002 to discard wiring issue.
It does NOT confirm it's not a CAT4101/frequency problem. It only only confirms that you are not yet even in a position to know if there is CAT4101/Frequency problem.

First, you need to get the PWM working on an 18X.
(as mentioned earlier, the 18X is the ONLY chip in the 18 series which supports PWMout).
 

sghioto

Senior Member
ashleyps,

Try operating the circuit using batteries. If this code will not operate a LED/resistor connected to leg #9 on a 18X then there is something wrong with the chip.
Code:
main: for w0 = 1 to 1000
        pwmout 3,249,w0
        pause 5
        next w0
        goto main
Steve G.
 

premelec

Senior Member
Does the code run ok in the editor simulator? Are you sure you are connected to the correct 18x pin? Only one pin will take the PWMOUT if I recall correctly... and it's too easy to confuse leg #s with PIN#s - persist!
 

Dippy

Moderator
16F88 is the 18X.

Step No.1 should have been to see if the PICAXE was outputting PWM on pin 9 directly, but we got there.

So, have checked your test LED?
Have you got it the right way round?
Have you 'scoped the PWM pin?
Have you done a simple high/low test on that pin (and the other PICAXE output pins)?
Have you tried a decoupling cap at the PICAXE power pins? (Some of those PC power supplies [i.e. big shiny things with loads of wires out of a PC] are awful)

Have you had any 'accidents' with that PICAXE prior to trying all this stuff?
 

ashleyps

New Member
ashleyps,

Try operating the circuit using batteries. If this code will not operate a LED/resistor connected to leg #9 on a 18X then there is something wrong with the chip.

Steve G.
I think is something wrong with the chip, because I can't download anything to it running on battery.
I have tried with 3 Alkaline AA battery (4.73V) and 4 Eneloop rechargeable AA battery (5.01V) and the chip don't work, is very strange.
I'm thinking about to use another kind of power supply to continue testing.
 

ashleyps

New Member
Does the code run ok in the editor simulator? Are you sure you are connected to the correct 18x pin? Only one pin will take the PWMOUT if I recall correctly... and it's too easy to confuse leg #s with PIN#s - persist!
I don't test the code in the editor simulator, but I'm sure about the pin because I have tried with "Pulsout 3, 5" and "High 3", and always work fine, but I start to believe is something wrong with the chip or the power supply.
 

premelec

Senior Member
Perhaps try LED + R with correct polarity to V+ in testing...
you've got an odd situation... so try pull up as well as pull down though I
don't see this will work I'd test it with PWMOUT running - and just leave it
run at one setting... could connect a piezo sounder there also to look for
pulses if you don't have a scope and such...

From Manual 2
"When driving a FET, a pull-down resistor between the PICAXE pin and 0V is
essential. The purpose of the pull-down resistor is to hold the FET driver in the
correct off state whilst the PICAXE chip initialises upon power up. During this
short initialisation period the pwmout pins are not actively driven (ie they ‘float’)
and so the resistor is essential to hold the FET in the off condition."
 

manie

Senior Member
ashleyps,

Sounds like the minimum PWM of 4KHZ is too fast for the CAT4101 though the specs say different. If using the "pulsout" command works as you say, then the PWM frequency with a 5ms pause ( also considering the delay time to execute the code ) might be 150Hz.

Steve G.

Maybe you should eliminate the "pause 5" command.
Code:
symbol led = w0                    
main:     for led = 10 to 996        
            pwmout 3 , 249 , led                                   
            next led                      
            goto main
Is the PWM not started and then runs in the background ? That means the "pause xx" has no effect on the frequency or on the duty, so why the pause ?
 

sghioto

Senior Member
manie,

You are correct it will not have any effect under normal conditions meaning the chip (18X) is functioning correctly. If you have read all the post on this thread then you know by this time we were just trying anything and everything. "ashleyps" says the chip is a PIC16f88 which should be a 18X but it behaves like a 18A. I believe it's one of three things. #1, somehow the bootstrap program is corrupt. #2 the chip was programed as a 18A, or #3 ashleyps is just messing with us.

Steve G.
 

ashleyps

New Member
The PWMout is still not working.
I put a picture of my actual breadboard.


I'm using SATA power cable and the SATA power port of my computer to power supply my circuit.



I'm working in this code to replace pwm fuction
Code:
'Dusk and Dawn effect with pulsout
symbol counter = w0
symbol counter2 = w1
symbol counter3 = w2
symbol led = w3
symbol time = w4
symbol time2 = w5

;Setup Time
time=1666 ' 28= 1 min / 139 = 5 mins / 415 = 15 mins / 833 = 30 mins / 1666 = 1 hour
time2=600  ' 1= 1 min / 60= 1 hour 

lightup:
led = led+1
for counter = 1 to time
pulsout 3, led
pause 5
if led = 300 then goto lightstay
next counter
goto lightup

lightstay:
high 3
high 7
for counter2 = 1 to time2
Pause 60000
Low 7
next counter2
low 3

lightdown:
led = led-1
for counter3 = 1 to time
pulsout 3, led
pause 5
if led = 0 then goto endlight
next counter3
goto lightdown

endlight:
high 7
Pause 500
Low 7
Pause 500
high 7
Pause 500
Low 7
end
http://www.youtube.com/watch?v=8eF9boQUbdw

I have tried to connect a DS1307 to my proyect but is not working too.

:confused:
 

Dippy

Moderator
Have you tried:-

1. Checking the 5V line at the chip leg/pin? (Is it 5V) and checking the 0V pin is grounded properly?
2. 'Scoping the 5V to make sure there isn't too much noise?
3. Putting a decouple cap directly across PICAXE +/- power pins?
4. Making a stripped down breadboard with just the recommended download circuit and THEN checking PWM?
5. Using the P.E. to check the PICAXE and firmware?

I find it difficult to check that complete breadboard, and my initial steps would be to do a 'checklist' of tests.
And certainly we can't tell the electrical integrity on the Forum... that's your job.

I get the impression that you have TOO MUCH in one go on that breadboard to do tests.
(Any bad connections, inappropriate connections, components, values can all affect operation. More components and connections = more variables in the circuit equation).
You should build up the project in stages.
e.g.
1. Get the basic download circuit working to programme PICAXE to flash a test res+LED from different legs.
Working? Yes:
2. Now download a drop of code to set PWM.
Check with res+LED or piezo sounder or preferably a 'scope.
Working? Yes.
then, 3. Add other things, one at a time, code-up and test....
or, No.
3. Check connections, code, PICAXE firmware,....everything.
Can't sort? Then swap out for another PICAXE.

Basically, if you've got the code right and downloaded OK, and it isn't working then there are three general possible faults.
1. The PICAXE is faulty.
2. The Power Supply is unsuitable.
3. Your circuit has a fault - and the Forum will rely on you to make the diagnostic tests.

Get the basics working before you use a DS1307, otherwise you can off at a tangent and waste time when the basics may be the root cause of the fault.

Tip 1 for newbies: Keep it Simple to start with.

Tip 2 for newbies:ALWAYS buy more than ONE of your chosen PICAXEs. In the unlikly event of a duffer you can swap out without waiting days/weeks for a replacment and saves carrige costs.
A duffer is VERY, VERY unlikely. The usual cause of failure is bad operation and ooops moments. This can happen to 'old lags' and Newbies so don't be shy!
 

premelec

Senior Member
You have 'long' power leads to the chip so perhaps a .1uF or more ceramic capacitor from pin 5 to pin 14 will help - just another shot in the dark... but a bypass capacitor at the chip IS called for and MAY help... a more robust capacitor on the power source could also be in order... The other thing I didn't check out is - ARE ALL THE INPUT LEADS CONNECTED?? NO FLOATING INPUTS ARE ALLOWED!!! ever :)
 

hippy

Ex-Staff (retired)
@ ashleyps : I'd also recommend stripping your circuit down to a bare minimum or build the bare minimum on another breadboard. Investigate PWMOUT and get that working before trying to get anything else working.

I'd also recommend using batteries rather than the PC supply; you need to take all unknown quantities out of the equation.

Take a particular look at the reset button connections. It's not clear to me in that photograph but there looks to be a potential for a short which would cause problems.
 

kevrus

New Member
The 4k7 'reset pull up' resistor looks like its touching the 22k 'download circuit' resistor, column 13 on the breadboard, may just be camera angle though, or my eyes...
 

ashleyps

New Member
1. Get the basic download circuit working to programme PICAXE to flash a test res+LED from different legs.
Working? Yes:
2. Now download a drop of code to set PWM.
Check with res+LED or piezo sounder or preferably a 'scope.
Working? Yes.
then, 3. Add other things, one at a time, code-up and test....
or, No.
3. Check connections, code, PICAXE firmware,....everything.
Can't sort? Then swap out for another PICAXE.
Hi Dippy,
I start over again, then I have tested with high and low all pin out in my picaxe 18X, and all worked fine.
I have tried to check with res+led the pwm and fail.
I have used this code with and without pause
Code:
symbol led = w0                    
main:     for led = 10 to 996        
            pwmout 3 , 249 , led                                   
            next led                      
            goto main


:confused:
 
Last edited:

hippy

Ex-Staff (retired)
What happens using ...

PwmOut 3 , 249 , 249
Do : Loop

That should give 25% duty, the LED glowing less bright than full. If that doesn't work I'm out of ideas as well.
 

premelec

Senior Member
Just to be tedious... all inputs must NOT float and .1uF V- V+ bypass at the IC chip should be installed... I don't see it...
 

ashleyps

New Member
Just to be tedious... all inputs must NOT float and .1uF V- V+ bypass at the IC chip should be installed... I don't see it...
I'm not sure about not float mean, but searching around I find something about using a 10K resitor tie to ground for each input, and I put the ceramic capacitor .1uF between pin 5 and 14.

Then I have tried the following code and nothing.
Code:
Main:
PwmOut 3 , 249 , 249
goto main


:confused:
 

hippy

Ex-Staff (retired)
Just to be tedious... all inputs must NOT float
That's not an absolute requirement, only necessary in particular circumstances. Most PICAXE programs should work correctly with floating inputs ( providing they aren't using those inputs ).

Then I have tried the following code and nothing.
Code:
Main:
PwmOut 3 , 249 , 249
goto main
I did suggest ...

PwmOut 3 , 249 , 249
Do : Loop

Which is not the same as what you tried, however ...

Having now tried all the proposed test programs on my PICAXE-18X all of which worked, it would appear that, if HIGH-LOW does control the LED but PWMOUT does not, then you have somehow damaged your 18X.
 
Last edited:

BeanieBots

Moderator
Worth trying the code suggested by Hippy.
What firnware version does your PICAXE 18X have?
You can find out from the programming editor and selecting:-
View/Options, then click on the "Firmware?" button.
 
Top