Author Topic: Pwm for pic 16f84A and DC motor  (Read 1874 times)

0 Members and 1 Guest are viewing this topic.

Offline AlienOnEarthTopic starter

  • Newbie
  • Posts: 2
  • Country: ro
Pwm for pic 16f84A and DC motor
« on: April 02, 2017, 05:29:58 pm »
Hello guys!

I want to make a PWM for PIC 16F84A and a DC motor. I use Mplab ide and hitech C compiler.

I have found some code on the internet but I have got an error when I compile it:

Error   [192] D:\Documents\cod licenta\licenta (1).c; 17.1 undefined identifier "OPTION_REG"

Can you give me some advice to get rid of this error, or maybe another source code for a PWM?

In the attachment you will find the code if you want to look on it.

Thank you!
Have a nice evening  :)
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Pwm for pic 16f84A and DC motor
« Reply #1 on: April 02, 2017, 06:08:48 pm »
Quote
PWM for PIC 16F84A
why on earth.

anyway, read this: http://www.microchip.com/forums/m717850.aspx
 

Offline AlienOnEarthTopic starter

  • Newbie
  • Posts: 2
  • Country: ro
Re: Pwm for pic 16f84A and DC motor
« Reply #2 on: April 02, 2017, 06:37:43 pm »
Thank you very much!

Now it is working but it is not functional in Proteus. |O
Do you have an example of a pwm generator code? Or some suggestions of how to modify the existing code.

Thanks
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1612
  • Country: gb
Re: Pwm for pic 16f84A and DC motor
« Reply #3 on: April 02, 2017, 10:40:14 pm »
I believe the reaction was for the old device.  Nothing wrong with old devices, but it just makes your life more difficult.  The '84A is well over 20 years old, expensive, doesn't have many peripherals, and poor support.  Almost all of the existing projects for it will happily work on other PIC16's.
 
The following users thanked this post: AlienOnEarth

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Pwm for pic 16f84A and DC motor
« Reply #4 on: April 03, 2017, 12:39:07 pm »
Precisely. Make your life easier!
Anyway, The code you have posted is 100% okay, as to make a software pwm you have to do three things
1)set up a timebase, try also to use an interrupt so jitter will be reduced
2)set up three registers: counter, period,duty.
3)inside the interrupt (or at each timebase event) do the following:
- increase counter
- if counter is greater or equal than period reset counter
- if counter is less or equal than duty out is low/high, otherwise out is high/low
 
The following users thanked this post: AlienOnEarth


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf