-
Pwm 16f628
Hi
I need help
I have to read Port RB4 to RB7
The number I get from that reading (0-15) it has to be PWM output.
Mu question is how to use PWM on pic 16f628
This PWM signal has to be active 300ms and then read again portb4 to portb7
Rule
1.read portb4 to portb7
2.set pwm dutycycle (depend of reading value of portb)
3.activate pwm for 300ms
4.go to 1.
Thanks Milan
-
First there is no RB8, there is a RB7 though which is the 8th bit.
Are you reading a DIP switch or something?
-
I would read the port by using:
Code:
pwm_value.0 = portb.4
pwm_value.1 = portb.5
pwm_value.2 = portb.6
pwm_value.3 = portb.7
This will load the value between 0-15 in the byte sized variable pwm_value. If your running @ 4 MHz then you could use:
This would give you a 50% duty cycle for about 300ms out on portb.0. Or you can use the hardware PWM which is on portb.3.
-
Pwm
Hi
Thanks for help.
Those 4 bits I get from PC parallel port.
I would like to know how to use HPWM?
Milan
-
I think about the only thing you have to do is:
Code:
hpwm 0,pwm_value,32767
pause 300
CCP1CON = 0
The first line starts the PWM at whatever value is stored in the pwm_variable at 32.767kHz. It then pauses for 300ms then turns off the HPWM.