Author Topic: PIC  (Read 1401 times)

0 Members and 1 Guest are viewing this topic.

Offline cataTopic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
PIC
« on: November 15, 2010, 02:59:28 PM »
PIC micro controller in close loop that control the velocity of the motor ... 
« Last Edit: November 24, 2010, 01:10:01 PM by cata »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: PIC
« Reply #1 on: November 15, 2010, 04:30:14 PM »
Your statements are not very clear but I think I know what you want to do so I'll try restating your requirements.

1- Using the CCP module to output PWM to control the motors speed (angular velocity).
2- A Hall effect sensor detects the motor speed or period of a revolution and is an input to the PIC.
3- Using a hardware timer (TMR1) to measure the period of the Hall sensor pulse times.
4- Use the TMR1 period to adjust the PWM output duty cycle to maintain the motor speed.

Is this correct?


Offline cataTopic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: PIC
« Reply #2 on: November 16, 2010, 02:03:26 AM »
Thanks
« Last Edit: November 24, 2010, 01:10:42 PM by cata »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: PIC
« Reply #3 on: November 16, 2010, 08:47:33 AM »
Ok. This isn't very hard to do. In writing your code start by writing out the steps needed in your native language. This helps you see clearly what you need to have the code do.

For your application interrupts would be best. The PWM duty gets adjusted in the TMR2 ISR (Interrupt Service Routine) and use one of the PIC inputs that can cause an interrupt for the Hall sensor (INT0 or one of the PortB IOCs would work. In the Hall sensor ISR grap the counts from the timer, reset the timer (to start counting the next period), set a flag (a bit) to signal the PWM ISR to recalculate and update the duty cycle.

I posted code I use for my bot in this thread:
http://www.societyofrobots.com/robotforum/index.php?topic=11042.0
Look for the P_bot.c attachment.
This code controls two motors and measures the wheel speed to adjust the PWM duty.
The code is written for the free HiTech compiler available from Microchip for the 16F874 but is easy to port to the 16F88 with only a few minor changes. Compare the ports in the data sheets for the two PICs for differences.

For learning PIC programming I recommend these tutorials:
http://www.gooligum.com.au/tutorials.html

Do use the MPLAB SIMulator to test your code and/or to learn how the code works.

 


data_list