registered authors login here For more on PMWiki, see pmwiki.org |
I was getting similar "code 0000" errors and it turned out that my pic processor wasn't working. I worked with Vincent on the project - we put together a simple version of Groundhog Day: if the shadow over the photocell is dark enough, a green LED lights up - 6 more wks of winter. If it's almost dark enough, a yellow blinking 'warning' LED lights up. And if there's no shadow, a red LED comes on. any time you get error in code at 0000, it means that the programmer couldn't read the chip. Either the chip isn't in the programmer right, or the chip is dead. 9 times out of 10, it's the former, so check that the chip is seated correctly and facing the righr direction, and that the lock lever is down. Could someone explain to me what is happening on the compiler window where it says in red "CP On" (when I rollover it, I see "code protected state." What does this mean exactly? At any rate, I hadn't noticed this before and I'm wondering if it is to blame for the Code Verify error I've been getting that I wasn't encountering before: "at 0000 \ 0000 should be 283F." Any ideas / suggestions? This means "code protection on" Manufacturers can protect the code on a chip using this feature. It keeps the chip's program from being read or written to by a programmer. You should have code protection OFF at all times. You only use it when you plan never to reprogram a PIC again. Crap. So this is what I should have been doing with my lab results all along. Is it possible to declare and initialize a variable at the same time? Not in PicBasic Pro. I just bought an IR LED and IR Pin Photodiode, and I want to make a remote control-type thing (I guess). The IR Photodiode is p/n NTE3033 and the LED is p/n NTE3017. I copied the code from the lab description and put the Photodiode in, connected from the input pin to ground, and connected the LED to the potentiometer to ground, and I can see in Hyperterm that the "lighting up" of the LED can be seen to increase the analog reading. But it hovers around 50 or so, and if I change the pot to turn up the LED, my voltage regulator starts to get hot as soon as the reading in hyperterm increases above 70 or so. How can I increase the output (and also the sensitivity) of the LED (and photodiode)? Getting hot is always code for a short circuit. It's hard to tell what's going on from your description here, could you post a schematic diagram of your circuit?
if ADCvar < 60 then ' light turns on when Hyperterm shows value of > 60
high portb.0
endif
if ADCvar > 60 then ' light turns off when value in Hyperterm goes below 60
low portb.0
endif
cory, you're code seems to be working perfectly. i read it as, "if ADCvar (is less that 60) portb on" and "if ADCvar (is greater than 60) then portb is off" just swap your symbols! What Toshi said. My code/application seems to be working, but I am getting inconsistent readings from the flex sensor (a lot of 0's even if its bent). It's probably an issue with the flex sensor. I have posted my documentation here. lab #3 can't tell from the picture (a schematic would help) but it appears you're missing a base resistor on that flex sensor input. Read on if your potentiometer is acting funny. I'm using a potentiometer to control the state of an LED display and was wrestling with a problem where the potentiometer was really sensitive at one extreme of its range and non-responsive at the other extreme. I tried a few things before remembering that the potentiometer I'm using is of the "audio taper" type. This kind is handy if you're controlling audio volume since it responds kind of the way human hearing does but it causes trouble if you're wanting to control something linear-wise. If you're seeing this type of behavior from your pot, you might want to check it on a multimeter - see if the resistance increases linearly as you turn the knob. an important and useful point. An audio taper pot changes its resistance on a logarithmic curve, to match the curve of audio intensity. A linear taper port changes its resistance linearly.
DEFINE ADC_BITS 10 ' Set number of bits in result
DEFINE ADC_CLOCK 3 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
TRISA.0 = 1
TRISD = %00000000
ADCvar VAR WORD ' Create variable to store result
main:
ADCIN 0, ADCvar ' Read channel 0 to adval
IF ADCvar <= 3 THEN
LOW PORTD.2
ELSE
IF ADCvar >= 4 THEN
high PORTD.2
ENDIF
ENDIF
GoTo main ' Do it forever
First, what's the resistance range of the thermistor? And what's the resistance value of the base resistor you used? ADCON1 = %10000010 TRISA = %11111111 For Step 3 I used a solar cell with a 10K resistor. As I covered and uncovered the cell, the readings oscillated between 270 (with full light) and 760 (covered with thumb). In the next part, to deal with the rapidly increasing numbers, I first tried using a PAUSE statement after the serial output. This way, each press of the button would only get counted once. I didn't like this approach as it seemed to impede the response of the apparatus. It would only count the button press if you held it down long enough. Eventually i used a loop with a counter to only recognize a button push once every 250 cycles. Also, i wrote some code to only write to the serial port if the total count has changed, thereby eliminating the rapid stream of numbers. Here is my code for that: switchedOnVar var byte main: if portb.0 = 1 And iCounter = 0 then
iCounter = iCounter + 1
prevSwitchedOnVar = switchedOnVar
switchedOnVar = switchedOnVar + 1
endif
if icounter > 0 and icounter < 250 then
icounter = icounter + 1
endif
if iCounter = 250 then
icounter = 0
PAUSE 200
endif
if prevSwitchedOnVar <> switchedOnVar then
serout2 portc.6, 16468, [DEC switchedOnVar, 13,10]
prevSwitchedOnVar = switchedOnVar
endif
goto main instead of using the PAUSE, which doesn't really ensure that the button push is counted once, check into my code samples for an edge detection routine. It counts the button push only when the button goes from off to on. Question: I attached a motor to my pot so that my pot output wouldn't just be numeric (hyperterm) but would actually correlate to an action. When the numbers go up the motor gets faster. The problem is, the number stop showing up in the hyperterm. It's as if the chip cannot do both. What am I missing? thanks update, I put this online: http://itp.nyu.edu/~mb2811/archives/2005/09/week_3_lab_seri.html First, put a schematic up. Hard to tell without a sense of where the motor is attached, where the PIC is attached, etc. Watts = Volts x Amps So if you're running, say, a 1 amp motor at 5 volts, that means you're running 5 watts through the pot. Way too much. I'd suggest holding off on motors just yet. But if you want some more info on them, there's details on my site, and in one of the advanced chapters of the phys comp book. My project is behaving very strangely. Here's the code. The concept of the project is to have a row of LEDs that light up depending on the heat received by a thermister--a "mojometer," if you will. I only programmed for the first light, just to see if I could get the first step working. Well, it didn't, so I decided to just wire up the other lights and turn the project into a joke: you can't get any of the lights to come on, and thus, you have no mojo. So I wired the other lights to RC3 and RD 0, 1, 2, 3 and RC 4. Now, when I give it power, the light at RD1 comes on steadily. No other lights come on, but when I rub the thermister, the programmed light--RD2--works! WHY!? If I rewire that steady light at RD1 to, say, RC2, nothing works anymore. This is crazy. Any ideas? off the top of my head, I'd say there's something wrong with the circuit. The code above should light only PORTD.2. Got a picture, schematic,, etc. of the board? I got my infrared remote control working. It uses a bar led display to indicate the signal strength. Pictures, a movie and the code are here: http://itp.nyu.edu/~cf831/pcomp/archives/2005/09/analog_inout_se.html Nice work! And nice clear pictures. A schematic would help too. My pot smells funny. I've realized I have been wiring my pot with the middle lead to ground. Thank you to Nick for lending me a new one. I've also now experienced the unholy secrets of a floating pin with this lab. Creepy. It turns out the switch coming off of my pin did not have a properly wired resistor. This solved the problem. In other steps I used a photo resistor to get a different readout from the hypertrm. The basics of a photo resistor seem counter-intuitive to me. More light=less resistance? On a grand scale, I suppose it would be interesting to try some perpetual feedback experiments with this concept. think of it as less darkness = less resistance. As for the pot, remember, the ends of the pot are the fixed ends, they go to power and ground. The middle is the wiper, that gives a variable value. You can find alphanumeric LED displays at Digikey. The red kind I used is from Lite-On (the part number is LTP-587HR) but there's a few other manufacturers and you can get them in other colors and even two displays in one package. My source code is here. Hopefully I'll have a schematic up real soon. This week's lab was pretty simple: the 4 leds correspond to how far the pot is turned. You can find documentation and code here. As always, you can get to my general PCOMP index at http://www.editmation.com/pcomp |