12F683 - basic code not working


Closed Thread
Results 1 to 40 of 57

Hybrid View

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

  2. #2
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    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

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Robert,

    I grabbed the h-bridge circuit from a web site, which using pnp / npn transistors works ok for the test motor (see above). I will be using an H-bridge chip for the larger motor.

    Yes for testing I have the motor running for 5 sec once the threshold has been breached

  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 think you need a voltage divider network for the LDR. As it is the voltage on your ADC input line will always be 5VDC.

    I also wonder about the capacity of your transistors. The stall current on the some of the motors I found was 46 Amps. If the motor were to stall, your transistors would burn out with unknown consequences. If you want to use this motor I'd put a fuse in the supply line to limit current during stalls.

    Typically motors make alotta noise when running. I think it's a great idea to separate the power supplies. Just make sure to make the low side connected between the two systems.

    My intimation of TRISIO is relevant to PBP2.6 also. I'm not sure if PBP starts with LSB when reading the TRISIO and quits after 6 bits or starts at the MSB and quits after 6 bits. I do know the 12F683 only has 5 I/O pins and one I only pin so your TRISIO statement should be 6 bits wide.

  5. #5
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Thanks for the comments:

    I've tried using the LDR in series with a 10K pot between 5v and GND, connecting GPOI.0 to the junction between them and still can't get anything meaningful for the value of the variable that stores the ADC readings.

    I've corrected the code thus:

    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 byte
    
    GPIO = 0 ' clear all output
    Pause 50 ' internal oscillator settle time
    
    main:
    low Motor1
    low Motor2
    adcin 0,adchannel0 ' Read AN0
    
    If adchannel0 >10 then
      high Motor1
      Low Motor2
    pause 5000
    low Motor1
    low Motor2
    
    endif
    
    
    goto main

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


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Check the risistence of your LDR in both condition (dark and light). Since the lowest resistance should be found in light, use this value for your devider network. In this way you should have a value in volts near to zero in dark and near to Vdd/2 in light, more than enough to be sure to trip the system at the right time.

    By the way the schematics of your Hbridge is wrong! NPN should be connected on the low side, while PNP should be connected on the high side.

    Follow the wise suggestion given above, always use freewheel diodes when using inductors!

    Cheers

    Al.
    Last edited by aratti; - 19th January 2014 at 20:43.
    All progress began with an idea

  7. #7
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: 12F683 - basic code not working

    Al,

    My fault, I drew the schematic the wrong way round (I was rushing ). I've now placed diodes between the collector and emitters of each transistor as suggested.

    Measuring the LDR I get a few hundred ohms when the torch is directly into the face of the LDR and around 2.1m ohms when I place my finger over it. Under the ambient light in the room it was averaging 16K - 18K. I've tried placing the LDR and an 18k resistor in series between +ve and GND and then connecting GPOI.0 to the junction between the two. The LED on the development board was lit quite bright and covering the LDR had no effect. I then used a 200 ohm resistor based on the fact that in light the resistance was a few hundred ohms when tested.

    With the 200 ohm resistor in place as a voltage divider with the LDR, under normal room light with a value of adchannel0 >2 in the if then statement the motor runs. If I change that to adchannel0 >3 and re-compile the motor won't run regardless of bright light or darkness.

    With the divider made up as the LDR between +5v and GPOI.0, and the 18K between GPIO.0 and GND I get 0.6v on GPIO.0 when the ldr is covered, and around 3.5v with the torch shone directly at the ldr. So I would assume this voltage range of 3v should be enough for the ADC to read ? so why is it that the ADC is acting more like a switch with a value of 1 rather than 255 steps ?

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