PWM with 12f615

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
Itzco
Posts: 28
Joined: 18 Mar 2012 02:37

PWM with 12f615

#1 Post by Itzco » 10 Mar 2013 19:31

Hi everybody :D

I was just wandering if somebody could helpme with these trouble. I´m trying to set:
PWM1_Init
PWM1_Set_Duty
PWM1_Start
PWM1_Stop :shock:

but none of these seem to function. :evil:

Code: Select all

WM_puente_H

' Declarations section 
dim current_duty, current_duty1, old_duty, old_duty1 as byte

sub procedure InitMain()
cmcon1=7
ANSEL = 0 ' Configure AN pins as digital I/O
TRISIO = %00101000 ' configure PORTA pins as input
PWM1_Init(5000) ' Initialize PWM1 module at 5KHz
PWM2_Init(5000) ' Initialize PWM2 module at 5KHz
end sub

main:
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) ' endless loop
if (RA0_bit <> 0) then ' button on RA0 pressed
Delay_ms(40)
Inc(current_duty) ' increment current_duty
PWM1_Set_Duty(current_duty)
end if
if (RA1_bit <> 0) then ' button on RA1 pressed
Delay_ms(40)
Dec(current_duty) ' decrement current_duty
PWM1_Set_Duty(current_duty)
end if
if (RA2_bit <> 0) then ' button on RA2 pressed
Delay_ms(40)
Inc(current_duty1) ' increment current_duty1
PWM2_Set_Duty(current_duty1)
end if
if (RA3_bit <> 0) then ' button on RA3 pressed
Delay_ms(40)
Dec(current_duty1) ' decrement current_duty1
PWM2_Set_Duty(current_duty1)
end if
Delay_ms(5) ' slow down change pace a little
wend
end.
i mean, pic12f615 has 4 PWM outputs but i do´t know how i should call them to run, or should i place them on other site? :roll:

Well hope you can helpme
Have a good day :wink:

PD: also my CONFIG word is set: :$2007 : 0x0355 :mrgreen: :mrgreen:

Durango
Posts: 134
Joined: 11 May 2006 17:48
Location: Maryland USA

Re: PWM with 12f615

#2 Post by Durango » 11 Mar 2013 00:29

Hi,

I changed some of your program to at least get it to compile for your chip.

Code: Select all

' Declarations section
dim current_duty, current_duty1, old_duty, old_duty1 as byte

sub procedure InitMain()
    'cmcon1=7
    cmcon0 = 0      ' disable comparator
    ANSEL = 0       ' Configure AN pins as digital I/O
    TRISIO = %00000011          ' configure GPIO bits 0 and 1 as input
    PWM1_Init(5000) ' Initialize PWM1 module at 5KHz
'    PWM2_Init(5000) ' Initialize PWM2 module at 5KHz
end sub

main:
    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) ' endless loop
        if (GP0_bit <> 0) then ' button on RA0 pressed
            Delay_ms(40)
            Inc(current_duty) ' increment current_duty
            PWM1_Set_Duty(current_duty)
        end if
        if (GP1_bit <> 0) then ' button on RA1 pressed
           Delay_ms(40)
           Dec(current_duty) ' decrement current_duty
           PWM1_Set_Duty(current_duty)
        end if
'        if (RA2_bit <> 0) then ' button on RA2 pressed
'           Delay_ms(40)
'           Inc(current_duty1) ' increment current_duty1
'           PWM2_Set_Duty(current_duty1)
'        end if
'        if (RA3_bit <> 0) then ' button on RA3 pressed
'           Delay_ms(40)
'           Dec(current_duty1) ' decrement current_duty1
'           PWM2_Set_Duty(current_duty1)
'        end if
        Delay_ms(5) ' slow down change pace a little
    wend

end.
This chip only has one PWM so I commented out any PWM2 commands and I also changed the port names to GPx.

It now programs and pin 5 (GP2) should have a PWM on it hopefully.

Good luck

Itzco
Posts: 28
Joined: 18 Mar 2012 02:37

Re: PWM with 12f615

#3 Post by Itzco » 11 Mar 2013 03:50

uuu actually you are right, it just recognizes one pwm :( , but but but but on page 8 it says it has 4 :roll:
http://www.agspecinfo.com/pdfs/P/PIC12F6B.PDF
:roll:

do you know a 12fxxxx which has at least pwm outputs?

Thankyou for your help, now the program is compiling
Regards

Itzco
Posts: 28
Joined: 18 Mar 2012 02:37

Re: PWM with 12f615

#4 Post by Itzco » 14 Mar 2013 03:00

Hi haha, i just realized i made a mistake on my last question :lol: , i was wondering if you know about a pic12f which had
at least two PWM outputs :lol:

Thankyou again
Regards

manno
Posts: 3
Joined: 17 Jan 2024 09:40

Re: PWM with 12f615

#5 Post by manno » 17 Jan 2024 11:51

Hello,
I want to jump in this old post because I cannot compile a PWM code I wrote. Thinking it was some mistake I did, I found and copied the exact code below by Durango but the compiler (mikrobasic) returns the following error at line 11 anyway:

0 133 Compilation Started C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for PIC\Examples\Progetti\Test_PWM2.mbas
1 1015 Hint: Compiling unit "C:\Users\Public\Documents\Mikroelektronika\mikroBasic PRO for PIC\Examples\Progetti\Test_PWM2.mbas"
11 303 Identifier "PWM1_Init" was not declared
11 304 Syntax error: Expected "end" but "PWM1_Init" found
11 304 Syntax error: Expected "sub" but "(" found
11 304 Syntax error: Expected "end" but "5000" found
11 304 Syntax error: Expected "." but ")" found
0 102 Finished (with errors): 17 gen 2024, 11:01:58 Test_PWM2.mbppi


Can anyone address me to understand what's wrong? I attached the settings for this simple project. At first I set INTOSCIO for the oscillator section but since it wasn't compiling the code I switched to XT thinking this was the reason
Thanks
Ermanno
Attachments
settings.png
settings.png (54.22 KiB) Viewed 1620 times

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: PWM with 12f615

#6 Post by IvanJeremic » 17 Jan 2024 12:27

Hi,

You need to turn on the PWM library in the library manage on the right side of the compiler.
PWM.png
PWM.png (12.85 KiB) Viewed 1618 times
Regards,

Ivan.

manno
Posts: 3
Joined: 17 Jan 2024 09:40

Re: PWM with 12f615

#7 Post by manno » 17 Jan 2024 13:47

Great! Many thanks!!
I didn't knew this... maybe the last time I used mikrobasic the libraries were enabled by default? I remember that I wrote some code for the LCDs in the past but without flagging any library.
Good to know anyway.
Thanks again.
Ermanno

User avatar
IvanJeremic
mikroElektronika team
Posts: 316
Joined: 05 Sep 2022 14:32

Re: PWM with 12f615

#8 Post by IvanJeremic » 19 Jan 2024 11:25

Hi,

When changing the project in some way (changing the MCU for example) it can cause the libraries to turn off, so it is always best to check them.

Regards,

Ivan.

Post Reply

Return to “mikroBasic PRO for PIC General”