![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Ok so I need opinion on how to implement this.
I am reading an analogue voltage (GP0) on 12f675, and I need to trigger an LED if the results in ADRESH or ADRESL, are >greater then 3volts, LED turns off if in between 2.99v and 1.70v, but if it is less then 1.70volts, the LED must turn on again. I have setup my ports to be GP0 and GP1 as Analogue input, and GP3 as digital. I turned Comparators off etc... I'm no math wizard, but I just wondered if this is possible without reading thru a table. Maybe interrupt?? |
|
|
|
|
|
|
(permalink) | ||
|
Quote:
Quote:
|
|||
|
|
|
|
|
(permalink) | |
|
The reason for GP0 and GP1 are both analogue, is that I will be reading both ports one after the other and if any of those two separate readings are greater then or less then set number, then LED goes on. I'm reading two different probes, and if either one or both is out of range, LED(alarm) goes off until voltage returns to acceptable levels.
Quote:
In any case,thanks for your reply. |
||
|
|
|
|
|
(permalink) |
|
What I meant, was that comparing to one constant is easy, but not so when you have a range to got thru.
|
|
|
|
|
|
|
(permalink) |
|
I asked you about GP3 because it's input only. So, if you planned to connect the LED there, you have to change pin.
EDIT: are you using assembly or higher-level language? Last edited by eng1; 22nd March 2007 at 01:31 PM. |
|
|
|
|
|
|
(permalink) | |
|
Quote:
I am using assembly, and even after 2 yrs, I still have some issues, when it comes to compare or math. |
||
|
|
|
|
|
(permalink) |
|
Ok. I am going to use 8-bit resolution to make it simple. For example, if you want to compare the A/D result (stored in ADRESH) with 3 V, you can write:
Code:
;select bank movf ADRESH, w ;select bank sublw 0x99 btfss STATUS, C goto LED_ON Last edited by eng1; 22nd March 2007 at 01:56 PM. |
|
|
|
|
|
|
(permalink) |
|
Ok Yes I understand your code. I will try that. Thanks a bunch.
|
|
|
|
|
|
|
(permalink) |
|
Try checking on the PICList, there's an entire section about comparisons - greater than, less than, greater than or equal - etc. There are also 8 and 16 bit versions, but for your purpose I would suggest configuring the A2D as 8 bit (one bit change in a register) and use 8 bit routines.
|
|
|
|
|
|
|
(permalink) |
|
Ok thanks Nigel, I will check Piclist.
|
|
|
|
|
|
|
(permalink) |
|
The subtract instructions in the pic chips are not very sensible. For example sublw does not equal subtract literal from word as you would expect. It actually executes subtract word from literal.
With this in mind, I thought I'd practice a little 16 bit comparison and came up with this, Code:
movlw low(0x015B) subwf Word,W movlw high(0x015B) btfss STATUS,C movlw high(0x015B)+1 subwf Word+1,W ; carry clear if word is less than 0x15B btfss STATUS,C goto LEDon movlw low(0x0266) subwf Word,W movlw high(0x0266) btfss STATUS,C movlw high(0x0266)+1 subwf Word+1,W ; carry set if word is greater or equal to 0x266 btfsc STATUS,C goto LEDon ; turn LED off here Mike. Edit, I had the led on at the wrong time. Last edited by Pommie; 22nd March 2007 at 03:11 PM. |
|
|
|
|
|
|
(permalink) |
|
P.S. the values are the voltages.
So, 0x015b = 1.7V 0x0266 = 3.0V |
|
|
|
|
|
|
(permalink) |
|
Thanks Pommie, I will try that, and unfortunately I'm at work right now, so my replies are pretty slow and far apart.
|
|
|
|
|
|
|
(permalink) |
|
Sorry to cut in,
But does this style of code work for 16F628 PIC's as well? I'm considering the same thing. Thanks |
|
|
|
|
|
|
(permalink) |
|
It will work on any of the pic chips.
Mike. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Microcontroller interface with ADC | revjam | Chit-Chat | 4 | 1st August 2008 08:21 AM |
| rms reading | mpj111 | General Electronics Chat | 3 | 10th July 2006 12:36 PM |
| is reading lots of schematics the best way to learn? | psasidisrcum | General Electronics Chat | 17 | 18th April 2005 08:57 PM |
| Specifications Applied | Caltech | General Electronics Chat | 1 | 25th December 2003 05:00 PM |
| A/D help steady reading in low range but bounces in high | usaf1 | Micro Controllers | 3 | 30th September 2003 01:14 AM |