I want square pulse of 50Hz from a pin of PIC16F676. I cannot use PWM as CCP pin is not available I am using mikroc for programming.
How can I achieve what I required ?
Please help me out, Thanks in advance.
I'd run an interrupt with 100Hz (10ms) and toggle the pin in the ISR.
..just a couple of code lines. Works independently from other code in main().
Maybe uses less than 1% of processing power.
I'd run an interrupt with 100Hz (10ms) and toggle the pin in the ISR.
..just a couple of code lines. Works independently from other code in main().
Maybe uses less than 1% of processing power.
This is very basic thus it's explained many thousand times in the internet.
Please do an internet search on your own. You will find internet pages, documents, tutorials, even videos...many example codes.
1. configure a timer so it rolls over from maximum to zero 100 times a second (100Hz)
2. enable the interrupt for that timer.
3. write an interrupt routine that toggles the state of the pin you want.
A better method than 3 above is to simply increment a counter at every interrupt then copy the least significant bit to the output pin. A potential problem with toggling is PICs read the pin in, invert the bit then write it out again so if anything external loads the pin it might read the state incorrectly. Writing the LSB doesn't require the pin to be read so the problem is avoided.