Code trouble


Closed Thread
Results 1 to 5 of 5

Thread: Code trouble

  1. #1
    Join Date
    Aug 2005
    Location
    Los angeles
    Posts
    39

    Default Code trouble

    Can anyone spot my mistake in this simple program. The program run but it will never go into the wakeup mode. thank you much see below:

    ' this is for pic12f675
    ANSEL=0 ' change pin into digital Input
    CMCON=7
    pulsewidth var word
    counter var word
    looptime con 10000


    pulsin 4,1,pulsewidth ' read the pulse width at pin 4

    for counter=0 to looptime 'loop

    if pulsewidth >150 then gosub switch ' read pulse width again
    if pulsewidth=0 then gosub blink

    pulsin 4,1,pulsewidth
    pause 1
    if counter=looptime-1 then gosub wakeup

    next counter


    switch:
    low 2 'pin 2 becomes ground =20 ohms resistance w ground
    pause 1000
    input 2 ' pin 2 becomes open collector means high impedance
    pause 1000
    counter=0 ' reset the counter
    return

    ' : wake up will do the same thing as the switch function above but only after
    ' the loop times out

    wakeup:
    low 2 'pin 2 becomes ground =20 ohms resistance w ground
    pause 1000
    input 2 ' pin 2 becomes open collector means high impedance
    pause 1000
    counter=0
    return

    blink: ' blink the led
    high 0
    pause 80
    low 0
    pause 80
    counter=0
    return

  2. #2


    Did you find this post helpful? Yes | No

    Default

    I would have to say your problem is using an "IF" statement inside the "FOR...NEXT" loop. Also you do realize the PAUSE 1 = 1mS and not 1s. I also noticed there is not main program loop, do you in fact what the program to stop once it has read the pulse width?

    Code:
    start:
    counter = 0
    
    loop:
    counter = counter + 1
    pulsin 4,1,pulsewidth
    if pulsewidth >150 then
      gosub switch
      endif
    if pulsewidth=0 then 
      gosub blink 
      endif
    pulsin 4,1,pulsewidth
    pause 1
    if counter = (looptime - 1 ) then
      gosub wakeup
      endif
    goto start
    
    switch:
    blah, blah, blah...
    return
    
    blink:
    blah, blah, blah...
    return
    
    wakeup:
    blah, blah, blah...
    return
    Last edited by CocaColaKid; - 24th August 2005 at 01:29.

  3. #3
    Join Date
    Aug 2005
    Location
    Los angeles
    Posts
    39


    Did you find this post helpful? Yes | No

    Angry

    still doesn't work... i don't see what's the problem with mine. the program never gets to wakeup.

  4. #4
    Join Date
    Aug 2005
    Location
    Los angeles
    Posts
    39


    Did you find this post helpful? Yes | No

    Question

    I got it to work...initially i though that the 1ms pause and i am doing a 10000 loop i would get about 10 seconds delay...but it turned out that this is not correct i would get about 56 seconds delay for 2700 loop not sure why it took so long to execute all these functions

  5. #5


    Did you find this post helpful? Yes | No

    Default

    All the other commands require processing time which can certainly add up over these kinds of execution times. I'm sure if you calculate how long each command take to process you will find your time is pretty close if not bang on. Especially is say one command take 1ms to process then you would have added 2.7s to the time right off the bat.

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Microchip MCP41xxx Digital Potentiometer Code Trouble
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 18:21

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