Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Changing the output frequency of a PIC to 2kHz

Status
Not open for further replies.

trevoooor

Newbie level 2
Joined
Jul 20, 2009
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,297
Hi All

I have a question about a 12V Dc Motor project I am undertaking at school. I am using a PIC 16F84A and all I need to do is change the output frequency from the chip to 2kHz to the motor. I have looked in Microchip and searched the forum but I must be looking in the wrong places. Just need a little puch in the right direction.

Thanks
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,574
Helped
4,778
Reputation
9,573
Reaction score
4,558
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
124,235
interrupt 16f628 mikroc timer0 function

In nearly 50 years of experience, I have never seen a motor that needs 2Mhz to drive it. It must be a VERY fast motor!!

Can you re-phrase your question so it explains why 2MHz is needed and not the low frequency or DC that motors usually need.

Brian.
 

maheshkuruganti

Advanced Member level 4
Joined
May 18, 2007
Messages
106
Helped
7
Reputation
14
Reaction score
3
Trophy points
1,298
Location
India
Activity points
1,910
up/down counter with 16f628a

Theoretically you can use TMR0 to Set at Interrupt at 4Khz and then Toggle the Output.But you could rather go for a 628 like blueroom says as it is much easier to use. Also 84A is an obsolete part which is expensive than the 628
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,574
Helped
4,778
Reputation
9,573
Reaction score
4,558
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
124,235
pic frequency interrupt

Trevoor has contacted me by PM to explain the error in his first message which originally said 2MHz not KHz.

As the other have said, the 16F84 is not a good choice for this application and the 16F628A is *almost* identical but has extra features. I have used 628A's as plug in upgrades for 84A devices and mailed them to customers to swap over they are so similar. The 628A is also cheaper and you may be able to utilize it's internal oscilator to reduce your component count as well.

You haven't said why you need 2KHz to drive a DC motor so I'm guessing you are controlling it's speed by PWM. The 628A has built in PWM, the 84A does not.

Having said that, if you really want to use the 84A, this is what you do:

Based on your clock frequency, work out the prescaler ratio and value to pre-load into TMR0 to give a 2KHz roll-over interrupt.

In your interrupt routine, re-load the value into TMR0 for the next roll-over (remember it counts up not down so load the number of remaining counts, not the number you actually want - also remember that as the time in interrupt TMR0 = 0)
Now clear your PWM output pin, this is your frame reference point.

At this point you are resetting you output pin at a 2KHz rate.

Now you need to use a counter in software to set the pin (switch it on). Ideally, you want a counter that reaches maximum value in 500uS so it gives as many possible different values. Set it at zero at the start of your frame period. When you reach the desired count, turn the pin on.

This is only one of many ways you can do it. For example you could reverse the on and off in the example above or you could drive your counter from the timer and provide the framing period in software. You can even do it without the timer at all.

Brian.
 

elrayes

Full Member level 5
Joined
Jun 3, 2008
Messages
246
Helped
20
Reputation
40
Reaction score
7
Trophy points
1,298
Location
Egypt/Canada
Activity points
2,780
PIC Frequency

simply if you are using MikroC or C18 you can use software delay functions to create 2Khz frequency to the motor, but as most of the previous colleagues mentioned use PIC timer or another PIC with a PWM module.

good luck
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top