Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

AD problem... update.

Status
Not open for further replies.
That's exactly what I'm thinking. I have the chip in the firefly, and it has an AD input, and I run this input from 0-5v and then I use debug to get the values from ADRESH that is in the chip in the circuit. Isn't that what it's supposed to do?

If others have the correct reading in adresh, why don't I?
I have to be certain it works before I go any further.
 
Last edited:
I know that you are using Vdd and Vss as positive and negative reference for the AD converter.

Code:
		movlw	b'0'<<ADFM|b'1'<<ADCS2|b'00'<<VCFG0
		movwf	ADCON1;

but are you sure that you have enough capacitance on the voltage reference, which is in this case the supply?

I found, when using a separate reference, that 10 nF wasn't enough and the reference dipped badly just as the measurement was taken. That was on an 18F PIC but I think the AD converters work the same.

It can also help to have capacitors on the analog signal. It can't hurt on a slow moving signal like from a potentiometer.
 
I'm using the firely, and I assume it is built correctly. You could be right, there were some problems with this programmer before, minor ones mind you, but still. The fact that lowering the pot resistance changes the values in ADRESH does point to a problem. The values are not dipping though they are top heavy, running high. That's why I want to get in touch with Bill and have him take a look at it. And that's why I want to program directly. Get a outside AD input and read the adresh. Once I am certain the program is running OK then I can use firefly to program the chips, it doesn't matter if the program runs OK.
 
Last edited:
That's exactly what I'm thinking. I have the chip in the firefly, and it has an AD input, and I run this input from 0-5v and then I use debug to get the values from ADRESH that is in the chip in the circuit. Isn't that what it's supposed to do?

It's not reality - don't run it as a debugger, program the chip to do something, and run it on it's own.

If others have the correct reading in adresh, why don't I?
I have to be certain it works before I go any further.

Probably no one else is using a debugger to read it?, Eric is just using a simulator.
 
Not sure if debug can be effecting your readings or not but you might consider formatting the ADC values as ASCII and send them out the 16F88 serial port to Hyperterminal.

Mike
 
That could very well be what the problem is.

Then I should be using the simulator too.
How do I use the simulator to get AD results?
I only know how to use the debugger.

Formatting ADC values as ascii and send them through the serial port... well if it comes to that I just might do that. It's a good idea. But I want to try the sim first. If the sim works, then I'll build the prototype.
 
Last edited:
Not sure what to tell you. I've been experimenting for 5 years now and I've never used a debugger, just a serial connection to Hyperterminal.

Mike
 
I clicked on the sim and ran it, and got;

ADC-W0001: Tad time is less than 1.60us
ADC-W0008: No stimulus file attached to ADRESL for A/D.


I guess I have to add a stimulus to the pin, I'm looking for that on MPLAB, can't find it yet. And add Tad time because it's too short.
 
Last edited:
I want to make sure I'm getting the reading I need before building the rest of the circuit. I want to make sure the chip is working right. So I run AD input and read the ADRESH it's supposed to be linear and it's not. Others have it working right, so I want to get it right also, to be sure everything is working as it should. I hate having areas not fully cleared up. This AD reading is wrong, just for me, and that's not the way I work. It works for others, so I have to find out what I'm doing wrong, I have to work on the ADRESH output also, and I need the output to work with, so the output must be working so I can continue with the project.

What is a hyperterminal, and can you cue me a little about how to format the ADRESH to output to TX...?
 
Last edited:
Sure. Send it to Hyperterminal (a terminal package that ships with Windows) as ASCII hex or ASCII decimal characters. Perhaps something like this;

Code:
;
PutADRESH
        movf    ADRESH,W        ; 0..255                          |B0
        call    PutByte         ; send it as ASCII Hex, 00..FF    |B0
        movlw   ' '             ;                                 |B0
        call    Put232          ; send space char                 |B0
        movf    ADRESH,W        ; 0..255                          |B0
        call    PutDec          ; send it as ASCII Dec, 000..255  |B0
        movlw   '\n'            ;                                 |B0
        call    Put232          ; send line feed                  |B0
        movlw   '\r'            ;                                 |B0
        call    Put232          ; send return                     |B0
        return                  ;                                 |B0
;
;  Print byte in W as two ASCII nybbles
;
PutByte movwf   Temp            ; save byte                       |B0
        swapf   Temp,W          ; swap nybbles in W               |B0
        call    Hex2Asc         ; process left nybble             |B0
        movf    Temp,W          ; process right nybble            |B0
Hex2Asc andlw   b'00001111'     ; mask off left nybble            |B0
        addlw   a'6'            ; 0-9>36-3F, A-F>40-45            |B0
        btfsc   STATUS,DC       ; A..F?  no, skip, else           |B0
        addlw   h'07'           ; A-F (40-45) > 47-4C             |B0
        addlw   0-6             ; '0'..'9' or 'A'..'F'            |B0
        goto    Put232          ; print ASCII nybble              |B0
;
;  Print byte in W as three ASCII chars, 000..255
;
PutDec
        clrf    Tens            ; 15 words                        |B0
        clrf    Huns            ;                                 |B0
