12F683 - basic code not working


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default 12F683 - basic code not working

    Hi Guys,

    Playing about with a 12F863 chip for a small project, but to start with thought I would do the basic LEDs flash to ensure programming and that the PIC runs. The code compiled, and ran, flashing the LED on RA0 (on the EasyPIC5 board, which corresponds to GPIO.0). I then added a simple "if then" statement so that if a switch was pressed taking GPIO.1 low the code would jump to the section to flash the LED. But when compiled and loaded to the chip the LED still continues to flash regardless if the switch is pressed or not. I've enabled the pull up on the development board which has no effect

    Code:
    ASM
     __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    endasm
    
    TRISIO = %11111110
    ANSEL = 0   		
    GPIO.0 = 0
    CMCON0=7
    
    Motor var GPIO.0
    Switch1 var GPIO.1
    Switch2 var GPIO.2
    
    main:
    If Switch1 = 0 then 
    goto demo
    else 
    goto main
    
    demo:
    high Motor
    pause 1000
    low Motor
    pause 1000
    goto main
    endif
    Goto main
    Any ideas why ?

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Interestingly this works

    Code:
    ASM
     __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    endasm
    
    TRISIO = %11111110
    ANSEL = 0   		
    GPIO.0 = 0
    CMCON0=7
    
    Motor var GPIO.0
    Switch1 var GPIO.1
    Switch2 var GPIO.2
    
    main:
    If Switch1 = 1 then 
    gosub demo
    endif 
    goto main
    
    demo:
    high Motor
    pause 1000
    low Motor
    pause 1000
    goto main
    REturn

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Hi, Malc

    I would have written ...

    Code:
    ASM
     __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    endasm
    
    TRISIO = %00111110
    ANSEL = 0           
    GPIO.0 = 0
    CMCON0=7
    
    Motor var GPIO.0
    Switch1 var GPIO.1
    Switch2 var GPIO.2
    
    main:
    
    If !Switch1 then 
    
    demo:
      high Motor
      pause 1000
      low Motor
      pause 1000
    endif
    
    goto main
    but it's just me ...

    at least, your "endif" should be placed just before the " demo " label ...

    cause the " IF " condition never sees the " ENDIF " condition reset ....

    tadaaaaaa ...

    Alain
    Last edited by Acetronics2; - 14th January 2014 at 20:58.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    I'm assuming your using PBP3 and to do configs you need to do them like this and both "config" lines need to be in caps. I know PBP2.6 was different but with either version both "config" lines need to be in caps.

    #CONFIG
    ;configuration directives in Assembly Language
    #ENDCONFIG

    TRISIO on the 12F683 is only 6 bits wide so I'm wondering if you need to change it to TRISIO = %111110. I think when you set the TRISIO and the GPIO as input and low respectively you'll always have a low at GPIO.0. When you set the pin low and told it to wait for a low it did what you told it to do. That is go to the demo subroutine. Since you changed it to =1 you had a state change and the chip could sense that. The reply by Acetronics2 did that by using the ! sign.

    Your second take on the subroutine and endif look better.

    As usual I'll await for someone to tell I'm wrong.

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Quote Originally Posted by AvionicsMaster1 View Post
    I'm assuming your using PBP3 .
    Sorry, wrong assumption - using 2.60

    Quick question and slightly off topic, but related to this project... I'm using an H-bridge to control the motor as I need it to be bi-directional. I've been experimenting with some NPN and PNP transistors that I had in my hobby box, BC639 and BC640 and have had a small low current motor running from the PIC. However the actual motor I will be using is a 540 type with a 6:1 gearing. Even though it will be running from a 3v supply (separate to the 5v pic supply) my guess is that the current might be too high for the BC639 / 640 transistors. Can anyone advise if using these transistors would be OK for such a motor, or should I use something like the TIP220 transistors ??
    Attached Images Attached Images  

  6. #6
    Join Date
    Dec 2012
    Location
    Tennessee
    Posts
    262


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    I would use FET's, or a L298 chip. the 298 works great. the FET's i use are a bit overkill for what your doing but you can get lower values.
    some that work well for all hobby motors from the old style that were in tape decks to modern RC racecars is
    RFP12N10L
    IRF540
    IRF9530
    Chris


    Any man who has accomplished anything in electronics at one time or another has said... " STOP! WAIT! NOOO! Dangit.... Oh Well, Time to start over..."

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Following suggestions I've ordered a module from e-bay based on an L298N controller, which should work as under testing the 540 motor was drawing 0.7A and these things are rated at 2A.

    I'm now working on the light detection side of the circuit. Basically the idea is to automatically open a door at dawn (wife now keeps chickens !). So when the light level reaches or exceeds a threshold, the motor runs, opening the door until the door hits a micro switch which then changes a pin status which then turns off the motor.

    I've purchased a 16k-33K LDR from Maplin ( http://www.maplin.co.uk/p/16k-33k-oh...resistor-n57ay ) and connected that from the 5v line to GPIO.0 and covering the LDR makes the associated LED on my development board go out, and increase in brightness due to ambient light or when a bright torch is shon on the LDR. So the resistance is varying based on the light level, so far so good. Now the issue I'm having is that having set the ACD to 8 bits this should give me a 0 - 254 range of values... but in testing to get the motor to run at various values, these are not what I would expect.

    Here's the test code:

    Code:
    ASM
     __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF 
    endasm
    
    ' Hardware configuration
    ' ======================
    
    
    
    TRISIO = %001111 
    ADCON0 = %10000001 
    ANSEL = %00110011 
    DEFINE ADC_BITS 8
    DEFINE ADC_SAMPLEUS 50 
    CMCON0=7
    
    Motor1 var GPIO.4
    Motor2 var GPIO.5
    ADChannel0 var word
    
    GPIO = 0 ' clear all output
    Pause 50 ' internal oscillator settle time
    
    main:
    low Motor1
    low Motor2
    adcin 0,adchannel0 ' Read AN0
    
    If adchannel0 >2 then
      high Motor1
      Low Motor2
      pause 5000
    low Motor1
    low Motor2
    endif
    
    goto main
    If I put in <1 for the argument, the motor runs even with the LDR covered. If I put in >1 the motor won't run unless I shine the torch directly on the LDR. I'm sitting here in ambient light with the sun shining in the window so the motor should be running.

    Any ideas as to what I'm doing wrong ?

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Do you use a word for 8 bit as well?

    Motor2 is never going on by the way.

    Robert

  9. #9
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    OK corrected that (original example code must of been for higher resolution...) but still no joy in setting the thresholds

    Motor two is always off in this example as its the other terminal to the H bridge

  10. #10
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    You should post the schematic of your project in order to get proper help. Very likely your problem is in the hardware arrangement.

    Cheers

    Al.
    All progress began with an idea

Similar Threads

  1. 12F683 - Pin1 not working
    By ruijc in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 8th February 2014, 17:38
  2. 12F683 Maths and code genius reqd.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st January 2014, 08:44
  3. please help with 12f683 pwm code
    By haidar in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 22nd May 2013, 21:25
  4. Problem converting 12F683 code to 12F1840
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th March 2013, 01:55
  5. Working code but my layman approach uses too much code space
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th December 2012, 20:44

Members who have read this thread : 2

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