asharan/necec/presentation_v3.…  · web viewmicrocontroller based manufacturing, robot and...

25
AUTOMATED MANUFACTURING IN REMOTE AREAS USING MICRO-CONTROLLERS BY PUNIT ANAND GRADUATE STUDENT FACULTY OF BUSINESS ADMINISTRATION McMASTER UNIVERSITY HAMILTON, ONTARIO, CANADA E-MAIL: [email protected] AND ANAND M. SHARAN PROFESSOR MECHANICAL ENGINEERING MEMORIAL UNIVERSITY OF NEWFOUNDLAND, ST JOHN’SNEWFOUNDLAND, CANADA A1B 3X5 E-MAIL: [email protected] 1

Upload: phungkhue

Post on 30-Jan-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

AUTOMATED MANUFACTURING IN REMOTE AREAS USING MICRO-CONTROLLERS

BY

PUNIT ANAND

GRADUATE STUDENTFACULTY OF BUSINESS ADMINISTRATION

McMASTER UNIVERSITYHAMILTON, ONTARIO, CANADAE-MAIL: [email protected]

AND

ANAND M. SHARAN

PROFESSOR MECHANICAL ENGINEERING

MEMORIAL UNIVERSITY OF NEWFOUNDLAND, ST JOHN’SNEWFOUNDLAND, CANADA A1B 3X5

E-MAIL: [email protected]

1

Page 2: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

ABSTRACT

To achieve economical production, automation using micro-

controllers have been used.

This is carried out by mounting a frame for weaving a pattern

on the end effector of an X-Y robot. The robot operates in

conjunction with a sewing machine.

The energy for driving these dc motor powered machines is

obtained using photo-voltaic panels.

The co-ordinated motions for the robot and sewing machine

are obtained by programming a controller in mikrobasic

language.

KEYWORDS: Robots in manufacturing, Microcontroller based manufacturing, Robot and machines having co-ordinated motions.

1. INTRODUCTION

2

Page 3: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

In vast areas of the world, economical manufacturing in rural areas has become a necessity as the cities are becoming over-crowded.

This requires introduction of high-tech industries to be located in such areas. Quite often, such places require introduction of low cost machines due to the shortage of capital in these areas.

For an example, stitching / weaving type of industries require very small amount of power but are labour intensive.

To reduce the cost – automation and mechanization is needed even here because hand-made products of matching quality are difficult to be produced economically in large quantities since the probability of error is there in every piece made.

Secondly, if we introduce robots, they can make many more variety of products than earlier generation of machines like existing lathes and milling machines with human operators .

This paper deals with programming a microcontroller to make a pattern using a sewing machine. The microcontroller is used to

3

Page 4: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

provide motions to an X-Y or Cartesian robot as well as to a sewing machine as shown in Fig. 1.

FIG. 1 MOTION TO EMBROIDERY FRAME BEING PROVIDED BY X-Y MOTION

ROBOT

2. ILLUSTRATION OF DEVICES FOR AUTOMATED MANUFACTURING

Fig 2 shows an arrangement where on a fabric, a geometrical shape has to be weaved (made).

FIG. 2 BATTERY BEING CHARGED BY A SOLAR PANEL

4

Page 5: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

To have co-ordinated motion in the X, Y and Z directions, one uses micro-controller shown in Fig. 3.

FIG. 3 USE OF MICRO-CONTROLLER TO PROVIDE MOTION CONTROL

Here two Pulse Width Modulated (PWM) signals are generated and

sent to two respective H-Bridges (Fig. 4) corresponding to X and Y

motions. The third motion, that of the needle along the Z direction,

is given by motor 3.

FIG. 4 THREE DC MOTORS CONTROLLED BY MICRO-CONTROLLER THROUGH

H BRIDGES

5

Page 6: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

These H Bridges are switching devices which open the high current

gates using MOSFETs. The signals generated by micro-controllers

in Fig. 3 can drive the two dc motors shown in Figs 1, and 2 using

these H Bridges.

3. PROGRAMMING A MICRO-CONTROLLER

