Hello everyone,
If this is the wrong forum: apologies, but I couldn’t find a more appropriate one.
I did my bachelor in electrical engineering, but now master in a different engineering field. they once let us play with a PIC microchip, and only changing some variables in a premade template. Years later, I decided to start programming a PIC16F690 for a personal project. I’ve been busy for days trying to figure everything out. So pls don’t shoot me when asking stupid questions. This is a ‘from zero’ beginner.
OBJECTIVE:
This might turn into a build thread later on. Thing is, I do motorcross and I would like to build a automatic startgate.
The working of the gate has to be the following: set up manually. Once on bike press a button on a remote, this triggers a 10 second red warning light on the startgate. Once the 10 seconds are up, a red light flickers for 5 seconds followed by a 1 sec buzzer and after that the gate gets dropped (with a 9V solenoid pushing (for 1 second) the release) between 3 and 6 seconds RANDOMLY after the flickering light.
I’ve already programmed the PIC with a pickit 2, it simulated perfectly. Oscillator is set correctly, registers should be correct,… Point is, on the computer it works. But this has to transfer to hardware :(.
I’ve used MPLAB with XC8 compiler and wrote it in C. A review is always welcome :D. [See G Drive or attachment
I made the hardware scheme, with some small corrections by a friend. Here’s how it looks like: [See picture or attachement.
For the wireless part I have a cheap ebay ‘garage controller’. Here is a list of all the used parts. I can only order from farnell. [See G Drive or attachment
Today I’ve carefully made everything on a breadboard. And thus far I’m satisfied that it partially works. Here is what has to be solved, and really need your help with. I’ve been staring at it for hours and after this solo project, I’m ready for some outside help:
STATUS:
The input pin is kept low when the 9V battery is connected. After this the green ‘on’ light goes on, which it should. BUT the solenoide is also continuisly on (as soon as 9V is connected which draws alot of mA), which is not part of the plan. When setting the input to logic high by the 10k resistor (to avoid a floating state), the red light goes on as it should, it also flickers after 10 seconds for 5 seconds as it should. Also the buzzer goes off for 1 second as it should. Then (the random timing I suspect) a couple seconds later, the solenoid turns OFF and stays off. As you see this is ALMOST the reverse of the what the solenoid should do.
This was problem one. Then I have a second one: There is no way for it to do this for more than one cycle. I always have to replug the 9V battery to make it do this. This is what happens when I retrigger the input after 1 cycle: The leds work as they are supposed to, but the buzzer ‘clicks’ (like putting a DC on a speaker) AND the solenoid does nothing. This happens every retrigger I try after the first cycle. To avoid this I need to replug the 9V battery in, which is quite impractical.
PROGRESS1: I think I’ve figured out most of the problem. I was using a cheap 9V battery. I decided to use a second one and run the solenoid and buzzer on that one. This helped. Now the device can go through the cycle many times: the buzzer now always goes and the solenoid operates.
Still 2 problems persist: when hooking up the solenoid is still continuilsy on untill I’ve gone through the first cycle.
Problem 2: After a while the timers start to stretch out: The leds blink slower and the time seems prolonged on every timer?? this baffles me. Because I can’t see a draining battery affect the internal oscillator of the PIC.
I also have a suspicion that the random timer isn’t random but constant. Does the PIC support rand()?
PROGRESS2: when hooking up 18 volt, the leds and timers are faster. Now I really don’t know anymore
PROGRESS3: Sorry for the double post: Here is a video I made. Pls ignore my brainfart for filming it vertically -_-
This is what I did: I replaced the buzzer and solenoid by a LED+220ohm hooked up to the microcontrollers outputs.
This is what takes place: On initial bootup the red ‘solenoid’ LED is on. This shouldn’t be happening Also notice that the LEDs (especially the green ‘on’ LED) are very dim the first cycle.
Also every time the green ‘buzzer’ LED turns on, the green ‘on’ LED goes very dim. Why? But after the first cycle, the LEDs return to full brightness.
A second problem is that on later cycles, the green ‘on’ LED goes out when the red ‘solenoid’ LED is actuated and dims when the green ‘buzzer’ LED is on.
This can’t all be because of the 9V battery can it, because I’ve tried it with some high quality ones.
What I also found out is that the random timer is indeed random, so I’m happy with that.
I’m pulling my hairs out. I’m not the kind of guy to come for ‘easy’ advice, and like to try everything myself first, but this got me puzzeled and I can really use some advice.
Kind regards,
Dries Coppens](https://www.youtube.com/watch?v=Jk6QjAnwoM0)](https://drive.google.com/folderview?id=0B62VCnggtg37dzNxYklLWUVnTjg&usp=sharing)](https://drive.google.com/drive/#folders/0B62VCnggtg37dzNxYklLWUVnTjg)](https://drive.google.com/folderview?id=0B62VCnggtg37dzNxYklLWUVnTjg&usp=sharing)