pic 16f886 0r 887 pwm half bridge power supply

General discussion on mikroElektronika website & forums.
Post Reply
Author
Message
christian lahoud
Posts: 12
Joined: 25 Apr 2015 01:59

pic 16f886 0r 887 pwm half bridge power supply

#1 Post by christian lahoud » 22 Dec 2019 19:56

hello!
this is my code to generate half bridge pwm signal on pin rc2 and rb2
the problem is that when i change the analog signal or duty cycle value the output will be inverted on rb2.
i need to generate a phase shifted pwm with dead time and a duty cycle that work properly on both outputs
anyone can help me to fix this ?

program :
dim duty_cycle as word
desired as float
MIN_INPUT as float
MAX_INPUT as float

main:
osccon = 117 ' oscillator config
ANSEL = 255 ' Configure AN2 pin as analog
ANSELH = 0 ' Configure other AN pins as digital I/O
TRISB = 0x00 'Make PORTB as Output
PORTB = 0
TRISA = 0xFF ' PORTA is input
TRISC = 0x00 ' designate PORTC pins as output for pwm pin
portc=0

PWM1_Init(500) ' Initialize PWM1 module at 500Hz
MIN_INPUT = 1 * ( 1023/5)
MAX_INPUT = 4 * ( 1023/5)
CCP1CON = %10001101
'CCPR1L=0''''; // Start with zero Duty Cycle
PWM1CON = %00111111
PSTRCON = %00010011' ; // Enable Pulse Steering on P1C (RC3)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
PWM1_Start()

while TRUE ' Endless loop
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'SPEED READING ON RA0 INPUT PIN
PWM1_Set_Duty(duty_cycle)

desired = ADC_Read(0) ' Get 10-bit results for duty_cycle
if (desired <= MIN_INPUT )then
desired = 0
else
if (desired >= MAX_INPUT )then
desired = 1023
else
desired = (desired - MIN_INPUT) * (1023 / (MAX_INPUT-MIN_INPUT))
end if
end if
portc.4=0
duty_cycle = (desired/4)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

wend
end.

Post Reply

Return to “Website & Forums General Discussion”