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
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
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
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.
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
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 21:43.
All progress began with an idea
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 ?
Add the following defines on top of your code:
DEFINE ADC_BITS 8
DEFINE ADC_CLOCK 2
DEFINE ADC_SAMPLEUS 50
Cheers
Al.
All progress began with an idea
Bookmarks