|
|
View previous topic :: View next topic |
Author |
Message |
williamcoral
Joined: 08 Feb 2010 Posts: 2
|
Help With a PWM code for PIC16F690 |
Posted: Mon Feb 08, 2010 6:55 pm |
|
|
Hi, I have this PWM code for the PIC16F690 but I don't know what is the problem because I make the simulation with Proteus (ISIS) and the output (pins P1B, P1C, and P1D) stay low always.
My CCS compiler vs. is 4.093
PD. I copied the code from another post of "PCM programmer"
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)
#define P1A PIN_C5
#define P1B PIN_C4
#define P1C PIN_C3
#define P1D PIN_C2
//===========================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
set_pwm1_duty(31); // 25% duty cycle
//!
//!// Enable PWM pins P1B, P1C, and P1D for output.
//!// Note: P1A is done by the compiler.
output_low(P1B);
output_low(P1C);
output_low(P1D);
// Steer the PWM output to all four P1x pins.
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A
| CCP_PULSE_STEERING_B
| CCP_PULSE_STEERING_C
| CCP_PULSE_STEERING_D );
while(1);
} |
|
|
|
williamcoral
Joined: 08 Feb 2010 Posts: 2
|
voila c'est bon |
Posted: Mon Feb 08, 2010 7:13 pm |
|
|
This is the problem with the code, this line of code was placed wrong:
Code: |
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
|
This is the good code and works fine with Proteus:
Code: |
#include <16F690.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, BROWNOUT, PUT, NOMCLR
#use delay(clock=8000000)
#define P1A PIN_C5
#define P1B PIN_C4
#define P1C PIN_C3
#define P1D PIN_C2
//===========================================
void main()
{
set_pwm1_duty(31); // 25% duty cycle
//!
//!// Enable PWM pins P1B, P1C, and P1D for output.
//!// Note: P1A is done by the compiler.
output_low(P1B);
output_low(P1C);
output_low(P1D);
// Steer the PWM output to all four P1x pins.
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A
| CCP_PULSE_STEERING_B
| CCP_PULSE_STEERING_C
| CCP_PULSE_STEERING_D );
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
while(1);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 08, 2010 8:21 pm |
|
|
It's likely a problem with the Proteus simulator. |
|
|
|
|
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
|