Using PWM with Swordfish

SwordfishUser.PWM History

Hide minor edits - Show changes to markup

April 26, 2023, at 02:29 PM by swordfish - add PIC Multicalc local download file
Changed line 25 from:

// * download PIC MultiCalc from http://mister-e.org/pages/utilitiespag.html

to:

// * download PIC MultiCalc

Changed lines 70-71 from:

All you need to do is transfer the values from PIC MultiCalc into the #options section in the above code and that's it!

to:

All you need to do is transfer the values from PIC MultiCalc into the #options section in the above code and that's it!

Changed line 94 from:

As you can see with the above code, it's very easy to use. When you call SetFreq(), the prescale, PR2 and max duty value are automatically calculated. Note that SetFreq() returns true if the frequency could be set, false otherwise. If it returns false, you need to check your datasheet (or use PIC MultiCalc to verify). The chances are the frequency you have entered is not supported at the clock frequency you are using.

to:

As you can see with the above code, it's very easy to use. When you call SetFreq(), the prescale, PR2 and max duty value are automatically calculated. Note that SetFreq() returns true if the frequency could be set, false otherwise. If it returns false, you need to check your datasheet (or use PIC MultiCalc to verify). The chances are the frequency you have entered is not supported at the clock frequency you are using.

Changed line 5 from:

I'm assuming the reader knowns what PWM is as I don't intend to discuss the ins and outs of PWM on a PIC but rather the basic steps to get PWM working when using Swordfish. The two methods I will discuss are fixed frequency PWM and variable frequency PWM. One of the first things I would recommend you do is download PIC MultiCalc?. This is a very useful utility that enables you to calculate Timers, PWM, USART or EUSART register values, you can see a screenshot to the left. If your eyes glaze over when reading the datasheet, then this utility is just what you need!

to:

I'm assuming the reader knowns what PWM is as I don't intend to discuss the ins and outs of PWM on a PIC but rather the basic steps to get PWM working when using Swordfish. The two methods I will discuss are fixed frequency PWM and variable frequency PWM. One of the first things I would recommend you do is download PIC MultiCalc. This is a very useful utility that enables you to calculate Timers, PWM, USART or EUSART register values, you can see a screenshot to the left. If your eyes glaze over when reading the datasheet, then this utility is just what you need!

Changed lines 5-6 from:

I'm assuming the reader knowns what PWM is as I don't intend to discuss the ins and outs of PWM on a PIC but rather the basic steps to get PWM working when using Swordfish. The two methods I will discuss are fixed frequency PWM and variable frequency PWM. One of the first things I would recommend you do is download PIC MultiCalc. This is a very useful utility that enables you to calculate Timers, PWM, USART or EUSART register values, you can see a screenshot to the left. If your eyes glaze over when reading the datasheet, then this utility is just what you need!

to:

I'm assuming the reader knowns what PWM is as I don't intend to discuss the ins and outs of PWM on a PIC but rather the basic steps to get PWM working when using Swordfish. The two methods I will discuss are fixed frequency PWM and variable frequency PWM. One of the first things I would recommend you do is download PIC MultiCalc?. This is a very useful utility that enables you to calculate Timers, PWM, USART or EUSART register values, you can see a screenshot to the left. If your eyes glaze over when reading the datasheet, then this utility is just what you need!

Changed line 11 from:

The steps in configuring PWM basically break down to (1) set the PWM period by writing to the PR2 register (2) set the PWM duty cycle (3) make the PWM pin an output (4) set the TMR2 prescale value and enable Timer2 and (5) configure the CCP module for PWM operation. This is much easier to understand with some code. Lets assume we want a 5KHz frequency. First, start the PIC MultiCalc utility and press the 'PWM calc' button. Just enter values for

to:

The steps in configuring PWM basically break down to (1) set the PWM period by writing to the PR2 register (2) set the PWM duty cycle (3) make the PWM pin an output (4) set the TMR2 prescale value and enable Timer2 and (5) configure the CCP module for PWM operation. This is much easier to understand with some code. Lets assume we want a 5KHz frequency. First, start the PIC MultiCalc utility and press the 'PWM calc' button. Just enter values for

June 17, 2008, at 06:28 PM by David Barker -
Added line 1:

(:title Using PWM with Swordfish:)