16F628 problem


Closed Thread
Results 1 to 2 of 2

Thread: 16F628 problem

  1. #1
    Join Date
    Mar 2005
    Posts
    7

    Angry 16F628 problem

    Hi, I just built an infrared robot using the 16F628's PWM module to activate the IR LEDs. The 2 IR LEDs are placed on either side of an IR receiver. I used 2 servos to make it move. I'm using 4 AA batteries for power. At first I couldn't get the servos to change direction, so I added a 1000uF capacitor between vdd and ground. Then it started working. Now, here is the new problem. When the robot encounters a wall, (lets just say the wall is on the robot's right side) it doesn't turn long enough to get away from the wall. As a result the robot ends up nearly parallel to the wall. I figured that I should add a "For...Next" statement to make the turning period longer. However, I just cannot get it to work! I have no idea what i'm doing wrong. Here, look at my program.
    Symbol cmcon = $1F
    Symbol ccp1con = $17
    Symbol ccpr1l = $15
    Symbol pr2 = $92
    Symbol t2con = $12
    Symbol trisb = 134
    Symbol portb = 6
    Poke cmcon, 7
    Poke ccpr1l, 5 ' duty cycle to 20%
    Poke pr2, 25 ' PWM to 38.4kHz
    Poke t2con, 4
    Poke trisb, 4
    Low 6 ' this is the left servo
    Low 7 ' this is the right servo
    main:
    B0 = 0
    B3 = 0
    B4 = 0
    Poke ccp1con, 12
    Low 0 ' this turns on right IR LED
    High 1 ' this turns off left IR LED
    Pause 1
    Peek portb, B0 ' this finds value of IR receiver output
    IF bit2 = 0 Then setleft ' 0 = something detected, 1 = nothing
    B1 = 1
    GoTo here1
    setleft:
    B1 = 0
    here1:
    High 0
    Low 1
    Pause 1
    Peek portb, B0
    IF bit2 = 0 Then setright
    B2 = 1
    GoTo here2
    setright:
    B2 = 0
    here2:
    High 0
    High 1
    Poke ccp1con, 0
    IF B1 = 1 AND B2 = 1 Then forward ' nothing there
    IF B1 = 0 AND B2 = 1 Then left ' something on right side
    IF B1 = 1 AND B2 = 0 Then right ' something on left side
    IF B1 = 0 AND B2 = 0 Then backward ' both
    forward:
    B3 = 200
    B4 = 100
    GoTo pulse
    left:
    High 5 ' turn on indicator LED
    B3 = 100
    B4 = 100
    GoTo pulse
    right:
    High 4 ' turn on indicator LED
    B3 = 200
    B4 = 200
    GoTo pulse
    backward:
    High 4 ' turn on indicator LED
    High 5 ' turn on indicator LED
    B3 = 100
    B4 = 200
    GoTo pulse
    pulse: ' WHY WON'T THIS PART WORK?
    B5 = 0 ' it never goes longer that a single pulse
    For B5 = 0 to 10
    PulsOut 6, B3
    PulsOut 7, B4
    Pause 20
    Next B5
    Low 4
    Low 5
    GoTo main

    Please help.
    Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    Wichita KS
    Posts
    511


    Did you find this post helpful? Yes | No

    Default

    Hello Brown,

    Brown>>
    B5 = 0 ' it never goes longer that a single pulse
    For B5 = 0 to 10
    PulsOut 6, B3
    PulsOut 7, B4
    Pause 20
    Next B5
    Low 4
    Low 5
    <<

    A couple of things to look at..

    1. the Pause 20... change it to a higher value... 20 milliseconds is only 1 50th of a second. pretty short time to turn. maybe you want something like 200 or 300. for a pause. That is 1/5 of a second. I see that you try to adjust the timeing to 200 mils with the pause 20 and counter. Since I do not know how your setup is.... I am assuming you want a little longer of a pulse. Thus, I would do something a little different....like the following....You will have a hard time convincing me that only a single pulse is happening... I think all your pulses are happening, just way to quick for your project to react the way you want.

    B5 = 0 ' it never goes longer that a single pulse
    For B6= 0 to 10
    For B5 = 0 to 60 'change this value and see what happens....200?
    PulsOut 6, B3
    PulsOut 7, B4
    Pause 1
    Next B5
    Pause 20
    NEXT B6.
    Low 4
    Low 5


    Dwayne
    Ability to Fly:
    Hurling yourself towards the ground, and missing.

    Engineers that Contribute to flying:
    Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute

    Pilots that are Flying:
    Those who know their limitations, and respect the green side of the grass...

Similar Threads

  1. LCD problem with 16F628
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 19th September 2016, 08:28
  2. Replies: 3
    Last Post: - 12th February 2007, 18:32
  3. Wavecom with 16F628 communication problem
    By ericbeaugiuet in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd June 2006, 11:05
  4. RS232 with 16F628 problem
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th June 2005, 03:19
  5. 16F628 on-chip eeprom problem
    By atomski in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 4th March 2004, 07:43

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts