|
|
View previous topic :: View next topic |
Author |
Message |
mukeshp11
Joined: 10 Dec 2008 Posts: 15
|
Pulse steering function in pic16f690 some problem. |
Posted: Thu Dec 29, 2011 6:28 am |
|
|
One of the function of my code for pwm generation is shown below:
Code: |
void pulse_steering()
{
if(input(PIN_B4) && input(PIN_C1)) //PUT NOT GATE FOR S1
{
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_A);
output_low(P1D); //output_high(P1D);
output_high(P1C); //output_low(P1C);
output_low(P1B); //output_high(P1B);
}
else if(!input(PIN_B4) && !input(PIN_C1)) //PUT NOT GATE FOR S2
{
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_C);
output_low(P1A); //output_low(P1A);
output_high(P1D); //output_high(P1D);
output_low(P1B); //output_high(P1C);
}
else if(!input(PIN_B4) && input(PIN_C1)) //FOR S3
{
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_B);
output_high(P1A); //output_low(P1A);
output_low(P1D); //output_high(P1D);
output_low(P1C); //output_high(P1B);
}
else if(input(PIN_B4) && !input(PIN_C1)) //FOR S4
{
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_D);
output_low(P1A); //output_low(P1A);
output_low(P1C); //output_high(P1C);
output_high(P1B); //output_high(P1B);
}
else
{
output_high(P1D);
output_high(P1C);
output_high(P1B);
output_high(P1A);
}
}
|
In the above code based on the input at pin B4 and C1 whether they are high or low I generate four different PWM individually at different times.
Now i want to generate PWM A and C as active high and PWM B and D as active low. So i am using PWM mode as CCP_PWM_L_H (i.e.CCP!m3:m0=1101) so I should get P1A and P1C as active low and P1B and P1D as active low.
But am nt able to generate all the PWM properly.
But when using below code when i generate all pwm simulatenouly it works,
Code: |
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_A | CCP_PULSE_STEERING_B | CCP_PULSE_STEERING_C | CCP_PULSE_STEERING_D);
|
By the above command I can generate PWM P1A and P1C as active low and P1B and P1D as active high.
But when I generate individual PWM as in the below code i am nt able to get PWM properly.
i.e
Code: |
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_A);
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_B);
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_C);
setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_D);
|
So, my main code shown initially don't work properly when I generate individual PWM at different time.
Kindly advise. Actually I want to generate not all PWM simultaneouly but after some time and under some conditions only then how does pulse steering works.
Its urgent pls comment how to generate individual PWM seperately in different times i.e using different command not in single command i.e not together using pulse steering.
Regards,
Mukesh |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Dec 29, 2011 8:30 am |
|
|
Have you tried setting the tris to 0 on the pin you want to drive?.
When you use all the pins, the compiler 'knows' that all four pins need to be outputs, and sets the tris for you, but when you use pulse steering, it doesn't know about this, and will leave the pins as inputs.
Best Wishes |
|
|
mukeshp11
Joined: 10 Dec 2008 Posts: 15
|
|
Posted: Thu Dec 29, 2011 10:23 am |
|
|
Hi, Ttelmah
Yes I have set portc as 0x00 and hence all four pwms are configured as output.
I can successfully generate PWM simultaneously with command:
Code: | setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_A |CCP_PULSE_STEERING_B|CCP_PULSE_STEERING_C|CCP_PULSE_STEERING_D); |
and I am getting four differnt pwm correctly.
But i have doubt if i can generate PWM with four different command when four different conditions occur. And I am not able to generate pwm practically properly with following commands.
CONDITION:-1
Code: | setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_A); |
CONDITION:2
Code: | setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_B); |
CONDITION3
Code: | setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_C); |
CONDITION4
Code: | setup_CCP1( CCP_PWM_L_H | CCP_PULSE_STEERING_D); |
Pls tell me can above commands generate four different PWM seperately or it overrides other.
My aim is to generate PWM A with condition 1, PWM B with condition 2, PWM C with condition 3, and PWM D when condition 4 arise, separately.
Regards,
Mukesh |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu Dec 29, 2011 10:25 am |
|
|
Have you selected fast_io mode?.
If not, the compiler will override TRIS settings, if you just set TRIS directly. You need to use 'output_drive(PIN)', to override the default behaviour.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 29, 2011 7:35 pm |
|
|
If you just want to change the pwm pulse steering, you could create a
special function to do that. I've done that in the program below. I'm
not at a location where I can test this program in hardware, so I'm not
completely certain it will work. But it probably should work.
This test program sets up PWM on the P1A pin initially. Then it changes
the pwm pin to the next one in sequence, once every second.
Code: |
#include <16F690.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT
#use delay(clock=8M)
// These are the PWM output pins for the 16F690.
#define P1A PIN_C5
#define P1B PIN_C4
#define P1C PIN_C3
#define P1D PIN_C2
#byte PSTRCON = getenv("SFR:PSTRCON")
// Call this routine to set the PWM steering. You can OR
// together the PWM steering constants from the PIC's
// header file.
void set_pwm_steering(int32 steering)
{
int8 temp;
temp = make8(steering, 3); // Get high byte only
PSTRCON = temp; // Setup PWM steering register
// Set the TRIS to outputs for the enabled steering pins.
// Also set the selected pins to a low level.
if(temp & 1)
output_low(P1A);
if(temp & 2)
output_low(P1B);
if(temp & 4)
output_low(P1C);
if(temp & 8)
output_low(P1D);
}
//====================================
void main()
{
setup_timer_2(T2_DIV_BY_16, 124, 1); // 1000 Hz
set_pwm1_duty(31); // 25% duty cycle
setup_ccp1(CCP_PWM_H_H | CCP_PULSE_STEERING_A);
// Change the PWM output pin once per second.
// Change sequentially from P1A to P1B, to P1C,
// and to P1D. Then repeat.
while(1)
{
set_pwm_steering(CCP_PULSE_STEERING_A);
delay_ms(1000);
set_pwm_steering(CCP_PULSE_STEERING_B);
delay_ms(1000);
set_pwm_steering(CCP_PULSE_STEERING_C);
delay_ms(1000);
set_pwm_steering(CCP_PULSE_STEERING_D);
delay_ms(1000);
}
} |
|
|
|
mukeshp11
Joined: 10 Dec 2008 Posts: 15
|
pulse steering function in pic16f690 some problem. |
Posted: Fri Dec 30, 2011 4:48 am |
|
|
for PIC16F690
Now i am getting things correctly.
In pulse steering mode when i generate PWM in P1B and simultaneously if i keep P1A as high then I am getting problem in P1A i.e. we get pulse trains in P1A instead of high signal.
This phenomena happens with PWM in P1C and P1D also while P1A is configured as high.
so (P1B=pwm && P1A=high)=problem in P1A.
(P1A=pwm && P1B=high)=no problem
(P1C=PWM && P1A=high)=problem in P1A
(P1D=PWM && P1A=high)=problem in P1A
So, always there is problem with P1A when P1A is high and other port are in PWM mode.
Kindly comment.
Regards,
Mukesh |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 30, 2011 4:27 pm |
|
|
Post a short test program that shows the problem. Don't post if-else
statements. Just post a very short program that shows one of the
problems, such as this one:
Quote: |
so (P1B=pwm && P1A=high)=problem in P1A.
|
The program should be compilable. |
|
|
mukeshp11
Joined: 10 Dec 2008 Posts: 15
|
|
Posted: Sat Dec 31, 2011 12:59 am |
|
|
hello,
pcm programmer,
1) i have set TRIS for port C(where my PWM outputs P1A,P1B,P1C,P1D )are there.
2)Configured timer for 20kHz switching frequency.
3)Configured PWM using pulse steering mode.
setup_CCP1(CCP_PWM_H_H | CCP_PULSE_STEERING_A);
similarly for other P1B,P1C AND P1D
In pulse steering mode,
I am generating 4 PWMs on P1A,P1B,P1C,P1D. In pulse steering mode as per data sheet P1A is modulated and steered on P1B, P1C, and P1D.
So (P1B=pwm && P1A=high)=problem in P1A.
(P1A=pwm && P1B=high)=no problem
(P1C=PWM && P1A=high)=problem in P1A
(P1D=PWM && P1A=high)=problem in P1A
One can see the attachment for the results and comment.
In the image of the results take it can be seen that when there is no PWM in P1A that is it is high and at the same time PWM is in other say P1B or P1C then at that time P1A disturbs and some pwm pulse comes instead of high.
https://docs.google.com/leaf?id=0B-MXAdMvGtiLNjFmYmRhZjUtNTlhNy00YWRhLTg0M2EtZDIyZWM5ZWY1Yzcz&hl=en_US
The yellow color first waveform is P1A where PWM is generated correctly but high signal is required then also some pulses come don't know why?
Blue is P1B, pink is P1C and green waveform is P1D.
Regards,
Mukesh |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 31, 2011 8:23 pm |
|
|
Your link asks people to "sign in" with an email and a password.
It's useless.
Your description is not enough. You need to post a test program.
Then we can see exactly what you are doing.
Also post your compiler version. It's a 4-digit number and it's
given at the top of the .LST file, which will be in your project
directory after you successfully compile a file. |
|
|
mukeshp11
Joined: 10 Dec 2008 Posts: 15
|
|
Posted: Sun Jan 01, 2012 9:49 pm |
|
|
compiler version:-CCS PCM C Compiler, Version 4.099, 49779
Hello pcm programmer,
Code is as follows:-
Code: |
#if defined(__PCM__) // Preprocessor directive that chooses the compiler
#include <16f690.h> // Preprocessor directive that selects the chip
#DEVICE ICD=TRUE //for debugging
#device adc=8
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=20000000)
#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
unsigned int duty_cycle=200;
void main()
{
set_tris_c(0x00); //for pwm pins as output
//setup_timer_2(T2_DIV_BY_1, 255, 1); //19531.25 is the exact switching frequency.
setup_timer_2(T2_DIV_BY_1, 255, 1);
clear_interrupt(INT_TIMER2);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL); ////enable_interrupts(GLOBAL);
//pwm low initially
output_low(P1A);
output_low(P1B);
output_low(P1C);
output_low(P1D);
}
#int_timer2 //timer 2 over flow
void timer2_isr(void)
{
// x++;
z++;
if(z>=399)
z=0;
if(z<=99)
x=1;
else if(z>99 && z<=199)
x=2;
else if(z>199 && z<=299)
x=3;
else
x=4;
set_pwm1_duty(duty_cycle); //for testing dutycycle is set fixed.
pulse_steering();
}
void pulse_steering()
{
if(x==1)
{
setup_CCP1( CCP_PWM_H_H | CCP_PULSE_STEERING_D | CCP_PULSE_STEERING_SYNC);
output_high(P1C);
output_low(P1B);
output_low(P1A);
}
else if(x==2)
{
setup_CCP1( CCP_PWM_H_H | CCP_PULSE_STEERING_C | CCP_PULSE_STEERING_SYNC);
output_low(P1D);
output_low(P1B);
output_high(P1A);
}
else if(x==3)
{
setup_CCP1( CCP_PWM_H_H | CCP_PULSE_STEERING_B | CCP_PULSE_STEERING_SYNC);
output_high(P1D);
output_low(P1C);
output_low(P1A);
}
else if(x==4)
{
setup_CCP1( CCP_PWM_H_H | CCP_PULSE_STEERING_A | CCP_PULSE_STEERING_SYNC);
output_low(P1D);
output_low(P1C);
output_high(P1B);
}
else
{
output_low(P1D);
output_low(P1C);
output_low(P1B);
output_low(P1A);
}
}
|
In pulse_steering function in timer2:-
For all x=1,x=2 and x=3, (I.W pwm in P1B,P1C AND P1D), whenever P1A is delared high its showing some pulse instead of remaining high but works when it is declared low,
and x=4 condition works well whenever PWM A is there.
Observation:-
In pulse steering mode,
I am generating 4 PWMs on P1A,P1B,P1C,P1D. In pulse steering mode as per data sheet P1A is modulated and steered on P1B, P1C, and P1D.
So (P1B=pwm && P1A=high)=problem in P1A.
(P1A=pwm && P1B=high)=no problem
(P1C=PWM && P1A=high)=problem in P1A
(P1D=PWM && P1A=high)=problem in P1A
Now the link below will work as I had declared it private by mistake earlier now it will not ask for user id and password. Pls see the link. Sorry for inconvinience.
LINK = https://docs.google.com/leaf?id=0B-MXAdMvGtiLNjFmYmRhZjUtNTlhNy00YWRhLTg0M2EtZDIyZWM5ZWY1Yzcz&hl=en_US
In the result line above the waveform:- yellow waveform is x=4 condition i.e P1A=PWM. (IT HAS PROBLEM WHENEVER OTHER PWM IS GENERATING ALONG WITH P1A AS HIGH ISTEAD OF HIGH SOME PULSES ARE NOTICED).
BLUE WAVEFORM IS x=3 condition i.e. P1B PWM.
PINK WAVEFORM IS x=2 condition i.e. P1C PWM. GREEN WAVEFORM IS x=1 condition i.e. P1D PWM.
Kindly comment.
Regards,
Mukeshh |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jan 01, 2012 10:49 pm |
|
|
1. It's not a short program, without if-else statements.
2. It doesn't compile. It gets several errors if you try to compile it. |
|
|
|
|
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
|