Hi everyone,
I seem to have come across a small problem in my current project.
I am using a PIC16F648A microcontroller that is programmed to take digital inputs, with the aid of buttons, across two pins of PORTA. According to which button is pressed and ultimately which pin registers a high edge, the microcontroller is supposed to either give out a constant 5V high or a PWM of 4.5V for a few seconds out of the same PORTB.0 pin. The program loop constantly checks for input activity.
Now here is the problem. The moment I press the button that initiates the PWM command, the microcontroller stops responding to the button that initiates the constant 5V high afterwards but keeps responding to the button that initiates the PWM. I have tried another two 16F628A microcontrollers but they seem to have the same problem.
Here is my code, I am using PICBasic Pro:
trisa = %00000011 'PORTA.0 and PORTA.1 are defined as inputs
trisb = %00000000 'All PORTB ports are defined as outputs
CMCON = %00000111 'Comparators for PORTA.0-3 are switched off
Main:
IF porta.0 = 1 THEN
portb.0 = 1
PAUSE 3000 'Pausing for 3 seconds
portb.0 = 0
ENDIF
PAUSE 5
IF porta.1 = 1 THEN
PWM portb.0, 230, 600
ENDIF
PAUSE 5
GOTO Main
END
Regarding the PWM command in the code; there are 230 steps(out of 256), which determine the duty cycle(0 = 0% and 255 = 100% duty cycle) and ultimately the average voltage. There are also 600 cycles of 5ms that add up to 3 seconds in duration.
I have also tried different IF-THEN setups that jump to a different label to initiate the action and jump back to the Main loop but they display the same problem. I am using an external 4MHz crystal with pump charge capacitors.
Any help is appreciated.
Thanks
I seem to have come across a small problem in my current project.
I am using a PIC16F648A microcontroller that is programmed to take digital inputs, with the aid of buttons, across two pins of PORTA. According to which button is pressed and ultimately which pin registers a high edge, the microcontroller is supposed to either give out a constant 5V high or a PWM of 4.5V for a few seconds out of the same PORTB.0 pin. The program loop constantly checks for input activity.
Now here is the problem. The moment I press the button that initiates the PWM command, the microcontroller stops responding to the button that initiates the constant 5V high afterwards but keeps responding to the button that initiates the PWM. I have tried another two 16F628A microcontrollers but they seem to have the same problem.
Here is my code, I am using PICBasic Pro:
trisa = %00000011 'PORTA.0 and PORTA.1 are defined as inputs
trisb = %00000000 'All PORTB ports are defined as outputs
CMCON = %00000111 'Comparators for PORTA.0-3 are switched off
Main:
IF porta.0 = 1 THEN
portb.0 = 1
PAUSE 3000 'Pausing for 3 seconds
portb.0 = 0
ENDIF
PAUSE 5
IF porta.1 = 1 THEN
PWM portb.0, 230, 600
ENDIF
PAUSE 5
GOTO Main
END
Regarding the PWM command in the code; there are 230 steps(out of 256), which determine the duty cycle(0 = 0% and 255 = 100% duty cycle) and ultimately the average voltage. There are also 600 cycles of 5ms that add up to 3 seconds in duration.
I have also tried different IF-THEN setups that jump to a different label to initiate the action and jump back to the Main loop but they display the same problem. I am using an external 4MHz crystal with pump charge capacitors.
Any help is appreciated.
Thanks