A computer program written in MikroBasic was used to drive the motors in Fig. 5.

6

Page 7: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

The program was written for making embroidery of circular shape as shown in Fig. 5.

This figure shows a circle whose equation was obtained using a Fourier series.

The Fourier coefficients were obtained using Fast Fourier Transform subroutine in MATLAB software

These coefficients were stored in the memory of the controller.

The pattern to be weaved was carried out in a sequential manner where a vertical line of variable length (1) was stitched followed by a very small horizontal line of fixed length(2) and then, again a vertical line(3) and so on.

7

Page 8: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

Clearly, the end points of the vertical line were computed using Fourier coefficients on line.

The associated computer program was written by referring to [9].

The chip used was Pic 18F45K22 which was mounted on an Easy Pic V7 Development Board. The experimental set up is shown in Fig. 7.

Using these principles, one can introduce automation in rural and remote areas where one can manufacture other parts or products at reduced cost and of far better quality than what is being done presently.

8

Page 9: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

4 CONCLUSIONS

In this paper, a methodology was presented to introduce automation in rural and remote areas.

By the introduction of micro-processors, these automated machines can be manufactured in rural areas, as well as such machines can be used to manufacture products.

By introduction of automation, people will find employment in villages and it will reverse the migration to cities for better life.

5 ACKNOWLEDGEMENTS

The author is thankful to Dr M. J. Hinchey, for his generous help in building hardware for controller.

The author is also indebted to Dr. T. Iqbal for valuable assistance in course of this research.

9

Page 10: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

6 REFERENCES

1. Ostwald , P.F., Amstead, B. H., and Begeman, M. L., “Manufacturing Processes” , 7th Edition, John Wiley and Sons, Toronto, Canada , pp 450-466.

2. Sharan, A.M. , and Prateek, M. , 2006, “ Automation of Minimum Torque Based Accurate Solar Tracking Systems Using Microprocessors “ 86, Sept – Oct. , pp . 415 - 437 Journal of Indian Institute of Science

3. Craig, J.,J.,” Introduction to Robotics, and Control”, 3rd Edition, Prentice Hall, New Jersey, USA, pp 62-92.

4. Klafter, R. A., Chmielewski, T.A., and Negin, M, “Robotic Engineering: An Integrated Approach”, 1989 Edition. Prentice Hall, New Jersey, USA, pp 58-70.

5. Guru, B.,S., and Hiziroglu, H.,R., “Electric Machinery and Transformers “,Third Edition, BJS Publishers, New York, USA, pp 201-244 ; 421-428

6. Sewing Machines, http://en.wikipedia.org/wiki/Sewing_machine7. MOSFET, http://en.wikipedia.org/wiki/MOSFET8. Fourier Analysis of Time Series,

http://people.uncw.edu/hermanr/signals/Notes/Signals.htm9. Mazidi, M.,A., Mazidi, J., G., and McKinlay, R., D.,” The 8051 Microcontroller and

Embedded Systems “, 2nd Edition, Prentice Hallm , New Jersey, USA, pp 153-178.

PROGRAM

'-------------------------------------------------------------------------------' FULL CIRCLE FILLUP'-------------------------------------------------------------------------------'PIK 18F45K22 on Easy Pic V7 Development Board; mikroBasic Pro for PIC V6.0.0' External 8 MHZ Oscillator

' Config Parameters' Oscillator Frequency = 8 MHZ' Oscillator Selection = HS Oscillator (medium power 4 -16 MHZ)' 4X PLL Enable = Disabled' Fail - Safe Clock Monitor Enabled' Internal / External Oscillator Switchover = Enabled' Power-up Timer = Enabled' Brown-Out Reset = "Brown - Out Reset enabled in Hardware only (SBOREN is disabled)' Brown out Reset Voltage = "VBOR set to 1.90 V nominal"' Watch Dog Timer = Disabled' Watchdog Timer Postscale = 1:32768' CCP2 MUX bit = CCP2 input/output is multiplexed with RC1

10

Page 11: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

