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.

Help me coding program for voltage comparator and PWM

Status
Not open for further replies.

down_creek

New Member
guys....i need your help me to programming the coding to generated the PWM signal using PIC18F4550....

i already build the test board using 8mHz crystal...but no idea how to coding the pic to generated the PWM signal....

what i want to do with my circuit is.....PIC will compare the input voltage from my sensing circuit and will stop the PWM signal if the input voltage is higher than the reference voltage.

for example....3V as reference voltage....if the sensing circuit give the higher input voltage than 3V to pic....pic will stop generate the PWM signal until the voltage is back to 3V....

guys...please help me.....:(
 
Hi

For an in depth explanation of what you need, together with fully working code and circuit examples see Nigels site -

HTH
 
Check out section 24.0 of the PIC18F4550 datasheet at Microchip's web site.
 
Check out section 24.0 of the PIC18F4550 datasheet at Microchip's web site.
Umm... Don't you mean section 15.0 - CAPTURE/COMPARE/PWM (CCP) MODULES?

Read it all, but look especially at the PWM section, 15.4. The step-by-step setup instructions are at 15.4.4 - SETUP FOR PWM OPERATION.

15.4.4 SETUP FOR PWM OPERATION
The following steps should be taken when configuring the CCP module for PWM operation:
1. Set the PWM period by writing to the PR2 register.
2. Set the PWM duty cycle by writing to the CCPRxL register and CCPxCON<5:4> bits.
3. Make the CCPx pin an output by clearing the appropriate TRIS bit.
4. Set the TMR2 prescale value, then enable Timer2 by writing to T2CON.
5. Configure the CCPx module for PWM operation.
As you write code for each step, refer to section 15.0 for the register values you need to set, and 13.0 for setting up Timer2.

That's pretty much all there is to it. To change the PWM duty cycle for your selected pin, just write to CCPRxL if you only need 8-bits resolution (256 PWM levels), leaving the two Lsb bits set to 0, and if you need the full 10-bits (1024 PWM levels), also write to the 1 and 0 Lsb's at CCPxCON<5:4>.
 
Last edited:
thanks for help me....can your guys give me the coding can i use for this project...i just have 1 week now to finish it....very2 blur now....i using picbasic pro.....

please help me guys...i'm very2 new in this PIC prog.....
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top