|
|
View previous topic :: View next topic |
Author |
Message |
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
pwm output pin setup on 886 |
Posted: Mon Oct 01, 2007 2:39 pm |
|
|
Hi.
How do i set this output to pin B1 on a 886?
I tried setting the ccp1 to p1c but i don't understand the output setup.
Code: | setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 255, 1);
set_pwm1_duty(128); |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 01, 2007 2:56 pm |
|
|
Here's an example for the 16F690, and it's similar to the 16F886.
http://www.ccsinfo.com/forum/viewtopic.php?t=31162&start=9
1. Create a #define statement for the P1C pwm pin, that tells
the compiler that it's on Pin B1.
2. Set that pin low, with an output_low() statement.
3. Call the setup_ccp1() function with the CCP_PWM_H_H pwm mode,
and "OR" it with the CCP_PULSE_STEERING_C value.
The example code shows how to put the pwm signal out on all four pins.
You need to modify it so it only uses the P1C pin (RB1). |
|
|
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
|
Posted: Mon Oct 01, 2007 3:19 pm |
|
|
Thaks. 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 );
After i set pin b1 to low is this the part that, when lookin at the pulse, is setting it high or what? And please cab you explain the PWM_H_H part? I see it in the header file but i don't understand? |
|
|
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
|