' PORTB A/D = Enabled' P3A/CCP3 Mux bit = P3A/CCP3 input/output is multiplexed with RB5' HFINTOSC Fast Start-up = Enabled' Timer3 Clock input mux = T3CK1 is on RC0' ECCP2 B Output mux = P2B is on RD2' MCLR PIN = MCLR pin enabled, RE3 input pin disabled' Stack Full/ UnderFlow Reset = Enabled' Low Voltage Program = Disabled' Extended Instruction Set = Disabled' Background Debug = Disabled' Code Protection Block 0 = Block 0 not Code Protected' Code Protection Block 1 = Block 1 not Code Protected' Code Protection Block 2 = Block 2 not Code Protected' Code Protection Block 3 = Block 3 not Code Protected' Boot Block Code Protection = Disabled' Data EEPROM Code Protection = Disabled' Write Protection Block 0 = Disabled' Write Protection Block 1 = Disabled' Write Protection Block 2 = Disabled' Write Protection Block 3 = Disabled' Configuration Register Write Protection = Disabled' Boot Block Write Protection = Disabled' Data EEPROM Write Protection = Disabled' Table Read Protection Block 0 = Disabled' Table Read Protection Block 1 = Disabled' Table Read Protection Block 2 = Disabled' Table Read Protection Block 3 = Disabled' Boot Block Table Read Protection = Disabled

program MotorControl

' Global Declarations section

' PWM at 80% duty cycle is required to move by 1 resolution in +ve dir &' PWM at 20% duty cycle is required to move by 1 resolution in -ve dir' Number of PWM waves required to move the motor by a minimum X,Y Resolution const motor_res_x as longint = 100 const motor_res_y as longint = 100

' minimum resolution in mm const res_x_mm as float = 1.0 const res_y_mm as float = 1.0 'PIC18F45K22 running at 8 MHZ ' PWM Timer to be at 500 HZ ' Timer0 is running at (8 Mhz/4) * (1/256), i.e 7812.5 HZ ' Therefore Timer0 multiple is 7812.5 / 500 = 15.625 const frequencymult as float =15.625

11

Page 12: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

'const frequencymult as float =4000 const timerscale as float =1.0

const Constword as word = 0xFFFF ' global variables that always contain position vectors of the frame dim xpos as float dim ypos as float 'counter dim cnt as word

'--------------Timer Interrupt handling--------------- 'This program uses TMR0L as a counter and when the register overflows it 'interrupts. This interrupt is used to generate PWM 'sub procedure Timer0_Interrupt iv 0x000008 ics ICS_AUTO 'sub procedure interrupt_low sub procedure interrupt 'IF INTCON.TMR0IF =1 Then TMR0H=0 TMR0L=0 'TMR set to initial value of 0 'INTCON.=0x20 'Interrupt control register only TMR0 overflow interrupt enabled 'INTCON.GIE=1 'INTCON.PEIE=1 'INTCON.TMR0IE=1 'INTCON.INT0IE=0 'INTCON.RBIE=0 INTCON.TMR0IF=0 'INTCON.INT0IF=0 'INTCON.RBIF=0

cnt = cnt +1 ' Counter incremented 'end if end sub

sub function AbsoluteValueFloat(dim abspara as float) as floatIF abspara <0THENresult = -absparaelseresult = absparaend ifend sub '--------------MoveX_pos--------------- 'This subroutine moves the frame so that the needle is at xnew coordinate 'The exact number of PWM pulses are provided to the X motor to position the

12

Page 13: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

' frame exactly below the needle. Position xnew in mm; ' PWM1 is used for generating pulse. For PIC18F45K22 its RC2 (port c 3rd bit) ' which for 40pin DIP is pin #17 sub Procedure MoveX_pos(dim xnew as float)'local declarationdim xmove, xtemp as floatdim pwm_time as worddim cnt_limit as worddim cnt_start as word'dim xtimerhi, xtimerlo as byte

'Delta movement computationxtemp = xnew - xposxmove = xtemp / res_x_mm

