12F683 - basic code not working


Closed Thread
Results 1 to 40 of 57

Hybrid View

  1. #1
    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..."

  2. #2
    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 ?

  3. #3
    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

  4. #4
    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

  5. #5
    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

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Al,

    The PIC is on an EasyPIC5 development board, but basically this is the schematic. I've also tried replacing the LDR with a 10k pot and whilst the LED on the dev board dims in brightness the threshold values still have the same effect. Placing the LDR between +5 and GPIO.0 gives a better range of brightness in the LED (not shown in the schematic) from off when the LDR is covered, to bright when an LED torch is placed directly over the LDR.

    I don't program much, so often feel like a newbie when I dust off the development board, and ADC is something I've only once played with. As far as I can understand, the voltage on GPIO.0 should be converted into a byte value between 0 and 254, so I could set the threshold at which point GPIO.4 is made high ?
    Attached Images Attached Images  

  7. #7
    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

    Shouldn't there be protective diodes "somewhere" whenever a motor is used?

    I don't really get how that motor is wired. I would expect a pulse method, but the code is constant on for 5 seconds.

    Admittedly confused.

    Robert

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