PDA

View Full Version : PWM setting PIC16F887



Gevo
- 13th February 2008, 15:12
Hello,

I work on a application and need two hardware PWM outputs. One PWM (CCP1) to
control a DC motordriver LMD18200 (10 Khz) and one PWM (CCP2) for IR comm (38KHz)
The motor is still running, but runs on 1 KHZ. (I need 10KHz or maybe the same 38KHz as the IR Comm.)

Questions:

- Runs CCP1 and CCP2 with the same Timer2 Prescale settings ?
- So, can I set different frequences on the two PWM channels ?

Thanks for replays,
Regards, Gevo


The setting in my program:

' PIC16F887

DEFINE OSC 4 ' Inform PBP PIC Speed
OSCCON = %01100111 ' Internal Clock set to 4MHZ

INTCON.7 = 0 ' Disable interrupts.
CM1CON0 = 0 ' Comparators off
CM2CON0 = 0 ' Comparators off

' Motor PWM settings
TRISC.2 = 0 ' Set PORTC.2 (CCP1) to output
CCP1CON = %00001100 ' Set CCP1 to PWM, ACTIVE HIGH
T2CON = %00000101 ' Timer2 ON, Prescale 1:4
PR2 = 249 ' Set PWM Periode to 1 KHz

' IR COMM PWM settings
TRISC.1 = 0 ' Set PORTC.1 (CCP2) to output
CCP2CON = %00001100 ' Set CCP2 to PWM, active high
T2CON = %00000100 ' Timer2 ON, Prescale 1:1
CCPR1L = 13 ' Set PWM Duty-Cycle to 50%
PR2 = 25 ' Set PWM Periode to 38 KHz

---

skimask
- 13th February 2008, 16:47
Hello,
I work on a application and need two hardware PWM outputs. One PWM (CCP1) to
control a DC motordriver LMD18200 (10 Khz) and one PWM (CCP2) for IR comm (38KHz)
The motor is still running, but runs on 1 KHZ. (I need 10KHz or maybe the same 38KHz as the IR Comm.)
---

Might help you out...
http://www.mister-e.org/pages/utilitiespag.html

Bruce
- 13th February 2008, 17:57
You can have different duty-cycles, but the frequency will be the same on both CCP1 & CCP2 since they both use the PR2 register of TIMER2 for the PWM period.

skimask
- 13th February 2008, 18:14
You can have different duty-cycles, but the frequency will be the same on both CCP1 & CCP2 since they both use the PR2 register of TIMER2 for the PWM period.

Hey...good point...Duh on my part...
Set up a 555 timer for a 50% 38Khz square and turn it on/off with a PIC pin, or use a 2nd PIC set up for the same thing as the 555. An 8-pin PIC makes a helluva useful 555 timer....with a load of options...

Bruce
- 13th February 2008, 18:33
Something like this http://www.rentron.com/remote_control/TX-IR.htm

flotulopex
- 11th June 2008, 17:29
Hi Gevo,

What is your email adress? I can't reply to your pm.

Gevo
- 12th June 2008, 07:24
Hi Roger,

Thnx for your replay.

My direct Email adress: [email protected]

Beste Regards,
Gerben Voort