Basicly I am trying to tie in a microcontroller do automate some functions on a piece of equipment. Each "button" has two contacts. 1 side of each tie in together. I originally though maybe this was a shared ground. It is aparently not.
So that shared trace goes to the is where a signal is sent to tell the equipment what to do. The other trace is the one with the signal on it.
When I use "let gpio.3 = gpio.1" and then tell it "high 1" it works but I can't get it to "pause" to try and send another function to it. I am basicly trying to create a macro. When I try and use the "pause" command it does functions that I never tied in to. This is why I think it is a pulse. ( I was cutting the signal off too early or too late)
Isn't the default for Pulsin's max 65535 @4mhz? If anything I would need to give it a high max not a lower one right?
I didn't want to start another thread for this question.
Is there any way to take a signal coming in on one pin and output that same signal on another?
I don't know if the signal is digital or analog so it's not like I can just set it to high, low, or any pulse commands.
Any idea how this can be done?
Hi plyrathrt,
If you want to switch an unknown (low frequency AC) or (DC signal), with a PIC, you could use a relay.
Your unknown signal would come in one contact, and you could chose when to switch it to the other contact(s).
I think you will probably still need a pull-up resistor in your design to get the PIC to see a high-to-low and low-to-high transition to get any of these commands to work.
If you wanted, for example portb.0 to be your input and portb.1 to be an output, then you'd:
'program the port so the correct pins are in or outs
'this makes bit 1 an input, all other pins are outputs
trisb = 1
START:
portb.1 = portb.0
GOTO START
If you wanted to do this across ports:
trisb = 255 'all of port b is inputs
trisd = 0 'all of port d is outputs
START:
portd = portb
GOTO START
or if you just want to do a single bit on each port:
START:
portd.0 = portb.1 'this makes bit 0 on port D reflect what is going on on portb bit 1
You could also flip-flop the bits of a port using a variable:
portd = portBflipval 'port d now has the value that is on port b, but flipped!!!
Also, if you wanted to track the status of an input, so your code doesn't, for example send out multiple codes:
buttonState VAR BIT
START:
if portb.0 <> buttonState then
buttonState = portb.0
if buttonState = 0 then HSEROUT ["Button 0 released and it's a zero!"]
if buttonState = 1 then HSEROUT ["Button 0 pressed and it's a one!"]
endif
goto START
I've found that this method is excellent for be-bouncing a button press... I don't know why but it works great, even with a hundred lines of code...
If your aim is to read an analog voltage and then send that out on one of the 8 bit ports, that should be easy. Although I havent worked with this yet myself.
I used transistors to make it work but was hoping there was a way to use it with only the pic.
Once you use the "let" command how do you cancel it? That would make it so I would only need to use 1 transistor for the entire project. Example
PIC12F683
I could say
LET GPIO.0 = GPIO.1 'GPIO.0 IS INPUT AND GPIO.1 AS OUTPUT TO TRANSISTOR
HIGH 2 'SEND HIGH TO TRANSISTOR TO LET SIGNAL THROUGH
PAUSE 100 'WAIT 100MS
LOW 2 'STOP TRANSISTOR FROM LETTING SIGNAL THROUGH
NOW HOW DO i CANCEL THE "LET" COMMAND SO I CAN CONTINUE LIKE THIS
LET GPIO.3 = GPIO.1
HIGH 2 'SEND HIGH TO TRANSISTOR TO LET SIGNAL THROUGH
PAUSE 100 'WAIT 100MS
LOW 2 'STOP TRANSISTOR FROM LETTING SIGNAL THROUGH
I would probably just turn the port on, wait and then turn if off:
if portb.0 = 1 then
portd.0 = 1 'turn on port d bit 0
PAUSE 100
portd.0 = 0 'turn it back off after 100 ms
endif
modifiying this idea with my variable makes it a one-shot deal, so the output only pulses once on the low-going transistion, but does nothing when the user releases the button.
buttonState VAR BIT
START:
if portb.0 <> buttonState then
buttonState = portb.0
if buttonState = 0 then 'user is pushing on button
portd.0 = 1
PAUSE 100
portd.0 = 0
endif
endif
Unfortunately all of the bits on a PIC are latching. So if you want them to be a one-shot blink, then you have to code them to do it. I would try to avoid using the HIGH and LOW commands, unless you intend to use the basic stamp compatability files. These can add some overhead to your compiled program that goes onto your chip.
The pause command also affects how the PIC performs in real-time as the world has to stop inside the pic for this command to execute.
Last edited by Jasonce65; - 22nd January 2008 at 01:12.
Reason: update
keep in mind that if your're working with more than one input, one that is an "enable", for example, that you can use a logical operator to make some magic...
if portb.0 <> buttonState AND portd.3 = 1 THEN... etc.
In one case I needed to validate what was going on with a variable that came from the HSERIN and had to use some intense logic...
If (BtVar = 48 AND porte = 0) OR (BtVar = 49 AND porte = 1) OR (BtVar = 50 AND porte = 2) ... THEN...
This let me match the port e value to the character that came in on the serial port. Since Port e on an 16F877A is 3 bits, I needed to compare for all 8 values using this if-then. It's incredible what tis complier and the chips, for that matter can do!
Bookmarks