Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 4th December 2007, 06:07 AM   (permalink)
Default Plz help building a voltmeter on PIC12F683

I'm beginning discovering a PIC world. Trying to build a voltmeter indicator, so it will turn LED on if input voltage drops lower than 3 Volts, and turn it back off it the voltage goes back. It sounds awefully simple, but I'm stuck for couple of day already. I'm using PIC12F683, in MicroCode Studio with PicBasicPro 2.47, and PICKit 2. I'd really appreciate if somebody could give me a code example how to make it work. Thanks in advance.
MrSpock is offline  
Old 6th December 2007, 11:19 AM   (permalink)
Default

Quote:
Originally Posted by MrSpock
I'm beginning discovering a PIC world. Trying to build a voltmeter indicator, so it will turn LED on if input voltage drops lower than 3 Volts, and turn it back off it the voltage goes back. It sounds awefully simple, but I'm stuck for couple of day already. I'm using PIC12F683, in MicroCode Studio with PicBasicPro 2.47, and PICKit 2. I'd really appreciate if somebody could give me a code example how to make it work. Thanks in advance.
Here where I'm so far [see code below]. Conversion seems like working, but I can't make both LEDs go HIGH simultaniously! In other words when Vin somewhere between 86 and 170 both LEDs go into glow or blink. Is there a trick to make both of them go ON at the same time? Or am I doing something wrong?

PIC12F683 connections:
Pin 3 - Input 0-5V
Pin 4 - +5V
Pin 6, 7 - LEDs

Code:

Code:
GrnLED  VAR    GPIO.0   ' Define green pulse-width variable
RedLED  VAR    GPIO.1   ' Define red pulse-width variable
Vin     VAR    BYTE     ' Allocate A/D variable

'A/D Parameters
DEFINE OSC 8
DEFINE ADC_BITS 8		' Use 10-bit A/D as 8-bit A/D

ANSEL.3 = 1				' Set ANS3 as analog input pin
ANSEL.4 = 0				' Set A/D clock
ANSEL.5 = 1
ANSEL.6 = 0
        
ADCON0.0 = 1            ' Turn On A/D
ADCON0.2 = 1			' A/D channel 3
ADCON0.3 = 1            ' ?
ADCON0.6 = 0			' VDD is voltage reference
ADCON0.7 = 0            ' Left Justify result

'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0

PauseUs 100  

start:

    ADCON0.1 = 1        ' Start conversion
    while ADCON0.1 = 1  ' Wait for conversion           
        PauseUs 100   
    wend                    
    Vin = ADRESH
    if Vin < 85 then
        HIGH GrnLED
        'LOW RedLED
    endif
    if Vin > 86 AND Vin < 170 then
        HIGH GrnLED   
        HIGH RedLED
    endif
    if Vin > 171 then
        HIGH RedLED
        'LOW GrnLED    
    endif   
    PauseUs 250
        
goto start
Here is my code:
MrSpock is offline  
Old 6th December 2007, 02:34 PM   (permalink)
Default

Here are 3 things to check.

Are you sure you have enough power for the circuit? Check this first.
Make sure MCLR is handled properly.
Are interrupts turned off?
mramos1 is offline  
Old 6th December 2007, 03:35 PM   (permalink)
Default

Looking at your code, you should have both LEDs turned on. If you haven't then I would suspect you are overloading the pic pins and causing a RMW problem. Try placing higher value resistors in series with your LEDs, something like 1K. Alternatively, place a PauseUs(10) after each write to an LED.

Mike.
Pommie is online now  
Old 6th December 2007, 04:06 PM   (permalink)
Default

Thank you for response, mramos1.
Quote:
Originally Posted by mramos1
Are you sure you have enough power for the circuit? Check this first.
Yes, more than enough. Tried it in Proteus - same result.
Quote:
Originally Posted by mramos1
Make sure MCLR is handled properly.
Tried connecticting MCLR pin through 10K ressistor, no luck.
Quote:
Originally Posted by mramos1
Are interrupts turned off?
I put DISABLE directive, it should turn interrups off, right? Anyway, still blinking.
MrSpock is offline  
Old 6th December 2007, 04:07 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
Looking at your code, you should have both LEDs turned on. If you haven't then I would suspect you are overloading the pic pins and causing a RMW problem. Try placing higher value resistors in series with your LEDs, something like 1K. Alternatively, place a PauseUs(10) after each write to an LED.

Mike.
Tried both, no luck. I'm using Proteus before testing it on a breadboard, so it shouldn't be a problem with power.
MrSpock is offline  
Old 6th December 2007, 04:14 PM   (permalink)
Default

How fast do they blink?

Maybe make the PauseuS 250 to say 2000 and see if the blink rate changes.

Also, can you single step? Halt (breakpoint) at the end of the routine and see if the LEDS stay solid.

