PDA

View Full Version : NewbieFirstPost PIC16F616 or 16LF818



buglow
- 22nd June 2008, 20:34
Hi. This is my first post. Yes, I'm a newbie. Trying to come up with a way to read a variable voltage (from a sensor through an op-amp) using the PicBasic Compiler from MicroEngineering Labs, then convert it to be displayed on a two-digit 7-segment LCD. Is there a standard for doing this? It's not PicBasic Pro so it doesn't allow ADCin, making it more difficult to read ADC inputs. I have to somehow use the PEEK command instead. Is it possible to simply PEEK an input or do I have to somehow store the value in a register then PEEK that? I have analog experience but programming microcontrollers is alltogether different! Is there some simple method to accomplish this? Thank You, Buglow

mat janssen
- 23rd June 2008, 17:02
Please post your code so we can help you further.

BrianT
- 23rd June 2008, 23:33
Directly driving the ADC is pretty simple. Here is a code snip from a PIC 18LF4620 job. This is for an 8 bit result. Change the ADCON2 definition for 10 bits.



GetECG: '
trisa.2 = 1
ADCON0 = %00001001 'Ch2 selected, Go/Done = 0, ADC ON
ADCON1 = %00001100 'VRef = Vdd, Vss, <2:0> analog
ADCON2 = %00111111 'Left just (=8 bit), ADacq time = 20 Tad, ADClk = RC
pauseus 50
ADCON0.1 = 1 'start conversion
ADCNotDone:
if adcon0.1 = 1 then adcnotdone
ecgval = adresh
if ecgval > MaxECG then MaxECG = ecgval ' find MAX
if ecgval < MinECG then MinECG = ecgval ' find MIN
'Turn ADC OFF
ADCON0 = %00000000 'AD OFF, Ch0 selected, Go/Done = 0
return




HTH
BrianT

buglow
- 28th June 2008, 21:49
Thank you for the code. I haven't written any yet. I've got the PICBasic compiler from MicroEngineering, the ePIC programmer and several 16F616 microcontrollers. The whole thing is new to me so it may take awhile to get it. The requirement is to sample an analog voltage at power up, convert it to a digital value and display it as 00 on a two-digit LED display, and reassign a momentary "on" button to an "off" button so one button turns the thing on and off, and provide some sort of interrupt so you can always turn it off by pushing the momentary "off" button. The analog voltage comes from a sensor amplified by an instrumentation amplifier. The firmware would have to "zero" the display and convert the input voltage to a pre-determined display range. So, for example, if the range of the sensor is 20mV to 120mV, the display would read, let's say, 00 to 60. But if the sensor voltage were 31mV to 97mV the display still has to read 00 to 60. Since the MCU would know the lower limit (and set it to zero on power-up) that's fine. But how am I going to let the MCU know the upper limit? I'm thinking it might be possible to come up with a calculation that when given the low number would provide the high number. Then the MCU would know how to scale the voltage over 00 to 60. Does anyone think this is reasonably accomplished with a PIC16F616? Has someone already done something like this? Would someone be interested in writing code that would do the above? I may be able to offer some sort of incentive. I'm rather afraid my analog mind has a lot of trouble with the digital side of things...
Thank You.