Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] How can I generate square pulses of 50Hz from PIC16F676 in Mikroc.

Status
Not open for further replies.

hammad1

Newbie
Joined
Jun 6, 2021
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
15
Hi, Everyone I am new in PIC programming.

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.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,043
Helped
4,716
Reputation
9,448
Reaction score
5,091
Trophy points
1,393
Activity points
152,644
Hi,

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.

Klaus
 

hammad1

Newbie
Joined
Jun 6, 2021
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
15
Hi,

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.

Klaus
Thanx for helping. I am a beginner can u elaborate more or can u post a demo code for better understanding.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
23,043
Helped
4,716
Reputation
9,448
Reaction score
5,091
Trophy points
1,393
Activity points
152,644
Hi,

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.

I'm not able to explain better...

Klaus
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
15,731
Helped
5,069
Reputation
10,163
Reaction score
4,924
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
133,218
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.

Brian.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top