Quite hard program Pic16F88

Discussion in 'Programmer's Corner' started by aGpLT, Jun 8, 2010.

  1. aGpLT

    Thread Starter Member

    Jan 21, 2010
    128
    0
    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...


    Code ( (Unknown Language)):
    1.  
    2. ANSEL = 0   ' set all outputs from analogue to logic
    3. OSCCON = $60    ' set 4 Mhz internal clock
    4. TRISB = %00000000 ' All PortB to outputs
    5. TRISA = %00000111 '
    6. '''''''''''''''''''''''''''''''''''''''''
    7. M1 var  PORTB.0     'First motor to right
    8. M1L VAR  PORTB.1    'First motor drive  
    9. M2 VAR  PORTB.2     'Second motor to right
    10. M2L VAR  PORTB.3    'Second motor to left
    11. M3 VAR  PORTB.4     'Third motor to right
    12. M3L VAR  PORTB.5    'Third motor to left
    13. '''''''''''''''''''''''''''''''''''''''''
    14. ' Motor Logic                           '
    15. '''''''''''''''''''''''''''''''''''''''''
    16. ' M1 - 0                                '
    17. ' M1L - 0                               '
    18. ' output - 0                            '
    19. ' M1 - 1                                '
    20. ' M1L - 0                               '
    21. ' Output - 1 to right                   '
    22. ' M1 - 1                                '
    23. ' M1L - 1                               '
    24. ' Output - 1 to left                    '
    25. '''''''''''''''''''''''''''''''''''''''''
    26. J1 VAR  PORTA.0 'Sensor 1 for motor1
    27. J2 VAR  PORTA.1 'Sensor 2 for motor2
    28. J3 VAR  PORTA.2 'Sensor 3 for motor3
    29. MYG1 var PORTA.3 '3 state button Manual mode
    30. MYG2 VAR PORTA.4 '3 state button Automatic mode
    31. MYG3 var PORTA.5 '3 state button midle pin of button (5V) from uC
    32. cnt1 var byte 'to count impulses from first sensor
    33. cnt2 var byte 'to count impulses from second sensor
    34. cnt3 var byte 'to count impulses from third sensor
    35. 'STARTING PROGRAM'
    36. PORTA = 0        '
    37. PORTB = 0        '
    38. cnt1 = 0         '
    39. cnt2 = 0         '
    40. cnt3 = 0         '
    41. ''''''''''''''''''
    42. Begin:
    43.     HIGH MYG3
    44.     if MYG1 = 1 then manual
    45.     IF MYG2 = 2 THEN automatic
    46.     goto begin
    47. 'MANUAL MODE'
    48. manual:
    49.     if J1 = 1 then
    50.         cnt1 = cnt1+1
    51.             while J1 = 1
    52.         wend
    53.     endif
    54.     if J2 = 1 then
    55.         cnt2 = cnt2+1
    56.             while J2 = 1
    57.         wend
    58.     endif
    59.     if J3 = 1 then
    60.         cnt3 = cnt3+1
    61.             while J3 = 1
    62.         wend
    63.     endif
    64.     if myg = 1 then manual
    65.     goto begin
    66.  'AUTOMATIC MODE'
    67.  automatic:
    68.     if cnt1 > 0 then motor1
    69.     if cnt2 > 0 then motor2
    70.     if cnt3 > 0 then motor3
    71.    
    72.  motor1:
    73.      
    74.  
    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.
     
  2. aGpLT

    Thread Starter Member

    Jan 21, 2010
    128
    0
    Sorry for double thread, network issues made me make this mistake :(
     
  3. Harrington

    New Member

    Dec 19, 2009
    86
    3
Loading...