|
|
View previous topic :: View next topic |
Author |
Message |
mukeshp11
Joined: 10 Dec 2008 Posts: 15
|
CCS COMPILER WITH 16F690 IN PWM STEERING MODE |
Posted: Thu Sep 15, 2011 3:51 am |
|
|
The below shown my code has problem while generating more than 1 PWM simulatenously i.e I can't generate say all the 4 PWMS together in all ABCD channels. Kindly help
Code: |
#if defined(__PCM__) // Preprocessor directive that chooses the compiler
#include <16f690.h> // Preprocessor directive that selects the chip
#device adc=10
#fuses HS
#use delay(clock=10000000)
//#include <STDLIB.h>
#endif
#include <math.h>
#include <STDLIB.h>
//pwm pins
#define P1A PIN_C5
#define P1B PIN_C4
#define P1C PIN_C3
#define P1D PIN_C2
//global variables
int duty_cycle=0;
int sum,sum1,sample=0;
int i_rms,v_rms;
int i,v,bias;
float i_1,v_1,bias_1;
int oc_timer=0;
void read_adc();
void protection();
void main()
{
//setup_oscillator(OSC_NORMAL );
set_tris_b(0xff);
setup_timer_2(T2_DIV_BY_1, 255, 1); //19.53 khz switching frequency =51us sampling time
clear_interrupt(INT_TIMER2);
enable_interrupts(INT_TIMER2);
//enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL); ////enable_interrupts(GLOBAL);
//set_pwm1_duty(235);
output_low(P1A);
output_low(P1B);
output_low(P1C);
output_low(P1D);
if((input(PIN_B6)) && (input(PIN_B4)))
{
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_A);
output_high(P1C);
output_low(P1B);
}
if((input(PIN_B6)) && (!(input(PIN_B4))))
{
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_D);
output_high(P1A);
output_high(P1C);
output_low(P1B);
}
if(!((input(PIN_B6))) && (input(PIN_B4)))
{
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_BCCP_PULSE_STEERING_D);
output_high(P1A);
output_high(P1C);
output_low(P1D);
}
if((!(input(PIN_B6))) && (!(input(PIN_B4))))
{
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_C);
output_high(P1A);
output_high(P1D);
output_low(P1B);
}
|
The above four IF loops are execute based on 2 input conditions simulataneously satisified.i.e pin B6 and pin B4.
Now in any of the above 4 if loops I am not able to generate two PMW together i.e
Code: |
if((!(input(PIN_B6))) && (!(input(PIN_B4))))
{
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_A);
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_D);
}
|
In the above IF loop I am not able to execute both of the above statements i.e not able to generate two PMW together...only one PWM at a time is generated. Here in above IF loop only PWM in P1D is executed and not in P1A.
Is it like that in pulse steering mode only one PWM at a time is generated? i.e what can be done if I want to generate two or all of the 4 PWMs together ? Can it be done using pulse steering mode?
Kindly help in the same
Rgds
Mukesh |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Thu Sep 15, 2011 5:12 am |
|
|
The chip has a _single_ PWM module, which can generate just one timing.
The output of this module, can be routed to give two complementary signals (but with the same timings). Data sheet section 11-4.
Look at Figure 11-6, which shows the output options available. at most two pins are driven at a time (half bridge), with complementary signals (with an optional deadband delay).
In single PWM mode, you can route the PWM, to up to all four pins using (for example):
Code: |
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_A | CCP_PULSE_STEERING_D);
|
Whenever you execute a setup_ccp1, is overrides what has gone before, so to set multiple pins you have to OR them in the single statement.
Best Wishes |
|
|
|
|
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
|