|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 01, 2007 4:07 pm |
|
|
Quote: |
I understand the first part but what does this part do in the program?
setup_ccp1(CCP_PWM_H_H
| CCP_PULSE_STEERING_B
| CCP_PULSE_STEERING_C
| CCP_PULSE_STEERING_D ); |
That part tells the CCP what PWM mode to use, and it tells it what
pins to use for PWM output. The code that you posted will send out
the PWM signal on pins P1B, P1C, and P1D.
Quote: | can you explain the PWM_H_H part ? |
It sets the ECCP mode in the CCP1CON register.
See this table from the 16F886 data sheet, for the CCP1CON register:
Quote: |
1100 = PWM mode; P1A, P1C active-high; P1B, P1D active-high
1101 = PWM mode; P1A, P1C active-high; P1B, P1D active-low
1110 = PWM mode; P1A, P1C active-low; P1B, P1D active-high
1111 = PWM mode; P1A, P1C active-low; P1B, P1D active-low
|
Compare it to the #define statements in the 16F886.H file.
Note that CCP_PWM_H_H selects the first option above. This means
that P1A and P1C will put out positive-going pulses as the PWM signal.
That's the normal operation for a single-output PWM pin. Most people
use it in that mode.
Quote: |
#define CCP_PWM_H_H 0x0c
#define CCP_PWM_H_L 0x0d
#define CCP_PWM_L_H 0x0e
#define CCP_PWM_L_L 0x0f
|
Here's a test program. This was compiled with vs. 4.056 and it works OK.
It puts out a 1 KHz waveform with a 25% duty cycle on pin B1.
Code: | #include <16F886.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOLVP, BROWNOUT
#use delay(clock=8000000)
#define P1A PIN_C2
#define P1B PIN_B2
#define P1C PIN_B1
#define P1D PIN_B4
//========================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 124, 1);
set_pwm1_duty(31);
output_low(P1C);
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_C);
while(1);
}
|
|
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Mon Oct 01, 2007 4:08 pm |
|
|
Reading Assignment:
Read the Forum Policy and Guidelines Sticky (items 3, 4, and 5)
Device header file (look closely at the PWM/CCP setup info)
16F886 Data sheet from Microchip (Both PWM/CCP general info and PWM specific)
The compiler manual (search every statement you don't understand)
The c:\program files\PICC\readme.txt (see if there is anything missing from manual)
CCS Forum Search Exercise:
Look for posts that have similar text as keywords in your questions.
Posting Exercise:
Take what you've learned from the above and write a post that will make the pros want to help.
I know there is an overwhelming tendency to just blurt out a question and hope for help (I do it regularly too.)
Good luck,
John |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|