PWM con moduli Option Compare

Sto lavorando con un PIC24EP512GU814 a 20Mhz usando il mikroBasic PRO for dsPIC della Mikroelektronika. Ho un problema con la gestione di due canali PWM.

che ho costruito ho modificato un programma di demo della Mikroelettronica in modo che le entrate corrispondano a degli interruttori e le uscite a due led.

program ProvaPwm dim current_duty, old_duty, current_duty1, old_duty1 as word pwm_period1, pwm_period2 as word

sub procedure InitMain() PLLPRE_0_bit = 0 PLLPRE_1_bit = 0 PLLPRE_2_bit = 0 PLLPRE_3_bit = 0 PLLPRE_4_bit = 0

PLLFBD = 38 ' PLL multiplier M=38

PLLPOST_0_bit = 0 PLLPOST_1_bit = 0

ANSELA = 0x00 ' Convert all I/O pins to digital ANSELB = 0x00 ANSELC = 0x00 ANSELD = 0x00 ANSELE = 0x00 ANSELG = 0x00

TRISG = 0xFFFF ' configure PORTG pins as input PORTD = 0 ' set PORTD to 0 TRISD = 0 ' designate PORTD pins as output end sub

main: InitMain() current_duty = 127 ' initial value for current_duty current_duty1 = 127 ' initial value for current_duty1

PPS_Mapping(64, _OUTPUT, _OC1) ' RD0 PPS_Mapping(67, _OUTPUT, _OC2) ' RD3

pwm_period1 = PWM_Init(5000 , 1, 1, 2) 'Frequenza (Hz),Canale PWM, timer prescaler(1,8,64, 256), timer usato (2,3) pwm_period2 = PWM_Init(10000, 2, 1, 3)

PWM_Start(1) PWM_Start(2)

PWM_Set_Duty(current_duty, 1) ' set current duty for PWM1 PWM_Set_Duty(current_duty1, 2) ' set current duty for PWM2

while (TRUE) ' endless loop if RG0_bit = 1 then ' button on RA0 pressed Delay_ms(2) Inc(current_duty) ' increment current_duty if (current_duty > pwm_period1) then ' if we increase current_duty greater then possible pwm_period1 value current_duty = 0 ' reset current_duty value to zero end if PWM_Set_Duty(current_duty, 1) ' set newly acquired duty ratio end if

if RG1_bit = 1 then ' button on RA1 pressed Delay_ms(2) Dec(current_duty) ' decrement current_duty if (current_duty > pwm_period1) then ' if we decrease current_duty greater then possible pwm_period1 value (overflow) current_duty = pwm_period1 ' set current_duty to max possible value end if PWM_Set_Duty(current_duty, 1) ' set newly acquired duty ratio end if

if RG6_bit = 1 then ' button on RA2 pressed Delay_ms(2) Inc(current_duty1) ' increment current_duty1 if (current_duty1 > pwm_period2) then ' if we increase current_duty1 greater then possible pwm_period2 value current_duty1 = 0 ' reset current_duty1 value to zero end if PWM_Set_Duty(current_duty1, 2) ' set newly acquired duty ratio end if

if RG7_bit = 1 then ' button on RA3 pressed Delay_ms(2) Dec(current_duty1) ' decrement current_duty1 if (current_duty1 > pwm_period2) then ' if we decrease current_duty1 greater then possible pwm_period1 value (overflow) current_duty1 = pwm_period2 ' set current_duty to max possible value end if PWM_Set_Duty(current_duty1, 2) end if

Delay_ms(2) ' slow down change pace a little wend end.

cenni di vita.

mio) montato in una demoboard Mikroelektronika che gira a 80 Mhz Ho provato a cambiare diverse cose:

- ho messo le frequenze a 5000 hz (non mi interessa al momento far girare i canali PWM a una frequenza particolare)

con la stessa uscita che aveva il primo canale (e qui non riesco a spiegarmelo).

canale PWM non funziona nemmeno a calci? Cosa sto sbagliando? (...e sopratutto, sono riuscito a spiegarmi? ;-) ) Grazie per l'attenzione!

Antonio

--
    Antonio 
http://brunettigiovanni.it  (sconti per chi cita questa lettera) 
http://ecceteraeccetera.it 
http://antoniopellati.it 
http://tecnologiadistudio.it
Reply to
Antonio
Loading thread data ...

Il 07/06/2015 18:19, Antonio ha scritto:

trovato la soluzione da solo... Grazie comunque.

--
    Antonio 
http://brunettigiovanni.it  (sconti per chi cita questa lettera) 
http://ecceteraeccetera.it 
http://antoniopellati.it 
http://tecnologiadistudio.it
Reply to
Antonio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.