Now that I know how to do A/D with the chip, my application requires two
signals to be sampled so I was wondering now what the procedure is to use 2
analog inputs. It looks to me as if only one analog to digital conversion
ever occurs at a time so my guess is I would configure 2 of the ports as
analog inputs initially and then depending which of the 2 I want to use at
any given time, I change the channel select bits to point to the port in
question, do one A/D conversion, claim the result from the high/low
register, and then change the channel select bits to the other input and
sample that sequentially back and forth?
Another question, since the A/D is 10 bits, how does the high/low result
register function in terms of the left and right justification? If I left
justify the result register and have 8 of the 10 bits in the High register
with the other 2 in the Low register, where is bit 0 and bit 1 of the 10 bit
result, are they the 2 bits in the low register?
In that demo program I was using with 8 LEDs on port C for outputs, I had
the result register left justified and I was reading the result from the
High register's 8 bits and I am now wondering if what I saw was bit 3 to 10
or bit 1 to 8.
ie: If I want to use these results for mathematical purposes...and I only
want to use 8 bits...does it really matter if I use the firsrt 8 or last 8
bits out of 10 as long as I calibrate the binary results to the input
voltages expected for my calculations using the binary results?
Lorick wrote:
>
> Now that I know how to do A/D with the chip, my application requires two
> signals to be sampled so I was wondering now what the procedure is to use 2
I know this might sound a bit tough, and there are plenty of good folk
on this list, including myself, who don't mind offering help.
If you haven't already, please get yourself a data sheet on these
devices before you proceed any further. Then sit down with a cuppa and
browse through the sections on RAM page selection, Port control and
Analog conversions. I've noticed that you aren't paying much attention
to some serious PIC programming issues and are relying on luck to get
you through.
It won't take too long. Write down what you need to set to enable your
ports and A2D and then translate it into code. Get a simulator and watch
what is happening. You won't be able to see analog results, but you can
set dummy values, and then see how your code performs.
You will be a much better programmer having done this. PIC's are
friendly little creatures, they always do what you tell them to even if
it's not what you wanted :-)
You had the A2D left justified, which means that the upper 8 bits were
being read from ADRESH and the lower 2 bits (7, 6) in ADRESL.
You will need to preselect the analog channel you which to read from
before using it.
> If you haven't already, please get yourself a data sheet on these
> devices before you proceed any further.
I've been finding all my information from the 200page 16F87x PDF printout
I made 2 weeks ago, and I read the A/D section but it only alluded to
discussing implementation of one channel besides showing how to enable any
number of channels, so I thought before I try to figure out where else in
the 200 pages to look, I'd ask people who might be able to tell me where to
look. I only wish I had time to read (and absorb) 200 pages but I'm taking
8 final year university courses this semester. Since Philosophy is one of
them, I'm having enough trouble figuring out that language, let alone pic
asm!
I did get my A/D 8 LED circuit working on luck but since then I've figured
out exactly what every command does in the code and I know why they are all
there now. I haven't worked with microcontrollers since the 68HC11 in 1997
so it's taking a while to get used to it again.
> browse through the sections on RAM page selection, Port control and
> Analog conversions.
I know that there will be an issue with page switching that someone warned
me about before I decided to buy a pic programmer, and slowly I'm running
into that, but I still don't know where in the 200 pages to start (maybe now
I do) to learn what I need to know. I really DO need to get my things up and
running, luck or no luck, but I think I'm heading more towards non-luck
implementations now that I know better questions to ask. I guess overall
I'm mostly asking "where in the data sheets do I look or which microchip.com
PDF file do I get" rather than "someone show me a working program to save me
some effort".
> It won't take too long. Write down what you need to set to enable your
> ports and A2D and then translate it into code.
I accomplished this earlier today when I learned what the A/D section of the
data sheets really mean.
>Get a simulator and watch what is happening. You won't be able to see
analog results, but you can
> set dummy values, and then see how your code performs.
I've been having trouble getting the simulator to show me anything more
complex than LEDs flashing on a port. I didn't know what to do, if there
was anything possible, to simulate the A/D things, so I tried setting a
stimulus pin on port RA0 with the Toggle so I could simulate a sample of
either 0 or VDD but it didn't work...and I always seem to end up watching
endless loops going on while animating the code...so I comment out things
like delays...and something else goes wrong etc....so I just modify one line
of code and Flash the chip and see what really happens.
> You had the A2D left justified, which means that the upper 8 bits were
> being read from ADRESH and the lower 2 bits (7, 6) in ADRESL.
Which is what I had assumed based on the picture map in the data sheet...so
I was wondering if, by only reading the upper 8 bits and ignoring the lower
2....I was doing something I shouldn't have when it comes to making use of
the analog data with the lower bits missing in my inner calculations.
> You will need to preselect the analog channel you which to read from
> before using it.
So If I want to continuously sample 2 analog signals I'll have to select the
first analog signal's channel, sample it, get the 10 bit data and move it
somewhere else or use it, then reconfigure the analog input path to the
second source I have and sample that, move its data somewhere or use it
directly, and then reconfigure the path back to the first analog channel and
do it that way repeatedly?
> So If I want to continuously sample 2 analog signals I'll have to select the
> first analog signal's channel, sample it, get the 10 bit data and move it
> somewhere else or use it, then reconfigure the analog input path to the
> second source I have and sample that, move its data somewhere or use it
> directly, and then reconfigure the path back to the first analog channel and
> do it that way repeatedly?
When you used the upper 8 bits of the result, you are simply using the
10 bit A2D result with less resolution. In other words you will only be
able to use 256 voltage steps instead of 1024.
Assuming perfection....
ADRESH
0 0.0v
1 0.019v
2 0.039v
...
254 4.961v
255 5.0v
Here is some code that may help you out.
; Set IO pins for A2D. 2 channels needed, but ADCON1 only allows 3,
; or 2 with Vref set on RA3.
; PortA RA0 and RA1 must be set as inputs for A2D to work, RA3 is not
; needed for A2D so it can be set as an output and is unused. PortB
; has a switch on input RB0 and nothing else. PortC is used for binary
; led display.
clrf porta ; initialise ports
clrf portb
clrf portc
bsf status,rp0 ; set for RAM bank 1
movlw b'00000011' ; RA0, RA1 = input for A2D
movwf trisa
movlw b'00000001' ; RB0 = input
movwf trisb
clrf trisc ; all outputs
; Use 3 A2D channels on RA0, RA1 and RA3 - set adcon0 = xxxx0100
; Use left justification - set adcon0 = 0xxx0100
movlw b'00000100' ; RA0,1,3 = A2D, left justify
movwf adcon1
bcf status,rp0 ; back to RAM bank 0
; set for A2D channel 0 - adcon0 <CHS2, CHS1, CHS0> (000)
; set A2D conversion clock - adcon0 <ADCS1, ADCS0> = internal RC (11)
; turn on A2D module - adcon0 <ADON> (1)
It feels like about 50 degrees in here at the moment. I think my hard
disk turned into a soft one along with the brain box.
This code should work better than the last.
; Set IO pins for A2D. 2 channels needed, but ADCON1 only allows 3,
; or 2 with Vref set on RA3.
; PortA RA0 and RA1 must be set as inputs for A2D to work, RA3 is not
; needed for A2D so it can be set as an output and is unused. PortB
; has a switch on input RB0 and nothing else. PortC is used for binary
; led display.
clrf porta ; initialise ports
clrf portb
clrf portc
bsf status,rp0 ; set for RAM bank 1
movlw b'00000011' ; RA0, RA1 = input for A2D
movwf trisa
movlw b'00000001' ; RB0 = input
movwf trisb
clrf trisc ; all outputs
; Use 3 A2D channels on RA0, RA1 and RA3 - set adcon0 = xxxx0100
; Use left justification - set adcon0 = 0xxx0100
movlw b'00000100' ; RA0,1,3 = A2D, left justify
movwf adcon1
bcf status,rp0 ; back to RAM bank 0
; set for A2D channel 0 - adcon0 <CHS2, CHS1, CHS0> (000)
; set A2D conversion clock - adcon0 <ADCS1, ADCS0> = internal RC (11)
; turn on A2D module - adcon0 <ADON> (1)
From: Tony Nixon
> When you used the upper 8 bits of the result, you are simply using the
> 10 bit A2D result with less resolution. In other words you will only be
> able to use 256 voltage steps instead of 1024.
> Here is some code that may help you out.
I have a good idea of what's going on (and how to help myself better now
that I finally have some fundamentals). Thanks
my coleague asked if we could use a PIC to make 6 voltage measurements
and show it on 6 x 3-digit 8-segment-LED displays.
I've said it's no problem, besides how to light 18 8-segment displays.
Anyone have tried to light a large quantity of 8-segment-LED-displays from
the same PIC? I think I could make this with one port driving the segments
and another driving three 4051 to select the display, but they will flicker
and the luminosity will be very low.
Anyone can make me some suggestions?
Maybe I can use a PIC16F877, with first-digit on portB, second-digit on
portC, third digit on portD. Then use PORTE to select the 3-digit-display
with a 4051.
Best regards,
Brusque
+------------------------+
| Edson Brusque |
| Research & Development |
| http://www.citronics.com.br |
+------------------------+
my coleague asked if we could use a PIC to make 6 voltage measurements
and show it on 6 x 3-digit 8-segment-LED displays.
I've said it's no problem, besides how to light 18 8-segment displays.
Anyone have tried to light a large quantity of 8-segment-LED-displays from
the same PIC? I think I could make this with one port driving the segments
and another driving three 4051 to select the display, but they will flicker
and the luminosity will be very low.
I've said it's no problem, besides how to light 18 8-segment displays.
Anyone have tried to light a large quantity of 8-segment-LED-displays from
the same PIC? I think I could make this with one port driving the segments
and another driving three 4051 to select the display, but they will flicker
and the luminosity will be very low.
Anyone can make me some suggestions?
How about using some Allegro UCN5832's? Cascadable serial in shift registers
with high current open drain outputs, 32 per chip.
The Maxim ICM7212 (4 digits) is good, use multiplexing on the Digit
Selects and Data lines. MC4511's I used before that do the business
too, just sort out the driving of Latch Enable for each digit.
> Anyone have tried to light a large quantity of 8-segment-LED-displays
> from the same PIC? I think I could make this with one port driving the
> segments and another driving three 4051 to select the display, but
> they will flicker and the luminosity will be very low.
You're right about the luminosity, but I don't know why they would
flicker. The PIC can easily multiplex them all every 10 ms. If your
drivers aren't "up to scratch" though, they will flicker as the numbers
change.
> Maybe I can use a PIC16F877, with first-digit on portB, second-digit
> on portC, third digit on portD. Then use PORTE to select the
> 3-digit-display with a 4051.
Mmm, let's see. The 4051 is an analog multiplexer. It it *totally*
unsuitable for display driving - been there, done that.
> Anyone can make me some suggestions?
Face facts. You cannot drive 18 digits with a PIC. You cannot
practically multiplex LED digits by 18, and even six might be asking.
Common cathode displays? If so, consider the 4511 latch-decoder-driver.
Use six of them, one per display, and three (or more) NPN multiplex
drivers. Switch off the drivers, load one digit data into each latch
then enable the appropriate driver. Needs: 3 driver control lines, 4
data lines, 3 decoder select lines (into a 74HC138). Ten lines.
Multiplex is by three, 4511s have 25mA drive capability. Should be OK.
One last thing - you would really *not* want to have the PIC driving
LED displays itself if you are going to use its in-built ADC, would you?
You're going to have plenty of fun with decoupling the drivers from the
PIC ADC as it is.
--
Cheers,
Paul B.
The 4051 can be used to select a whole digit, via a low- or high-side
transistor depending on whether common cathode or anode type. It
has only 25mA through current so cannot drive a display directly but
yes it does work as selector. My first meter project was a 10-digit
frequency meter, using a 68HC705K1 + 4051s + assorted glue to run
the display. The display PSU was diode-isolated with a couple of
k uF, no problems.
> > segments and another driving three 4051 to select the display, but
> > they will flicker and the luminosity will be very low.
>
> > Maybe I can use a PIC16F877, with first-digit on portB, second-digit
> > on portC, third digit on portD. Then use PORTE to select the
> > 3-digit-display with a 4051.
>
> Mmm, let's see. The 4051 is an analog multiplexer. It it *totally*
> unsuitable for display driving - been there, done that.
>
> The 4051 can be used to select a whole digit, via a low- or high-side
> transistor depending on whether common cathode or anode type. It
> has only 25mA through current so cannot drive a display directly but
> yes it does work as selector.
But why?
I suppose you used it instead of the base resistors? If you want a
positive selector, the 4017 is perfect for the job - selects ten digits
with just two lines. If a negative selector, the 74HC138 of course.
In one of these two applications with a 4051, if you push it (that is,
current-wise), something very nasty happens.
--
Cheers,
Paul B.
Take a look at the max7219. Its a serially interfaced 8 digit 7-segment+dp
display driver with the ability to cascase ( i think 4 or 5 of them ).
The timing sequences needed to run these are very simple and they only take
up 3 i/o pins
You can also change the decode method and then the chips will not do bcd to
7segment decoding, but rather give you induvidual control over each of the
64 i/o lines. no need to drive a set of tansistors to do bank switching, it
does all that for you
> and show it on 6 x 3-digit 8-segment-LED displays.
>
> I've said it's no problem, besides how to light 18 8-segment displays.
> Anyone have tried to light a large quantity of 8-segment-LED-displays from
> the same PIC? I think I could make this with one port driving the segments
> and another driving three 4051 to select the display, but they
> will flicker
> and the luminosity will be very low.
>
>
> +
>