The problem with PWM in compiller

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
PasiunePePaine
Posts: 1
Joined: 27 Nov 2019 14:51

The problem with PWM in compiller

#1 Post by PasiunePePaine » 27 Nov 2019 15:04

Hello!
I need your help!
I have a problem with PWM function in MikroPascal.
PWM1_Init(5000); is not correct.

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.


17 303 Identifier "PWM1_Init" was not declared pwm_test.mpas

An older version was running, V 6.0 but an V 7.6.0 is not working
Do you have any idea about this problem?

Thank you!
Attachments
PWM problem.jpg
PWM problem.jpg (295.1 KiB) Viewed 1207 times

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: The problem with PWM in compiller

#2 Post by stefan.filipovic » 02 Dec 2019 16:12

Hi,

Welcome to the MikroE forum.

Could you tell me which MCU you were using here?
Make sure to include the PWM library in the Library Manager.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroPascal PRO for PIC General”