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.

Just Basic PWM with an LED

Status
Not open for further replies.

PDubya

New Member
I've looked and looked and can't find anything that seems to do what I am trying to do. I'm trying to look for a way to fade/pulse an LED. Many many people suggested using PWM and a micro. That's what initially got me interested in learning about them - however I can't find a single example to pulse/fade using PWM and I am completely lost.

I've used the **broken link removed** in the past, and the effect works great. I'm so frustrated, I've throught about trying to get it to work on 5v and just triggering it with the pic. But, that tends to defeat the point.

Anyway, can anyone point me to anything that would get me going in the right direction with PWM? Most basic PWM code examples I see are using C or Basic, not ASM, and generally don't come with any real background and seem to be oriented to motors.

I tried searching the forum, but nobody's looked at the search term issue (it's 3 characters and won't search for it). I've searched on PicList but there really wasn't anything that was cohesive or very clear (is it just me or is that site a mess?). I look at the " but it's for robots/motors.

Apologies if I'm missing the boat on this, maybe I'm making it more complicated than it needs to be. I really appreciate the help and suggestions everyone shares.
 
Last edited:
I'm just wondering what aspect you are having trouble with... General principles of how to fade using pwm (applicable to any ucontroller) or pic specific programming (registers, etc.)

Although I cut my teeth on assembly back in the day on 6502's and z80's, it's my opinion that it's easier to whip something up like that in basic (or perhaps even C), where a simple command or function call takes care of everything. I know the 'real' programmers here will have a different opinion :)
 
Are there any special considerations using the code with a 16f628A?

[edit]

Sorry missed the other replies... let me answer.

agent420 > The concept of PWM isn't confusing, but some of the basic implementation within a pic and dynamically ajusting it. I just can't find any clear assembly examples (which isn't surprising considering my knowledge level at this point)

Mike > The 16f628A if I can get away with it
 
Last edited:
I've got a Demo for 16F628A running at 20-MHz. It uses RS232 and Hyperterminal "front end" using the "<" and ">" keys to adjust PWM duty cycle which is measured as a voltage between 0.0 and 5.0 volts in 100-mv steps from an RC integrator on the CCP1 pin. Will this help?

Regards, Mike
 

Attachments

  • PWM 16F628A Test Circuit.JPG
    PWM 16F628A Test Circuit.JPG
    51.5 KB · Views: 1,223
  • 16F628A PWM 01.zip
    2 KB · Views: 343
Last edited:
Mike,

Wow, I'll look through it and see if it's any more clear - seems a bit overkill for the LED, but even if I could just get it working with a couple buttons (fade up, fade down) that would be nice.

Thanks so much!!! I'm sure I'll be asking more questions after I read through it.
 
If you study and understand the code you should be able to;

(1) change the InitPWM code for a different oscillator/clock if necessary.

(2) replace the RC Integrator circuit on the RB3/CCP1 pin with your LED and resistor to VSS (ground).

(3) remove all the RS232 serial code (Init232, Put232, Get232, _Title macro, PutString, etc.).

(4) replace the serial "<" and ">" code in the LOOP routine with code to test switch press and release operations.

Several of us can help if you get stuck.

Have fun. Mike
 
Last edited:
**broken link removed**, but it's for a 12F675 and the assembly is really wierd. Is this some type of older assembly or something?
 
PDubya said:
**broken link removed**, but it's for a 12F675 and the assembly is really wierd. Is this some type of older assembly or something?

The source looks similar to my Parallax (formerly from UBICom) SX chips (PIC16C5X clones) programs. I used an SXKey last century.

You need to get a Parallax PIC assembler or just transcode it to MPASM.

**broken link removed**
 
Parallax had some of the first entry level tools, back in the days (early/mid 90's) when the 16C55's were hot stuff, and the Program/Burn cycle had a "wait for the UV chip to erase" state.

Just to nit-pick, Parallax kept up their "fork" of the assembly language, and teamed up with Scenix and their new SX line of chips which got ran 4x as fast and ate up power 4x as fast. Scenix changed names to Ubicom, released some mediocre processors, and got swatted by the bigger microcontroller companies.
 
if you use PIC16F628 do not forget change the default pins actions.
to wake pwm.. basicly: if you want to use ccp1:

BANKSEL CCP1CON
MOVLW 0x06
MOVWF CCP1CON
BANKSEL T1CON
BSF T1CON,TMR1ON
BANKSEL PIR1
BCF PIR1,CCP1IF
BANKSEL PIE1
BSF PIE1,CCP1IE
BANKSEL INTCON
BSF INTCON,PEIE
BSF INTCON,GIE
;------------------------------
BANKSEL TRISC
BSF TRISC,2
it is about using ccp1 module capture mod.. look upğ the data sheet and after that you can change the parameters

if you want to use ccp2 module only change the registers..

GOOD LUCK
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top