' compute the # of PWM required to reach X position'pwm_time = integer((AbsoluteValueFloat(xmove) * motor_res_x)/timerscale)pwm_time = integer((AbsoluteValueFloat(xmove) * motor_res_x * frequencymult)/timerscale)cnt_limit =1

' By default it is set to cnt_limit setupIF pwm_time > Constword thencnt_limit = 1+ (pwm_time div Constword)cnt_start = pwm_time - Constword*(cnt_limit-1)elsecnt_limit =1cnt_start = Constword - pwm_timeend if

cnt =0

'Duty cycle set on the choice of directionIF xmove >0 THENPWM1_Set_Duty (204) 'function takes only values in byte, 204 is 80% duty cycle'INTCON = 0xA0 'Interrupt control register Global interrupt & TMR0 overflow enabelsePWM1_Set_Duty (51) 'function takes only values in byte, 51 is 20% duty cycle'INTCON = 0xA0 'Interrupt control register Global interrupt & TMR0 overflow enabend if'TMR0L Loaded

'T0CON.7=0'xtimerhi = Hi(cnt_start)'xtimerlo = Lo(cnt_start)

13

Page 14: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

'TMR0H = xtimerhi'TMR0L = xtimerlo'T0CON.7=0TMR0H = Hi(cnt_start)TMR0L = Lo(cnt_start)T0CON.TMR0ON =1' loop until timer overflow interruptdoloop until cnt = cnt_limit'delay_ms(500)PWM1_Set_Duty (127)'PWM1_Stop()

cnt=0xpos = xnew ' New xpositionT0CON.TMR0ON =0end sub '--------------MoveX_pos_delta--------------- ' Move the motor by the smallest possible amoount in positive x directionsub Procedure MoveX_pos_deltadim posdelta as floatposdelta = xpos + res_x_mmMoveX_pos(posdelta)'MoveX_pos(xpos + res_x_mm)end sub

'--------------MoveX_neg_delta--------------- ' Move the motor by the smallest possible amoount in positive x directionsub Procedure MoveX_neg_deltadim negdelta as floatnegdelta = xpos - res_x_mmMoveX_pos(negdelta)'MoveX_pos(xpos - res_x_mm)end sub

'--------------MoveY_pos--------------- 'This subroutine moves the frame so that the needle is at ynew coordinate 'The exact number of PWM pulses are provided to the Y motor to position the ' frame exactly below the needle. Position ynew in mm; ' PWM2 is used for generating pulse. For PIC18F45K22 its RC1 (port c 2nd bit) ' which for 40pin DIP is pin #16

14

Page 15: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

sub Procedure MoveY_pos(dim ynew as float)'local declarationdim ytemp, ymove as floatdim pwm_time_y as worddim cnt_limit_y as worddim cnt_start_y as word

' xmove'Delta movement computationytemp = ynew - ypos'Motor direction control to be determined by xmove

ymove = ytemp / res_y_mm' compute the # of PWM required to reach X position'pwm_time = integer((AbsoluteValueFloat(ymove) * motor_res_y)/timerscale)pwm_time_y = integer((AbsoluteValueFloat(ymove) * motor_res_y * frequencymult)/timerscale)cnt_limit_y =1' By default it is set to cnt_limit setup

IF pwm_time_y >Constword thencnt_limit_y = 1+ (pwm_time_y div Constword)cnt_start_y = pwm_time_y - Constword*(cnt_limit_y-1)elsecnt_limit_y =1cnt_start_y = Constword - pwm_time_yend ifcnt =0

TMR0H = Hi(cnt_start_y)TMR0L = Lo(cnt_start_y)T0CON.TMR0ON =1

'PWM2_Init(488)'PWM2_Start()IF ymove >0 THENPWM2_Set_Duty (204) 'function takes only values in byte, 204 is 80% duty cycle'INTCON = 0xA0 'Interrupt control register Global interrupt & TMR0 overflow enab elsePWM2_Set_Duty (51) 'function takes only values in byte, 51 is 20% duty cycle'INTCON = 0xA0 'Interrupt control register Global interrupt & TMR0 overflow enab end if

