Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

the bits i cant seem to find.

Status
Not open for further replies.

Ricardoco

New Member
ok ive done a good bit of my programming from examples found on this site and else where
but i cant find examples for a few things i need so rather than asking several questions
ive designed a circuit and the program that runs it will answer all my questions at once.

I would like the 6 led's on PORTB to light sequentialy depending on the position of the
potentiometer

I would also like led 1a to be on for 1 second and off for 1 second when Led 1 is on,
and the time led 1a is on to be increased to 10 seconds when all the PORTB led's are on
being off for ten seconds as well. a sort of a pulse that increases with the potentiometer.
any help or links to examples that will help me achieve this would be magic.


INPUT TO PORTB.6 = Potentiometer

OUTPUT FROM PORTA.0 = led 1a
OUTPUT FROM PORTA.1 = led 2a

OUTPUT FROM PORTB.0 = led 1
OUTPUT FROM PORTB.1 = led 2
OUTPUT FROM PORTB.2 = led 3
OUTPUT FROM PORTB.3 = led 4
OUTPUT FROM PORTB.4 = led 5
OUTPUT FROM PORTB.5 = led 6

i have included a cuircuit diagram that should do the trick but im new so any input will not go un noted thankyou
 

Attachments

  • cuircuita.gif
    cuircuita.gif
    4.9 KB · Views: 585
Ricardoco said:
ok ive done a good bit of my programming from examples found on this site and else where
but i cant find examples for a few things i need so rather than asking several questions
ive designed a circuit and the program that runs it will answer all my questions at once.

I would like the 6 led's on PORTB to light sequentialy depending on the position of the
potentiometer

I would also like led 1a to be on for 1 second and off for 1 second when Led 1 is on,
and the time led 1a is on to be increased to 10 seconds when all the PORTB led's are on
being off for ten seconds as well. a sort of a pulse that increases with the potentiometer.
any help or links to examples that will help me achieve this would be magic.


INPUT TO PORTB.6 = Potentiometer

OUTPUT FROM PORTA.0 = led 1a
OUTPUT FROM PORTA.1 = led 2a

OUTPUT FROM PORTB.0 = led 1
OUTPUT FROM PORTB.1 = led 2
OUTPUT FROM PORTB.2 = led 3
OUTPUT FROM PORTB.3 = led 4
OUTPUT FROM PORTB.4 = led 5
OUTPUT FROM PORTB.5 = led 6

i have included a cuircuit diagram that should do the trick but im new so any input will not go un noted thankyou

did you really mean a 16f84 ?cuz a 16f84 has no analog input .
analog inputs are usually on PORTA on the ones that have one..
 
williB Wrote:
did you really mean a 16f84 ?cuz a 16f84 has no analog input .
analog inputs are usually on PORTA on the ones that have one..

well i was hoping that the potentiometer could be read by measuring the time period between the capacitor discharging and charging measuring scale ranges from 0 to 255 as if an 8-bit AD converter was used. :)
the cap on the pot is 100nF
 
Ricardoco said:
williB Wrote:
did you really mean a 16f84 ?cuz a 16f84 has no analog input .
analog inputs are usually on PORTA on the ones that have one..

well i was hoping that the potentiometer could be read by measuring the time period between the capacitor discharging and charging measuring scale ranges from 0 to 255 as if an 8-bit AD converter was used. :)
interresting idea
 
the 16F628 has a resistor ladder built in, although i havnt quite figured out how to use it yet.
i plan on using it to select ranges similar to what you are trying to do.
 
i have the code to do a similar thing but it is not quite what i need so ive posted here to get some ideas but if it helps you then here it is:


Basic

B0 var byte 'variable used by instruction POT
'Potentiometer is connected to RA0


symbol Potentiometer = PORTA.0

TRISA = $ff 'Port A is Designated input
TRISB = 0 'Port B is Designated Output

Main:
' Read the value of potentiometer

pot Potentiometer, 255, B0
PORTB = B0 ' ' Display value on led's
Pause 10
goto Main
end

there is also this:
Display the result of POT

Device 16F84
XTAL = 4
RSOUT_PIN = PortB.0

Dim Result as Byte

