Quite hard program Pic16F88

Thread Starter

aGpLT

Joined Jan 21, 2010
128
Hello everyone, i am trying to write program but it's hard to think how to do this.
Project: Robot arm
Language: PicBasic
Compiler: Picbasic pro 2.54
uC: PIC16F88
Motors: 3
Sensors: 3 opto interrupters
Motor control: 3 relay H-bridges.

Idea: So i have 1 button 3 states (ON-OFF-ON), if its 1 state (ON) then my robot arm goes to manual control. While pushing buttons motors starts and uC must count impulses from each sensor and save information to registers, when i go to off state when nothing, if i go to another ONE state, then robot arm goes to automatic mode. uC must read last information and put robot arm in starting position. ok its quite poor explanation.... i will try showing it in program, but i think i need to use interrupts for 3 state button but i don't know how...


Rich (BB code):
ANSEL = 0   ' set all outputs from analogue to logic
OSCCON = $60    ' set 4 Mhz internal clock
TRISB = %00000000 ' All PortB to outputs
TRISA = %00000111 ' 
'''''''''''''''''''''''''''''''''''''''''
M1 var  PORTB.0     'First motor to right
M1L VAR  PORTB.1    'First motor drive  
M2 VAR  PORTB.2     'Second motor to right
M2L VAR  PORTB.3    'Second motor to left
M3 VAR  PORTB.4     'Third motor to right
M3L VAR  PORTB.5    'Third motor to left
'''''''''''''''''''''''''''''''''''''''''
' Motor Logic                           '
'''''''''''''''''''''''''''''''''''''''''
' M1 - 0                                '
' M1L - 0                               '
' output - 0                            '
' M1 - 1                                '
' M1L - 0                               '
' Output - 1 to right                   '
' M1 - 1                                '
' M1L - 1                               '
' Output - 1 to left                    '
'''''''''''''''''''''''''''''''''''''''''
J1 VAR  PORTA.0 'Sensor 1 for motor1
J2 VAR  PORTA.1 'Sensor 2 for motor2
J3 VAR  PORTA.2 'Sensor 3 for motor3
MYG1 var PORTA.3 '3 state button Manual mode
MYG2 VAR PORTA.4 '3 state button Automatic mode
MYG3 var PORTA.5 '3 state button midle pin of button (5V) from uC
cnt1 var byte 'to count impulses from first sensor
cnt2 var byte 'to count impulses from second sensor
cnt3 var byte 'to count impulses from third sensor
'STARTING PROGRAM'
PORTA = 0        '
PORTB = 0        '
cnt1 = 0         '
cnt2 = 0         '
cnt3 = 0         '
''''''''''''''''''
Begin:
    HIGH MYG3
    if MYG1 = 1 then manual
    IF MYG2 = 2 THEN automatic
    goto begin
'MANUAL MODE'
manual:
    if J1 = 1 then
        cnt1 = cnt1+1
            while J1 = 1
        wend
    endif
    if J2 = 1 then
        cnt2 = cnt2+1
            while J2 = 1
        wend
    endif
    if J3 = 1 then
        cnt3 = cnt3+1
            while J3 = 1
        wend
    endif
    if myg = 1 then manual
    goto begin
 'AUTOMATIC MODE'
 automatic:
    if cnt1 > 0 then motor1
    if cnt2 > 0 then motor2
    if cnt3 > 0 then motor3
    
 motor1:
i don't know how to read value and make motors go to starting position :| If someone could help me it would be very nice. also i know that my language is quite poor, so if you don't understand what i wanted to say just say it. i will try explain it more in details, it would be helpful if you could ask concrete questions it's easier to answer them.
 
Top