Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Control the Luminance of LED by PWM - urgent

Status
Not open for further replies.

huanyong

New Member
This is my school project. I am using PIC16F628A to control the luminance of a LED. the test code is below :

include "modedefs.bas"
symbol RB4=PORTB.4
main:
pwm PORTB.4, 0, 400
pwm PORTB.4, 127, 400
pwm PORTB.4, 256, 400
goto main
end

i am using 4 MHZ internal clock and each duty crycle consume 5ms. My led is connected to PORTB.4 . i had try 0, 50, and 100 percent of duty cycle and hold each for 2 seconds.

But my led just ond when my duty crycle is 100% and it is off for other duty crycle... May someone help me to solve this problem?
 
How do you have connected your LED? Do you have a resistance?

You have an error in your code for the 100%...... it should be:
pwm PORTB.4, 255, 400

:idea: THe frequency of the PWM @ 4Mhz is of about 1/20usec= 50Khz ( I believe I am right 256 pulses in 5msec is 20usec per pulse.) At a 50% duty cyle the LED will see 5V for 10usec every 20usec or 2.5V but the LED will not have enoug time to blow up because of the fast switch. But at a 100% the voltage will be ON all the time and the LED will need a resistance to reduce the current in take.

I would recommend not to use a resistance and not to over pass the 50% dutycyle so you don't damage the PIC nor the LED. I should try doing that and see the results for myself :wink:

Ivancho
 
good website?

is there any good website or tutorial that teach how to use control the luminance of LED by PIC?
 
To save program space, I would recommend using the method below. It will make the LED glow more evenly.


include "modedefs.bas"
symbol RB4=PORTB.4
main:
for B0 = 0 to 255 step 1
pwm PORTB.4,B0,400
next B0
goto main
end
 
Status
Not open for further replies.

Latest threads

Back
Top