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
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
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
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 ?
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
Bookmarks