Pozdrav,
pokušavam na djelomično promjenjenom kodu (Mikrobasic, 16F887, 8 Mhz, EasyPic5) promjeniti pin (u originalu modulirani signal se pojavljuje samo na RC2). Iz toga razloga sam i dodao registar PSTRCON=$00101000(definira ulogu pinova za PWM) i želio sam preusmjeriti signal na RD7. Kada uključim i taj registar nestaje signal sa RC2 ali se niti jedna druga ledica ne pali. Pokušavao sam i sa drugim pinovima (RD5 i RD6) ali ništa.Što pogrešno radim? Molim pomoć.
' *
' * Project name
' PWM
' * Description
' The changes can be monitored on the CCP output pin (RC2).
' * Test configuration
' MCU: P16F887
' Dev.Board: EasyPIC5
' Oscillator: HS, 08.0000 MHz
' Ext. Modules: -
' SW: mikroBasic v7.1
program PWM1_Test_01
dim current_duty, old_duty, nn as byte
sub procedure InitMain
ANSEL = 0 ' Configure AN pins as digital I/O
ANSELH = 0
PORTC = 0 ' set PORTC to 0
TRISC = 0 ' designate PORTC pins as output
TRISD = 0
CCP1CON=$00001100 ' Single PWM mode; P1A, P1C active-high; P1B, P1D active-high
PSTRCON=$00101100
PWM1_Init(5000) ' Initialize PWM1 module at 5KHz
end sub
main:
initMain()
current_duty = 16 ' initial value for current_duty
old_duty = 0 ' old_duty will keep the 'old current_duty' value
PWM1_Start() ' start PWM1
while TRUE ' endless loop
for nn=0 to 255
Inc(current_duty)
PWM1_Change_Duty(current_duty)
delay_ms (10)
next nn
if current_duty=255 then
current_duty=0
end if
Delay_ms(1000) ' slow down change pace a little
wend
end.
PWM - radi samo pin RC3
Moderators: pedja089, stojke369, [eDo], trax
Re: PWM - radi samo pin RC3
Uradio sam svoj kod sljedeći datesheet za 16F887. Kod izvrsno radi za opciju half bridge (u oba smjera). U naprednom modu (jednostrukom PWM modu) po uputstvu trebalo bi signal moći propustiti na sve željene pinove uz pomoć ragistra PSTRCON, dva bita P1M1 i P1M1= u registru CCP1CON, tedva bita CCPM0 i CCP1M1 u registru CCP1CON. I opet ništa , signala nema pa nema. Gdje griješim?
Moj novi kod:
program PWM_moj
' *
' * Project name
' * PWM without MB-library
' * Description
' This code demonstrates using TMR2 and PWM without MB-library. Buttons B1
' and A0 decrise and increse pulse.
' * Test configuration
' MCU: P16F887
' Dev.Board: EasyPIC5
' Oscillator: HS, 08.0000 MHz
' SW: mikroBasic Pro for PIC
' * NOTES
dim cnt, oldstate, oldstate_2 as BYTE
sub procedure interrupt
if (PIR1.TMR2IF) then
PIR1.TMR2IF = 0 ' clears TMR2IF
TMR2 = 0
CCPR1L=CNT
end if
end sub
main:
cnt=122
oldstate=0
oldstate_2=0
ANSEL = 0 ' Configure AN pins as digital I/O
ANSELH = 0
TRISA.0=1
TRISB.0=1
TMR2 =0 ' Initialize Timer2 register
PIE1.TMR2IE = 1 ' enable interupt
INTCON = $C0 ' Set GIE, PEIE
TRISC.2=1
PR2=255
CCP1CON.P1M1=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.P1M0=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.CCP1M3=1
CCP1CON.CCP1M2=1
CCP1CON.CCP1M1=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.CCP1M0=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.DC1B1=1
CCP1CON.DC1B0=0
PIR1.TMR2IF=0
T2CON.T2CKPS1=0
T2CON.T2CKPS0=0
T2CON.TMR2ON=1
TRISC.2=0
TRISD=%00011111
while TRUE
if (Button(PORTB, 1, 1, 1)) then
oldstate = 1
cnt=cnt-1
delay_ms(1)
end if
if (oldstate and Button(PORTB, 1, 1, 0)) then
oldstate = 0
end if
if (Button(PORTA, 0, 1, 1)) then
oldstate_2 = 1
cnt=cnt+1
delay_ms(1)
end if
if (oldstate_2 and Button(PORTA, 0, 1, 0)) then
oldstate_2 = 0
end if
if cnt>=254 then
cnt=253
end if
If cnt<=1 then
cnt =2
end if
PSTRCON=%00001111 'OVDJE SE DEFINIRAJU PINOVI ZA IZLAZ PWM SIGNALA
wend
end.
Moj novi kod:
program PWM_moj
' *
' * Project name
' * PWM without MB-library
' * Description
' This code demonstrates using TMR2 and PWM without MB-library. Buttons B1
' and A0 decrise and increse pulse.
' * Test configuration
' MCU: P16F887
' Dev.Board: EasyPIC5
' Oscillator: HS, 08.0000 MHz
' SW: mikroBasic Pro for PIC
' * NOTES
dim cnt, oldstate, oldstate_2 as BYTE
sub procedure interrupt
if (PIR1.TMR2IF) then
PIR1.TMR2IF = 0 ' clears TMR2IF
TMR2 = 0
CCPR1L=CNT
end if
end sub
main:
cnt=122
oldstate=0
oldstate_2=0
ANSEL = 0 ' Configure AN pins as digital I/O
ANSELH = 0
TRISA.0=1
TRISB.0=1
TMR2 =0 ' Initialize Timer2 register
PIE1.TMR2IE = 1 ' enable interupt
INTCON = $C0 ' Set GIE, PEIE
TRISC.2=1
PR2=255
CCP1CON.P1M1=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.P1M0=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.CCP1M3=1
CCP1CON.CCP1M2=1
CCP1CON.CCP1M1=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.CCP1M0=0 'OVA DVA BITA SE MJENJAJU
CCP1CON.DC1B1=1
CCP1CON.DC1B0=0
PIR1.TMR2IF=0
T2CON.T2CKPS1=0
T2CON.T2CKPS0=0
T2CON.TMR2ON=1
TRISC.2=0
TRISD=%00011111
while TRUE
if (Button(PORTB, 1, 1, 1)) then
oldstate = 1
cnt=cnt-1
delay_ms(1)
end if
if (oldstate and Button(PORTB, 1, 1, 0)) then
oldstate = 0
end if
if (Button(PORTA, 0, 1, 1)) then
oldstate_2 = 1
cnt=cnt+1
delay_ms(1)
end if
if (oldstate_2 and Button(PORTA, 0, 1, 0)) then
oldstate_2 = 0
end if
if cnt>=254 then
cnt=253
end if
If cnt<=1 then
cnt =2
end if
PSTRCON=%00001111 'OVDJE SE DEFINIRAJU PINOVI ZA IZLAZ PWM SIGNALA
wend
end.