' TMR0H & TMR0L Loaded

' Loop until timer overflows

15

Page 16: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

do loop until cnt = cnt_limit_y

'delay_ms(500) PWM2_Set_Duty (127)'PWM2_Stop()

cnt=0ypos = ynewT0CON.TMR0ON =0

end sub '--------------MoveY_pos_delta--------------- ' Move the motor by the smallest possible amount in positive y direction

sub Procedure MoveY_pos_deltadim posdelta as floatposdelta = ypos + res_y_mmMoveY_pos(posdelta)end sub

'--------------MoveY_neg_delta---------------' Move the motor by the smallest possible amount in negative y direction

sub Procedure MoveY_neg_deltadim negdelta as floatnegdelta = ypos - res_y_mmMoveY_pos(negdelta)end sub

' 6th bit of Port C RC5, 24th pin of 40 DPI is 1sub procedure NeedleOn()PORTC.5 = 1 'RC5 or the 6th bit 1 for needle motor to switch onend sub

sub procedure NeedleOff()PORTC.5 = 0 'RC5 or the 6th bit 0 for needle motor to switch offend sub

'----------WEAVE OPERATION UP TO DOWN -------------' yup and ydown as integersub procedure WeaveYUpDown(dim yp,yn as float)' Local Declarationdim forcounter, PDtemp as integer

'PORTC = 0 ' PORT C =0'TRISC = 0 ' Set Port C as output

16

Page 17: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

PDtemp = integer((yp - yn) / res_y_mm ) + 1'Move the needle to Yup positionIF ypos = yp thenelseMoveY_pos (yp)end if

'switch on the needle'NeedleOn()

' Y to be moved by the y resolutionFor forcounter = 1 to PDtemp step 1MoveY_neg_delta()next forcounter

'switch off the needle'NeedleOff()end sub

'----------WEAVE OPERATION DOWN TO UP -------------' yup and ydown as integer

sub procedure WeaveYDownUP(dim yplus,yminus as float)' Local Declarationdim forcounter, DPtemp as integer

'PORTC = 0 ' PORT C =0'TRISC = 0 ' Set Port C as outputDPtemp = integer((yplus - yminus) / res_y_mm) + 1

'Move the needle to Ydown positionIF ypos = yminus thenelseMoveY_pos (yminus)end if' Switch on the needle'NeedleOn()

For forcounter = 1 to DPtemp step 1MoveY_pos_delta()next forcounter

' Switch off the needle'NeedleOff()end sub

'In order to weave a circle, fourier series is employed.'--------------------------Fourier Part begins--------------------------'sub function GetYup(dim i,N as integer) as floatdim A0,A1,A2 as floatdim B0,B1,B2 as float

17

Page 18: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

dim compT0,compT1,compT2,compT3,compT4 as floatA0 = 7.0554A1 = -0.5140A2 = 0.0013B0 = 0.0B1 = 0.0294B2 = 0.0010'get y location'i dont know how to do arrays in basic, so doing individually

compT0 = A0/2compT1 = A1*cos(2*PI*i/N)compT2 = B1*sin(2*PI*i/N)compT3 = A2*cos(2*PI*2*i/N)compT4 = B2*sin(2*PI*2*i/N)

IF i=0 THENresult = compT0elseresult = compT0+compT1+compT2+compT3+compT4end if

end sub

sub function GetYdown(dim i,N as integer) as floatdim ymin, ytmp as floatymin = 3.0ytmp = GetYup(i,N)

result = (2*ymin) - ytmpend sub

'--------------------------Fourier Part ends--------------------------' main:' Main program' assume that you have to start weaving at X initial positiondim N,i,j as integerdim yup as floatdim ydown as floatdim xinitial as floatyup =0.0ydown =0.0xinitial = 10.0N = 144 ' initial values

xpos=0.0 ypos=0.0 cnt =0'Configuring AN PINS as Digital I/O'ANSEL =0ANSELC = 0TRISC = 0 ' Set Port C as output

