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.

Motion DC Brushed motor PIC18Fxx41

Status
Not open for further replies.

myown

Member level 1
Joined
Jun 27, 2004
Messages
32
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
280
i=poscnth;

Code:
#include "D:\4431.h"

#BYTE QEICON=0xFB6 
#BYTE POSCNTH=0xF67 //Capture 2 Register, High Byte / QEI Position Counter Register, High Byte
#BYTE POSCNTL=0xF66 //Capture 2 Register, Low Byte / QEI Position Counter Register, Low Byte
#BYTE MAXCNTH=0xF65 //Capture 3 Register, High Byte / QEI Max. Count Limit Register, High Byte
#BYTE MAXCNTL=0xF64 //Capture 3 Register, Low Byte / QEI Max. Count Limit Register, Low Byte
#BYTE ANSEL0=0xFB8 //
#BIT ANS2=ANSEL0.2
#BIT ANS3=ANSEL0.3
#BIT ANS4=ANSEL0.4

#include "QEI.h"

#BYTE PWMCON0=0xF6F // PWM CONTROL REGISTER 0
#BYTE PTCON0=0XF7F // PWM TIMER CONTROL REGISTER 0
#BYTE PTCON1=0XF7E // PWM TIMER CONTROL REGISTER 0
#BYTE PTPERH=0xF7A // PWM Period Registers
#BYTE PTPERL=0xF7B // PWM Period Registers

#use fast_io(A)
#use fast_io(B)
#use fast_io(C)


#BYTE PORTA=0xF80
#BYTE PORTB=0xF81
#BYTE PORTC=0xF82

#BIT RB0=PORTB.0
#BIT RB1=PORTB.1

//CONNECT TO LCD ( FANUC 3000 )

#BIT DD1=PORTC.0   // XA (a) 1
#BIT DD2=PORTC.1   // XA (a) 2
#BIT DD4=PORTC.2   // XA (a) 3
#BIT DD8=PORTC.3   // XA (a) 4
#BIT DWT=PORTC.4   // XA (a) 5


static unsigned int32 currentQEIPos,temp; 	//must be signed long because of arithmetic.

#include "D:\f3000.h"

#int_rtcc                       
void clock_isr() //LED display  from fanuc 3000
{              
select_axis(x);
data_output(currentQEIPos);
}

void main()
{
   set_tris_a(0xff);
   set_tris_b(0b00111100);
   set_tris_c(0);
   set_tris_d(0xff);
   set_tris_e(0xff);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF|ADC_TAD_MUL_0|ADC_WHEN_INT0|ADC_INT_EVERY_OTHER);
   setup_spi(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_2); 
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

	setup_power_pwm_pins(PWM_COMPLEMENTARY,PWM_OFF,PWM_OFF,PWM_OFF);
		//PPWM channels 0 and 1 are both on and always opposite values
	setup_power_pwm(PWM_CLOCK_DIV_4|PWM_FREE_RUN,1,0,1023,0,1,0);
		//add dead time for reactive loads



   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);
//   setup_oscillator(False);

initQEI(4);

while(TRUE)
{
currentQEIPos = getQEIPos();
set_power_pwm0_duty(2048);
}



}

driver - under ir2184 and 4 irfp250
motor - Brushed(48V) with 500 pulse encoder


while my PWM duty = 2048 that is 50% PWM -> motor not turning

PWM < 2048 -> left turnig
PWM > 2048 -> right turnig

I must set position target, and target must be = currentQEIPOS
How I can do it (with or without PID, better with PID)

HELP!!!

maybe anybody have link for comlete code PID motion?
 

to to count with qei

Hi,

I suppose you have an H bridge to drive your motor. In this case, if duty cycle is >50% you'll give positive voltage and rotate positively, and vice versa.
If you want to do position control, you can use the encoder and use the difference between desired and actual positions to feed a PI that would give you your duty cycle.
There are different control structures to try, you might want to implement current control or speed control as internal loops to the position one.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top