Rsout Cls ' Clear the serial LCD
Inf: Result = Pot PortB.1,255 ' Read the potentiometer
Rsout at 1,1,@Result," " ' Display the result
Delayms 100 ' A small delay
Goto Inf ' Do it forever
found this on my travels writen by:Nebojsa Matic
 
i am not familiar with pic basic what do these two lines do?
Code:
pot Potentiometer, 255, B0 
PORTB = B0 ' ' Display value on led's
 
try this

pic basic contains a command "POT" to read a pot value without AD converter.
you may find this file usefull it explains it all.


**broken link removed**

Always check files for viruses!!
 
Beating Nigel to the punch, why don't you use a 16F628? They do everything that the 84 does, plus they have built in voltage comparators. You simply load the appropriate bit pattern, as listed in the data sheet, into the comparator control register to set the configuration you want.

A friend and I did a very similar thing. Instead of testing a potentiometer and making a result, we made a capacitor tester. We have a known resistance value, and insert an unknown capacitor, and use a comparator to determine when it reaches a specific voltage level. When the comparator interrupt occurs, we use the value in TIMER1 to determine how long it took to charge, and hence the capacitance of the circuit. 8)

Or instead of using a comparator and a capacitor to test a resistor, why don't you use a chip that has a built in analog to digital converter that just works, as opposed to a software solution such as you are proposing?

By getting an analog to digital conversion, and simply outputting the results, your LEDs will count up or down sequentially in binary as you turn your potentiometer. If you would rather have something that rises like a volume indicator bar or something, perhaps just test to see what the most significant bit in the ADC result is, and then output all LEDs on up to that point, and leaving any higher ones off.
 
well here goes

I am very new to all this and im digesting information as fast as i can but it is hard work, i have a lot of 16f84's and there seems to be a lot of examples out there i just thought lets see what we can do with these to keep the learning curve not so steep, ive seen some pretty cool things done with a 16f84 so i thought it would be a good place to start ive got the chips (150 of them) ive got the programmer ive got the software...i will go over to the chip you suggested but i would like to find my feet before i do if you know what i mean lol :D
 
Oh you're the dude with the 150 84's! :D I remember reading that somewhere earlier.

Well, I've never used PIC Basic, so I don't know much about it. If you can use that POT command to get a number based on the position of the potentiometer, then it would be a simple matter of getting the LEDs going like you want. I am going to assume that it will give you a value between 0 to 255. Make 6 zones to test through. 256 / 6 is close to 43. So if the value is between 0 to 43, turn on port b.0, all others off. If the value is between 44 to 87, turn on port b.1, all others off, and so on. Or perhaps you could leave them on as you test higher, and have like a growing volume indicator bar. This assumes that PIC Basic can do greater than / less than comparisons. I would think so.

As for your timing, I'm not sure how you would go about it in BASIC, but in assembly, I would just use a timer interrupt. Your oscillator is running at 4 MHz, and the /4 internal operating frequency becomes 1 MHz. That's 1 microsecond per instruction. A quick brute way I made a clock once was to have the interrupt occur every 250 microseconds (would normally happen every 256, but I loaded a value into the timer to start at, so when it reaches 256, 250 microsecs have actually occurred.) Count those interrupts. When 4 have occured, it's been 1 millisecond. Then you can repeat the idea here. When 100 milliseconds have been counted, you've reached 0.1 seconds. Count ten of those and you've got a whole second. Not very elegant or complicated, but it gets the job done.
 
ok how about this

looking at the diagram how about having a switch (no) for add and a switch for subtract and a "growing volume indicator bar" is exactly what im looking for do you think that would be a better implimentation to do the trick?? :D
 
Yes having two switches would be easier. You don't have to worry about any timing considerations, or analog to digital conversions, setting value ranges to correspond to particular lights, testing them, etc.

If you had a switch for up and a switch for down, then it's a simple matter of starting at 0. If you press up once, increase the counter by one. Counter = 1. turn on the first one (port b.0). press up again, increase your counter. counter = 2, turn on the second one (b.1). rinse, repeat, wipe hands on pants. As for pressing the down button, just subtract one each time, and turn off the corresponding bit. Do boundary checking, such as don't let it go above 6 or below 0.

After you get that done, tackle the potentiometer method. :wink:
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top