[v 2.15 pro] PWM Problem

Beta Testing discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
alcidesramos
Posts: 272
Joined: 17 Feb 2009 02:39
Location: Colombia
Contact:

[v 2.15 pro] PWM Problem

#1 Post by alcidesramos » 30 Jun 2009 19:29

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.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#2 Post by yo2lio » 30 Jun 2009 20:11

The library don't support both PWM together !
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

piort
Posts: 1379
Joined: 28 Dec 2005 16:42
Location: Laval,Québec,Canada,Earth... :-)
Contact:

#3 Post by piort » 30 Jun 2009 20:30

hi,
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.
look where they put the init, the duty and the start...

HTH a bit ;-)

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#4 Post by yo2lio » 30 Jun 2009 20:38

I use this code with PIC18F24K20 :

Code: Select all

  Pwm1_Init(1000);
  Pwm1_Set_Duty(127);
  Pwm1_Start();;
  Pwm2_Set_Duty(127);
  Pwm2_Start();
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

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

Post Reply

Return to “mikroPascal PRO for PIC Beta Testing”