div10a
        movwf   Ones            ;                                 |B0
        incf    Tens,F          ;                                 |B0
        addlw   -10             ;                                 |B0
        bc      div10a          ;                                 |B0
        decf    Tens,W          ;                                 |B0
div100
        movwf   Tens            ;                                 |B0
        incf    Huns,F          ;                                 |B0
        addlw   -10             ;                                 |B0
        bc      div100          ;                                 |B0
        decf    Huns,W          ;                                 |B0
        iorlw   '0'             ; make it ASCII '0'..'9'          |B0
        call    Put232          ; print Huns                      |B0
        movf    Tens,W          ;                                 |B0
        iorlw   '0'             ; make it ASCII '0'..'9'          |B0
        call    Put232          ; print Tens                      |B0
        movf    Ones,W          ;                                 |B0
        iorlw   '0'             ; make it ASCII '0'..'9'          |B0
        goto    Put232          ; print Ones                      |B0
 
Last edited:
Not as easy as sending ADRESH to the pin but I see that's another thing (can of worms...) I might have to learn eventually. I would like to solve my AD problem with the sim first though. If the sim works, I'll build the circuit, and run the rest of the code through and finish debugging it.

I'm sure the sim is not that hard to figure out, I'll spend some time tomorrow on it. Read help files etc. The code is apparently OK, so I just have to see it with my own eyes, to make sure I don't get any surprises after I put the whole thing together.
 
I get this when I run the sim...:

ADC-W0001: Tad time is less than 1.60us

Is that time too short for proper acquisition of signal?
 
Section 12.2 "Selecting the A/D Conversion Clock" suggests you must select the Clock for a TAD time no less than 1.6 usecs and no greater than 6.4 usecs.
 
Last edited:
Maybe that's what the problem is.

The set up for ASCON0 is Fosc/2, Fosc/8, and Fosc/32. Which one should I use? I don't quite understand what Fosc means. I know it's oscillator F, divided by "2" but I don't know what the oscillator runs at, I have OSCON set up at 42.

What should I do to increase the Tad to proper value?
 
Last edited:
I want to make sure I'm getting the reading I need before building the rest of the circuit. I want to make sure the chip is working right. So I run AD input and read the ADRESH it's supposed to be linear and it's not. Others have it working right, so I want to get it right also, to be sure everything is working as it should. I hate having areas not fully cleared up. This AD reading is wrong, just for me, and that's not the way I work. It works for others, so I have to find out what I'm doing wrong, I have to work on the ADRESH output also, and I need the output to work with, so the output must be working so I can continue with the project.

What is a hyperterminal, and can you cue me a little about how to format the ADRESH to output to TX...?

Try reading my tutorials, they show not only how to use the A2D, but also how to display it as ASCII on an LCD or send out as serial to a PC.

Like Mike I've never used a debugger either, nor have I ever uses a simulator, but I've been using PIC's for a LONG time now - back from when it was all DOS based only, and there was only one EEPROM based PIC, the 16C84.
 
Maybe that's what the problem is.

The set up for ASCON0 is Fosc/2, Fosc/8, and Fosc/32. Which one should I use? I don't quite understand what Fosc means. I know it's oscillator F, divided by "2" but I don't know what the oscillator runs at, I have OSCON set up at 42.

What should I do to increase the Tad to proper value?

hi Robert,
Have you actually programmed a PIC with that program, in 'release' mode and tried it, with an external pot on the adc input.? OR are you talking about just simulation, using MPLAB.

What is the frequency of the PIC crystal or if you are using the PIC's internal osc, whats freq is it set for.

I dont a have a 16F88 to hand to try your program, only the OS sim.
 
Thanks Nigel, I'll do that. I decided to follow your advice and continue debugging the program and assume the AD is working properly. I'm almost finished. Then I'll try it in circuit.

Hi Eric, I'm not sure what frequency I'm using, I'm running the OSCON register at 42. It's my first PIC program, so I have a lot to learn. I have not programmed the chip and test it in release mode, only in debug mode. Maybe I should test it in release mode, it might make a difference. I test it in debug mode, on the firefly, which is an experimenter's board. I would like to do this like Futz set it up. But that'll be after I learn my baby steps.

I have a lot to learn about the programmer, the chip, the language, the tools of the trade, etc. lots of information to assimilate and I appreciate all the help you are providing guys, it's helped me a lot. I am almost ready to put this in production now, once I'm done with the program. I have run it a few times right through, and it performs quite nicely, notwithstanding my concerns with the AD, I still have a few bugs to iron out yet. It's over 100 lines of code, and I am quite satisfied with the way it looks and works. I'm looking forward to my next project.
 
Last edited:
hi,

Is that OSCCON = 0x42 .?

If yes, I make that 1MHz internal.?
 

Attachments

  • esp03 Aug. 10.gif
    esp03 Aug. 10.gif
    35.3 KB · Views: 135
That would be correct. It used to be 72, but I changed it. I wonder if it's still too fast.

Where should I add more time?
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top