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.

16F737 Hardware PWM

Status
Not open for further replies.

reddog176

New Member
I'm trying to do a simple project with the hardware PWM on the 16F737. RGB led's on the 3 hardware pwm lines, coding in C. The only hardware PWM examples I can find are in ASM, and I'm not able to follow that too well. Does anyone have any examples in C they'd be willing to provide?

Thanks,
Reddog176
 

Wilksey

Member
For which compiler are you looking at examples for? C/C++ is generic, however, compilers and / or libraries are not.
 

reddog176

New Member
Not really, I can figure out how to do a software PWM no problem, but we want to utilize the 3 hardware PWM lines on the chip.

Reddog176
 

Wilksey

Member
Ok, well if you look at the datasheet for that particular chip, you will find that at 9.6.3 page 94 it states you need to set PR2 register, which is defined as PR20 to PR27 (8 bits). This is for the PWM Period

It then states that you need to set the PWM Duty Cycle, this is done by writing to CCPR1L and CCP1CON.

Then it states to make CCP1 an input by using TRIS.

Then you need to set the prescaler, this is done by using Timer 2, set the prescale and turn on using T2CON = TMR2ON, the prescalers will be in the datasheet.

Final step is to turn the CCP module to PWM mode, which is done using CCP1CON = PWM1M1 or PWM1M0, there are 2 PWM modes looking at the datasheet it should tell you what these are.

You can repeat the steps for the other 2 PWM channels by using CCP2CON and CCP3CON.

This was done using the datasheet, so I am just guessing the process, I dont personally use HITECH C, but I think it's very similar to C18, so it should be fairly straight forward.

I may be able to go into more detail, but it's all in the datasheet.

Hope this helps.

Wilksey
 
Status
Not open for further replies.

Latest threads

Top