Hello the software dont generates 2 PWM in same time.
the code is:
program pwm;
begin
trisc:=0;
PWM1_Init(1000);
PWM2_Init (1000);
PWM1_Set_Duty(170);
PWM2_Set_Duty(100);
PWM1_Start();
PWM2_Start();
while true do
begin
delay_ms(1000);
end;//while true
end.
This code generates only the PWM1 signal but dont the PWM2.
Then I cant to work with two PWM signal in mikropascal.
I use the pic 16F873A and 4MHz.
If i do this:
PWM1_Init(1000);
PWM1_Set_Duty(170);
PWM1_Start();
The PIc dont generates the PWM signal.
At least that I place:
PWM1_Init(1000);
PWM1_Set_Duty(170);
PWM1_Start();
PWM2_Start(); //this line
Kind regard.
[v 2.15 pro] PWM Problem
-
- Posts: 272
- Joined: 17 Feb 2009 02:39
- Location: Colombia
- Contact:
hi,
from help file, MP Pro 2.15....
look where they put the init, the duty and the start...
HTH a bit
from help file, MP Pro 2.15....
Code: Select all
program PWM_Test;
var current_duty, current_duty1, old_duty, old_duty1 : byte;
procedure InitMain();
begin
ANSEL := 0; // Configure AN pins as digital I/O
ANSELH := 0;
PORTA := 255;
TRISA := 255; // configure PORTA pins as input
PORTB := 0; // set PORTB to 0
TRISB := 0; // designate PORTB pins as output
PORTC := 0; // set PORTC to 0
TRISC := 0; // designate PORTC pins as output
PWM1_Init(5000); // Initialize PWM1 module at 5KHz
PWM2_Init(5000); // Initialize PWM2 module at 5KHz
end;
begin
InitMain();
current_duty := 16; // initial value for current_duty
current_duty1 := 16; // initial value for current_duty1
PWM1_Start(); // start PWM1
PWM2_Start(); // start PWM2
PWM1_Set_Duty(current_duty); // Set current duty for PWM1
PWM2_Set_Duty(current_duty1); // Set current duty for PWM2
while (TRUE) do // endless loop
begin
if (RA0_bit <> 0) then // button on RA0 pressed
begin
Delay_ms(40);
Inc(current_duty); // increment current_duty
PWM1_Set_Duty(current_duty);
end;
if (RA1_bit <> 0) then // button on RA1 pressed
begin
Delay_ms(40);
Dec(current_duty); // decrement current_duty
PWM1_Set_Duty(current_duty);
end;
if (RA2_bit <> 0) then // button on RA2 pressed
begin
Delay_ms(40);
Inc(current_duty1); // increment current_duty1
PWM2_Set_Duty(current_duty1);
end;
if (RA3_bit <> 0) then // button on RA3 pressed
begin
Delay_ms(40);
Dec(current_duty1); // decrement current_duty1
PWM2_Set_Duty(current_duty1);
end;
Delay_ms(5); // slow down change pace a little
end;
end.
HTH a bit
I use this code with PIC18F24K20 :
The problem is with Pwmx_Stop, this stop both PWM !
Both PWM use the same timer and will have the same frequency.
I made my Pwm_Stop routine :
Code: Select all
Pwm1_Init(1000);
Pwm1_Set_Duty(127);
Pwm1_Start();;
Pwm2_Set_Duty(127);
Pwm2_Start();
Both PWM use the same timer and will have the same frequency.
I made my Pwm_Stop routine :
Code: Select all
procedure PWM1_Stop_;
begin
TRISC.2 := 1;
CCP1CON := CCP1CON and 240;
end;
procedure PWM2_Stop_;
begin
TRISC.1 := 1;
CCP2CON := CCP2CON and 240;
end;
Best regards, Florin Andrei Medrea.
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro
http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/
mail : florin@microelemente.ro