18

Page 19: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

PORTC = 0 ' PORT C =0

'Selecting Frequency to be 31.25KHZ Internal source

' OSCOCN2 Register Oscillator Control Register 2' PLLRDY; SOSCRUN; Unimplemented; MFIOSEL; SOSCGO;PRISD;MFIOFS;LFIOFS'OSCCON2 =%01000101

'OSCTUNE Register'INTSRC; PLLEN; TUN <5:0>'OSCTUNE =%00100000

'OSCCON Register'IDLEN; IRCF <2:0>, OSTC; HFINTOSC; SCS <1:0>'OSCCON =%00000010

'T0CON Timer0 Control Register 8 bits are TMR0ON, T08BIT, T0CS, T0SE, PSA,' TOPS <2:0>, 16 bit timer with 1:16 prescale vale' TMR0ON, T08BIT, TOPS (100) (1/4 * 1/256) 1:1024 frequency value

'T0CON.TMR0ON =0 'Timer Stopped'T0CON.T08BIT =0 '16 Bit Timer Mode'T0CON.T0CS =0 'Use System Clock to Increment Timer'T0CON.T0SE =0'T0CON.PSA =0 'Use Prescaler to Timer0'T0CON.TOPS2 =1 'Use 1:256 prescaler'T0CON.TOPS1 =1'T0CON.TOPS0 =1T0CON = %00000111'T0CON = %00001000TMR0H=0TMR0L=0 'TMR set to initial value of 0'Intcon Register 8 bits are GIE/GIEH; PEIE/GIEL; TMR01E; INT01E; RBIE; TMR01F;' INT01F; RBIF

RCON.IPEN=0

'RCON.IPEN=1'INTCON2.TMR0IP=1

INTCON.GIE=1INTCON.PEIE=1INTCON.TMR0IE=1INTCON.INT0IE=0INTCON.RBIE=0INTCON.TMR0IF=0INTCON.INT0IF=0INTCON.RBIF=0'INTCON=0xA0 enable interrupt TMR0

'TxCon Timer 1/3/5'TMRxCS<1:0>; TxCKPS<1:0>; TxSOSCEN; TxSYNC;TxRD16;TMRxON

19

Page 20: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

'TMRxCS =00 instruction cycyle (1/4); TxCKPS<1:0>=11 (1/8)'T1CON=%00110101'T3CON=%00110101

'TxCON, Timer 2/4/6'Unimplemented; TxOutps postcaler <3:0> ; TMRxON; TXCKPS (prescaler)

PR2 = %11111001T2CON = %00000111CCPR1L = %01111100CCP1CON = %00111100

' With this LF Stable Oscillator at 31.25 KHZ is chosen as the primary clock' driving Timer0, Timer2 at prescale value of 1/64;' PWM will be generated at frequency 488.28 Hz'PWM1_Init(488)'PWM2_Init(488)'PWM1_Init(500)'PWM2_Init(500)PWM1_Start()PWM2_Start()PWM1_Set_Duty (127)PWM2_Set_Duty (127)

MoveX_pos (xinitial)j=0PORTC = 0 ' PORT C =0TRISC = 0 ' Set Port C as outputNeedleOn()for i = 0 to N step 2IF i =0 thenyup = GetYup(i,N)elseyup = GetYup(j,N)end ifydown = GetYdown(i,N)WeaveYUpDown(yup,ydown)'WeaveYUpDown(yup,6.0-yup)j = i+1'delay_ms(1000)MoveX_pos_delta'delay_ms(1000)yup = GetYup(j,N)ydown = GetYdown(i,N)WeaveYDownUp(yup,ydown)'WeaveYDownUp(yup,6.0 - yup)MoveX_pos_deltanext iPWM1_Stop()

20

Page 21: asharan/NECEC/PRESENTATION_V3.…  · Web viewMicrocontroller based manufacturing, Robot and machines . having co ... as word = 0xFFFF ' global. variables that always contain position

PWM2_Stop()

NeedleOff()end.

21