registered authors login here For more on PMWiki, see pmwiki.org |
For the last part of the lab I made a rudimentary version of the game Simon. I attached 5 LEDs and four switches to the PIC microcontroller. My program blinked the 5th light to indicate play was about to start, then turned on a random set of the four remaining lights. The 5th light blinks again to notify the player that they should be ready to play, and then all lights go out. The player then holds down the buttons that correspond to the lights that were on (i probably should have bought toggle switches) and if they match, then the player has won (signified by rapidly blinking 5th light). Otherwise, they lose (signified by a steady 5th light). All lights go out and the program repeats. I didn't get the sense that the randomization was working terribly well, but everything else went alright. Cool, great job on the Simon game Andy! I'm impressed. Thanks also if you are the Andy who gave me the extra PIC chip. I'm going to give you a new one soon. My application requires that a person select two switches at the same time to illuminate an LED. Pretty simple, but I learned the "AND" command which is kind of cool. IF portb.7=1 AND portb.5=1 THEN HIGH portb.2... I will try to document my work throughout the semester. You can see my board and code here: lab 2 A note on the AND and OR operators: When you use them in IF statements, it's wise to put the various conditions in parentheses, so that the compiler evaluates them first, just like in algebra. For example:
IF (portb.7=1) AND (portb.5=1) THEN
HIGH portb.2
ENDIF
I just finished setting up step 1 of the lab, and I got all 7 leds to light in succession (with an additional light in portb.7 to use for program checking), but it only works when I hold the power in on the board really steady with my fingers. When I let go, either my checking light or my checking light in combo with another light get stuck on, and the program stops moving. The board is obviously still getting power because the LEDs are still on, but something is interrupting the program. Is it a defect with the PIC chip? Or my breadboard? I don't have another chip at the moment to test another one. Anyone have a spare? (I should have some coming by Tuesday or Wednesday so I could reimburse.) Can you put a picture of the board up, Christian? It's easier to diagnose when we can see it. Meantime, my guesses would be:
In all likelihood, your PIC chip is fine, but something is interrupting the running of the program. That usually means bad power, bad clock setup, or bad reset pin pullup. If none of those fixes it, post a pic. Ha!! I figured it out. I wasn't getting power to the left side of my board. Foolish, foolish. I had the 10k resistor set up to pin 1, but no wire to connect it to the 5V regulator. Won't make that mistake again. I programmed a simple light sequence using 3 LEDs. Included 2 switches (like Jet) that had to be pressed simultaneously to initiate the sequence. Tried different ways of doing this, using IF/AND/THEN... REPEAT/UNTIL... WHILE/WEND... all seemed to work ok. But if I held down the button for a sustained amount of time, after approx 5 secs, the sequence seemed to overload in some way, and all the LEDs lit up together (not in the sequence), and stayed lit when the switches were low. Then if I left them alone, sometimes it seemed to clear itself and would work again. Sounds like your chip is resetting itself. My guess is that you're not using 10Kohm resistors on your switches, but something smaller, which is causing a short. Post code and pix of the board. Tom I got the basic setup going, i'm off to radio shack to find something fun to play with. Questions: 1 - The first time I set the chip up, I put port 7 on high/low. The LED quickly burn out. I then tried to program the PIC again and got a 'device not found' error when I tried to compile. I then tried another chip and didn't get that error with the programmer which makes me think I somehow fried the chip? I then added capacitors to my circuit on Todd's suggestion and that helped. It's possible that you fried the chip, but not possible that the capacitors didn't solve that particular problem. I'd like to take a look at the board as you had it wired, because it's more likely that something else on the board caused the problem. 2 - I had a 9v out 1.3 Amp power supply from an old Nintendo. I think it fried the voltage regulator. Does the .3 amps make that much of a difference? Again, not likely. The regulator consumes what amperage it needs, and the rest is dissapated in heat by the Nintendo regulator. Again, I would like to see your circuit, because there's something not quite right about any of this. Can you post a picture? 3 - When I tried testing my circuit at different points by putting the probes directly into the bread board the multimeter didn't register. If I put wires into the board sticking up and then probed those I got a reading. I thought I could put the probes directly into the board? What were you trying to test for? Voltage? That would be possible. Resistance? That wouldn't be possible. Continuity? That would be possible, but wouldn't mean much in the circuit. Resistance and continuity are properties that you test in isolation, not in the circuit. thanks! mb2811 I tried to upload the files but even taking lowest quality photos on my digital camera I couldn't get the files down below 50k in photoshop without destroying the quality. Is there a good tutorial online? I put the low quality image on my blog: Most likely there is a good tutorial available from the Comm Lab syllabus, or perhaps ask Matt Culliford,the resident for that area. The way I'd do it is to crop out all but the part that's mportant, reduce the image size to something reasonable (say, 400x300), then "Save for Web..." which optimizes images pretty well, as JPGs. ![]() http://itp.nyu.edu/~mb2811/archives/2005/09/first_pic_lab.html Let me know if you cannot see it and I can put a nicer one up there. hard to tell much from this image. In particular, I can't see where the ends of the capactitor are going. But it looks like that resistor on the reset pin has red, red, and brown bands. That's a 220-ohm resistor. You want a 10Kohm resistor. 220 would allow way too much current into the reset pin and might cause it to short the PIC. I was just testing for voltage to see if I had current across the breadboard. Voltage and current are related, but not the same thing. To test for current, you measure the amperage. I've connected a potentiometer to the PIC. I used a very simple 'IF' statement, wanting the LED to turn on an off: INPUT portb.0
OUTPUT portd.1
IF portb.0 = 1 THEN
LOW portd.1 'Port of the switch'
ELSE
HIGH portd.1 'Port of the LED'
ENDIF
I thought that since this is a binary if statement, then if the PIC gets current into portb.0, it will output 5V to portd.1 (the LED). But turns out that the PIC outputs whatever voltage it receives as input. So the output voltage varies according to the input voltage. Does anyone know if this is always the case with the PIC? I got a project going: http://itp.nyu.edu/~mb2811/archives/2005/09/electronic_push.html I have a question. My voltage regulator gets pretty hot. People have suggested that I put more capacitors into my voltage regulator but shouldn't I be adding resistors to it? My circuit works well (and can stay on for a long time) but the voltage regulator does get pretty hot. In general, for this circuit what is the function of the capacitors? Todd suggested I put them in but i'm not clear on what they do. thanks! This means you have a short circuit somewhere on your board. Adding capacitors won't help the problem. Most likely there is a subcircuit somewhere that has too low a resistor value (like the 220 ohm resistor above that should be a 10Kilohm resistor). With the circuit unplugged, check your circuit against the circuit picture and schematic for the lab. Didn't get to do as much as I hoped. I'm planning to use my "two bit hard drive" (see last week's lab) to make a combi lock through the microprocessor. A pattern of on/off switches would light the led's. hopefully, i'll get to it by the weekend. After a few wrong turns, i finally got the microprocessor to blink all seven led's. I adjusted the pause duration for each led so they blinked in an abstract pattern. Using a clothespin switches for the next segment of the lab, I made the light turn on when the contact was open and off when it was closed, the reverse of what it would do without going through the chip. There seemed to be some bleed in the system though because some unpredicted blinking occured. Adding a 10k resistor to the switch (which i had forgotten) made the system more reliable, but i wasn't able to clear it completely of the idiosyncracies. Programming the chip to light one led and turn another off with one switch from one port made the matter worse. now totally unaddressed led's started to light. Is it possible that the previous programs were not getting cleared completely from the chip? I peared down the program to a minimum in an attempt to trouble shoot. Even when I returned to the original off when closed/on when open program, extraneous led's would still light up. Any clues? When you load a new program on the chip, the previous program is totally erased. Any unreliability is due to either a circuitry problem or a code error. One last question. Does anyone know how to read capacitance with a multimeter? Does it have to power going through it? Set the meter to capacitance (symbolized with F or C; not all meters can read capacitance). The should be a slot in the body of the meter for the capacitor. Like resistance, capacitance has to be measured out of the circuit. Andy, I also had trouble with randomization. I made a memory game, similar to yours. http://itp.nyu.edu/~cf831/pcomp/archives/2005/09/second_lab_prog.html I noticed that every time I unplugged and replugged the board, and started the game, the random number sequence generated was the same. It seemed more like there was a loop of random numbers. (i.e., if you look at my game, each time you play -- while it is still plugged in -- the sequence stays the same. It is different from game to game, but the second game plays the same way every time, and the third game plays differently from the second and the fourth games, but whenever the board is unplugged, those same second and third (and first and so on) games appear). I'm not sure if that makes complete sense. I can show everyone tomorrow in class. This is because random number generators, especially on a small processor like the PIC, are not that good. See my notes on random for an alternative. The pseudo-random number generator does have certain advantages. Because it generates the same random number sequence every time the chip is powered up, you can take advantage of this behavior for debugging. For example, if your program malfunctions after six rounds of the game, then you can recreate the behavior by cycling power and playing another identical six rounds. Later, once everything is working you can seed the random number generator using physically generated input. I kept a blog on what I have been doing these 2 weeks in the lab. http://www.wretch.cc/blog/itpbabe I got the basic programming today, but I'm still trying to figure out the combination lock and more complex stuff. A couple of people have asked me about the code for the PWM brightness control of the LED's I did in the lab this week. I have posted the code at http://homepages.nyu.edu/~js3854/sears1.pbp if anyone is interested. If you have any questions just ask. js3854@nyu.edu Here's a link to the documentation for this week's lab- A down and dirty Whac-A-Mole game. My general PCOMP index page is at http://www.editmation.com/pcomp ChrisK Here's the documentation for this week's Lab. Basic stuff. |