EDIT: Not sure what Proteus is. Is it a simulator? Or start PIC kit board?
mramos1 is offline  
Old 6th December 2007, 04:16 PM   (permalink)
Default

Simplified the program to the following, still blinking! Something really wrong with configuration here. Any ideas?

Code:
GrnLED  VAR    GPIO.0   ' Define green pulse-width variable
RedLED  VAR    GPIO.1   ' Define red pulse-width variable

'A/D Parameters
DEFINE OSC 8
DEFINE ADC_BITS 8		' Use 10-bit A/D as 8-bit A/D

ANSEL.3 = 1				' Set ANS3 as analog input pin
ANSEL.4 = 0				' Set A/D clock
ANSEL.5 = 1
ANSEL.6 = 0
        
ADCON0.0 = 1            ' Turn On A/D
ADCON0.2 = 1			' A/D channel 3
ADCON0.3 = 1            ' ?
ADCON0.6 = 0			' VDD is voltage reference
ADCON0.7 = 0            ' Left Justify result

'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0

DISABLE
PauseUs 100  

start:        
    
        HIGH GrnLED
        PauseUs(10)
        HIGH RedLED
        PauseUs(500)
        
goto start
MrSpock is offline  
Old 6th December 2007, 04:21 PM   (permalink)
Default

Quote:
Originally Posted by mramos1
How fast do they blink?

Maybe make the PauseuS 250 to say 2000 and see if the blink rate changes.

Also, can you single step? Halt (breakpoint) at the end of the routine and see if the LEDS stay solid.

EDIT: Not sure what Proteus is. Is it a simulator? Or start PIC kit board?
They blink about 10 - 50 Hz. The problem is that they can't be ON both. As soon as I put HIGH GPIO.1, GPIO.1 goes LOW. Even with Pauses. Not sure how to use breakpoints. Will research it.

Yes, ISIS Proteus is a simulator.

Last edited by MrSpock; 6th December 2007 at 04:29 PM.
MrSpock is offline  
Old 6th December 2007, 04:37 PM   (permalink)
Default

Is the Watch Dog Timer turned off? If yes then it's something to do with your simulator.

Mike.
Pommie is online now  
Old 6th December 2007, 04:37 PM   (permalink)
Default

The 12F683 has a comparator module and CVRef, this should be a very simple program.
Comparator mode 3 looks promising, and CVRef can produce very close to 3V
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 6th December 2007, 04:57 PM   (permalink)
Default

Got resistors on your leds to limit current?

When you get that working, in your first program remember that values 85,86,170 & 171 will do nothing.
You want to test your ranges more like:
if <85 ...
if >=85 AND <170 ...
if >=170 ...
matc is offline  
Old 6th December 2007, 05:56 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
Is the Watch Dog Timer turned off? If yes then it's something to do with your simulator.

Mike.
I tried to use @ DEVICE PIC12F683, WDT_ON and @ DEVICE PIC12F683, WDT_OFF
Same effect. Not sure it's a correct way of configuring Watch Dog. I tried to program the chip and put on breadboard - it acts exactly like on simulator. Only one LED goes ON.

Last edited by MrSpock; 6th December 2007 at 06:08 PM.
MrSpock is offline  
Old 6th December 2007, 06:03 PM   (permalink)
Default

Quote:
Originally Posted by matc
Got resistors on your leds to limit current?
Yes. two 300 Ohm resistors between LED cathods and the ground.

Quote:
Originally Posted by matc
When you get that working, in your first program remember that values 85,86,170 & 171 will do nothing.
You want to test your ranges more like:
if <85 ...
if >=85 AND <170 ...
if >=170 ...
The numbers here are for the reference, I'm using a voltage divider potentiometer attached to the input. It changes the input voltage from 0V to 5V. Ideally PIC should turn one LED on at the beginning, both in the middle, and another one at the end of the potentiometer run.
MrSpock is offline  
Old 6th December 2007, 06:05 PM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
The 12F683 has a comparator module and CVRef, this should be a very simple program.
Comparator mode 3 looks promising, and CVRef can produce very close to 3V
That is exactly my point! It should be very simple
I believe I'm missing something in configuration.
MrSpock is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Robot Building for Beginners Souper man Electronic Books 8 10th August 2008 06:11 PM
Simple 0-120VAC bar voltmeter help qsiguy Electronic Projects Design/Ideas/Reviews 8 13th October 2006 10:13 PM
I need a little help building a simple LED voltmeter joecool85 Electronic Projects Design/Ideas/Reviews 14 2nd February 2006 05:18 PM
Voltmeter using EPROMs robchava Electronic Projects Design/Ideas/Reviews 1 17th June 2003 05:49 AM
Building a signal mixer (for music primary) thec Electronic Projects Design/Ideas/Reviews 4 3rd October 2002 06:07 PM



All times are GMT. The time now is 03:50 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker