As mentioned above, I have problems when trying to use LCD (code above) and HPWM at the same time.
This is my HPWM program:
'Connections:
'SW2->RD1 increase switch
'SW3->RA4 decrease switch
'P1->Vdd motor turned on constantly
'RC5/CCP1->N2 CCP1 is pwm output pin
'DC motor is connected to DRIVE 1 and DRIVE 2
'HPWM initialization
duty VAR WORD ' Duty cycle value )
TRISC.5 = 0 ' Set PORTC.5 (CCP1) to output
CCP1CON = %00001100 ' Set CCP1 to PWM
T2CON = %00000101 ' Turn on Timer2, Prescale=4
PR2 = 249 ' Set PR2 to get 1KHz out
duty = 500 ' Set duty cycle to 50%
up var PORTD.1 'user-friendly names for ports
down var PORTA.4
'Main program loop
loop:
CCP1CON.4 = duty.0 ' Store duty to registers as
CCP1CON.5 = duty.1 ' a 10-bit word
CCPR1L = DUTY >> 2
'check if button "up" is pressed and duty is not maximum
IF (up=0) AND (duty<1000) THEN
duty=duty+50
PAUSE 200
ENDIF
'similar as before but for reducing the speed
IF (down=0) AND (duty>0) THEN
duty=duty-50
PAUSE 200
ENDIF
GoTo loop ' Do it forever
End
When I combine these two programs (first LCD then HPWM) it starts to work that is I get "1234" on the LCD and then motor starts to turn but only for 2-3sec. Later is just stops. It looks like PWM signal just dies...?!
I have no idea why these two modules (LCD and HPWM) cannot work togather? I have checked the pins and timing sources but don't see any possible conflicts?
Bookmarks