![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
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 | ||
| |
| | (permalink) |
| 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? | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |||
| Thank you for response, mramos1. Quote:
Quote:
Quote:
| ||||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| 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? | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) | |
| Quote:
Yes, ISIS Proteus is a simulator. Last edited by MrSpock; 6th December 2007 at 04:29 PM. | ||
| |
| | (permalink) |
| Is the Watch Dog Timer turned off? If yes then it's something to do with your simulator. Mike. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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 ... | |
| |
| | (permalink) | |
| Quote:
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. | ||
| |
| | (permalink) | ||
| Quote:
Quote:
| |||
| |
| | (permalink) | |
| Quote:
I believe I'm missing something in configuration. | ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |