Actually, shortly after I wrote that I had another idea. Couldn't
you use a diode, capacitor, resistor and a thermal resistor (or
whatever device you're measureing with) to make an RC circuit? You
could charge up the capacitor by turning the bit into an output, then
switch it back to an input. The input would stay high until the MCU
drained all the power (maximum count) or until the thermal resistor
(which would short the capacitor) drained the capacitor. Just yet
another thought
--- In avrclub@avrc..., "Patrick A. Timlin" <ptimlin@y...>
wrote: > No, but are you using an AVR with a analog
comparitor built in? There is an > app note put out by Atmel for making an ADC out of
the analog comparitor > found on many AVRs. Not high resolution, but good
enough to get rough ADC on > AVR chips without built in ADC functionality.
>
> Same sort of principle where you turn on an output which charges an RC > circuit and you keep track of the time it takes
for the analog comparitor to > toggle based on the voltage present on the
reference of the comparitor (the > voltage you are trying to read). Since you know
the R and the C and the time, > it is simple math to figure out the voltage.
Reply by Patrick A. Timlin●February 4, 20032003-02-04
--- "poitsplace <lmburt@lmbu...>" <lmburt@lmbu...>
wrote: > Anyone here ever try timing the pulse width (and
off time) of a 555
> timer's output to make a primitive (and obviously somewhat slow) A/D
> converter for reading resistance?
>
> It would be relatively simple...just use an interrupt to check it at
> regular intervals and increment the counter.
No, but are you using an AVR with a analog comparitor built in? There is an
app note put out by Atmel for making an ADC out of the analog comparitor
found on many AVRs. Not high resolution, but good enough to get rough ADC on
AVR chips without built in ADC functionality.
Same sort of principle where you turn on an output which charges an RC
circuit and you keep track of the time it takes for the analog comparitor to
toggle based on the voltage present on the reference of the comparitor (the
voltage you are trying to read). Since you know the R and the C and the time,
it is simple math to figure out the voltage.
=====
Patrick Timlin ptimlin@ptim... http://www.geocities.com/ptimlin/
Thanks man. Thats what it was. Boy is that a stupid mistake!
--- In avrclub@avrc..., "Patrick A. Timlin" <ptimlin@y...>
wrote: > --- "freerideruf
<freerideruf@y...>" <freerideruf@y...> wrote:
> > I have been trying to write embedded C, which will allow me to do an > > appropriate task when one of the 8 switches
is pressed. Here is my > > code. PORTB is connected to LED's and
PORTA is connected to the
> > switches. This code doesn't light up the appropriate LED when the
> > corresponding switch is pressed. Does anyone have any suggestions? > > Thanks in advance for the help.
>
> C is not my strong subject (I took a C class a little over a year ago and > that is about the extent of it). Anyway, keep in
mind that both the switches > and the LEDs on the STK500 are active low. So for
the switches, with none > pushed, that port should see all highs (0xFF).
When you push a button, that > pin is pulled low. Likewise, with the LEDs, you
pull the line LOW to turn on > the LED. Looking at your code it looks like you
are trying to do the
> opposite.
>
> Every one of your IF statements will be true since every switch input will be > high until the button is pressed. So the program
will test PINA.0, find that > it is high (true), set the port so that every LED
except one will be one > (since all the lines will be pulled low activating
the LEDs they are
> connected to, except for the first bit which is high). Then all the rest of > your statements will be ignored because they are
"Else" statements.
>
> If you push that button (A.0) then your program should skip to the next > statement, which will of course be true, and all
the LEDs, except for the > second one now, will be on.
>
> Is that what you are seeing?
>
> Patrick
> =====
> Patrick Timlin ptimlin@y...
> http://www.geocities.com/ptimlin/
>
> __________________________________________________
>
Reply by Patrick A. Timlin●February 3, 20032003-02-03
--- "freerideruf <freerideruf@free...>"
<freerideruf@free...> wrote: > I have been trying to write embedded C, which will
allow me to do an
> appropriate task when one of the 8 switches is pressed. Here is my
> code. PORTB is connected to LED's and PORTA is connected to the
> switches. This code doesn't light up the appropriate LED when the
> corresponding switch is pressed. Does anyone have any suggestions?
> Thanks in advance for the help.
C is not my strong subject (I took a C class a little over a year ago and
that is about the extent of it). Anyway, keep in mind that both the switches
and the LEDs on the STK500 are active low. So for the switches, with none
pushed, that port should see all highs (0xFF). When you push a button, that
pin is pulled low. Likewise, with the LEDs, you pull the line LOW to turn on
the LED. Looking at your code it looks like you are trying to do the
opposite.
Every one of your IF statements will be true since every switch input will be
high until the button is pressed. So the program will test PINA.0, find that
it is high (true), set the port so that every LED except one will be one
(since all the lines will be pulled low activating the LEDs they are
connected to, except for the first bit which is high). Then all the rest of
your statements will be ignored because they are "Else" statements.
If you push that button (A.0) then your program should skip to the next
statement, which will of course be true, and all the LEDs, except for the
second one now, will be on.
I have been trying to write embedded C, which will allow me to do an
appropriate task when one of the 8 switches is pressed. Here is my
code. PORTB is connected to LED's and PORTA is connected to the
switches. This code doesn't light up the appropriate LED when the
corresponding switch is pressed. Does anyone have any suggestions?
Thanks in advance for the help.
#include <90s8515.h>
void main(void){
DDRA=0x00; //PortA input from switches.
DDRB=0xFF; //PortB set to output to LED's
PORTB= 0x00;