Here is my first real project after playing around with LEDs
I have a DC motor with hall sensor and a L297 based stepper driver.
The motor speed can vary from 100 to 3000 RPM.
Calculating the actual speed would be nice but is not necessary.
What I´m trying to do is getting far beyond my present knowledge.
Thanks for any help or hints..
;ChipSettings#chip18F452,20;Defines(Constants)#defineLCD_NO_RW'Needed when RW is grounded#define LCD_IO 4#define LCD_RS PORTE.0#define LCD_Enable PORTE.1#define LCD_DB4 PORTD.4#define LCD_DB5 PORTD.5#define LCD_DB6 PORTD.6#define LCD_DB7 PORTD.7#define Stepper PORTC.1#define Enable PORTB.0#define Direction PORTB.1;VariablesDim Pulse As word;Interrupt HandlersOn Interrupt CCP1 Call Freqdir Stepper outdir Enable outdir Direction outinitCCP1start:Locate 1,0Print (Pulse)Repeat 5 set Stepper onWait 2 ms set Stepper off Wait 2 msend repeatgoto startSub initCCP1 dir PortC.2 in ;pulse input Pin RC2 T1CON = b'00110001' CCP1CON = b'00000101';startpulsecaptureonrisingedgeStartTimer1EndSubSubFreqTMR1L=0;resettimer1TMR1H=0Pulse_H=CCPR1H;readpulsewidthandstorePulse_L=CCPR1LCCP1IF=0;clearcaptureflagEndSub
Last edit: Dirk 2014-02-07
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here's a thought on using CCPX for rpm:
100rpm is going to be 1.667Hz or a 600ms period. At best with a 20Mhz osc and prescale of 8, you will get a period of 0.10486 sec or 572 rpm. With a 4Mhz osc you get 114rpm, so that would really help.
Here's some code updating a servo with the Timer1Overflow interrupt every 20ms.
First thing that strikes me is that a L297 is a stepper controller. You still need a L298 bridge driver for the motor or transistors.
Does your hall sensor pulse once per revolution?
So if you aren't interested in speed then you must be interested in position? You could run the sensor into a counter input to the PIC. But if you reverse the motor you still would count up. Then you need a second sensor and do some logic to determine direction or I guess you are telling the L297 direction so now i am stuck on how to count down in a PIC counter.
Have fun.
M
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
we are talking abaut two different motors.
The first one is a brushed 12v 200W dc-motor rotating clockwise only
with its own PWM driver board. Speed can be adjusted with a pot.
Perhaps, in future I´ll use a TC44xx and a suitable H-Bridge to control the motor.
The second motor is a NEMA17 bipolar stepper.
Logic circuit L297 and two L6203 drivers.
For each revolution of the DC-Motor, max speed is 3000RPM, the stepper
has to do 5 steps and of course reverse after a specific count.
If my math is right, we have 20ms to perform 5 steps in case the DC-motor is running at max speed.
Thanks a lot and have a nice weekend.
D
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is my first real project after playing around with LEDs
I have a DC motor with hall sensor and a L297 based stepper driver.
The motor speed can vary from 100 to 3000 RPM.
Calculating the actual speed would be nice but is not necessary.
What I´m trying to do is getting far beyond my present knowledge.
Thanks for any help or hints..
Last edit: Dirk 2014-02-07
You are updating a continuous rotation servo every 20ms? If it is a straight DC motor then I would us HPWM.
For others, here is the link that discusses using a CCPX module to get a frequency http://sourceforge.net/p/gcbasic/discussion/579126/thread/1c752e92/?limit=25#1ac9
Using select case or math could be faster than using table values.
Here's a thought on using CCPX for rpm:
100rpm is going to be 1.667Hz or a 600ms period. At best with a 20Mhz osc and prescale of 8, you will get a period of 0.10486 sec or 572 rpm. With a 4Mhz osc you get 114rpm, so that would really help.
Here's some code updating a servo with the Timer1Overflow interrupt every 20ms.
First thing that strikes me is that a L297 is a stepper controller. You still need a L298 bridge driver for the motor or transistors.
Does your hall sensor pulse once per revolution?
So if you aren't interested in speed then you must be interested in position? You could run the sensor into a counter input to the PIC. But if you reverse the motor you still would count up. Then you need a second sensor and do some logic to determine direction or I guess you are telling the L297 direction so now i am stuck on how to count down in a PIC counter.
Have fun.
M
Hi mmotte,
we are talking abaut two different motors.
The first one is a brushed 12v 200W dc-motor rotating clockwise only
with its own PWM driver board. Speed can be adjusted with a pot.
Perhaps, in future I´ll use a TC44xx and a suitable H-Bridge to control the motor.
The second motor is a NEMA17 bipolar stepper.
Logic circuit L297 and two L6203 drivers.
For each revolution of the DC-Motor, max speed is 3000RPM, the stepper
has to do 5 steps and of course reverse after a specific count.
If my math is right, we have 20ms to perform 5 steps in case the DC-motor is running at max speed.
Thanks a lot and have a nice weekend.
D