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.

Plz help building a voltmeter on PIC12F683

Status
Not open for further replies.
Nigel Goodwin said:
You're not showing all the circuit, what about the power supply and decoupling capacitors?.

Here is the full circuit. And I did powered up the PIC with 5V on VDD (Pin 1) and Ground to CSS (Pin 8).
 

Attachments

  • Schematic_full.JPG
    Schematic_full.JPG
    86.2 KB · Views: 527
Try 100uF or larger (a little larger) for C2.

Good-eye Nigel.

What is the power source? Wallwart or battery?

So you put in the breakpoint to halt the software and you still see it blink right? Or a LABEL: goto LABEL
 
Last edited:
mramos1 said:
Try 100uF or larger (a little larger) for C2.

Good-eye Nigel.

What is the power source? Wallwart or battery?

I'm using 12V motorcycle battery.

Attached is the screenshot of the oscilloscope diagram how the signal looks llike on pins 6 and 7. I don't think the problem is related to the power source.
 

Attachments

  • Oscilloscope.JPG
    Oscilloscope.JPG
    83.6 KB · Views: 250
Attached is a little 5 sec movie I captured from the screen with the circuit in action.

I'm about to go postal... :mad:
 

Attachments

  • circuit_in_action.zip
    302.1 KB · Views: 173
Sorry, I meant 100uF on C2 only, .1 on C1. But a battery should be fine either way.

Have you actually built this? Or is it all simulation (grant it that was pretty cool)?

Did you drop the scope on the input pin and make sure it is not moving around (I see the voltage on the video says it is). Can you step through the software and get a hint where it is doing the toggle?

I load the list files sometimes with compiler code and step and many times see the problem right away.

Anyway when I have weird things happen with PICS, it is always something simple I missed. Not turning off something, MCLR, CMCON, ADCON1, noise, etc.

Do not give up, others will pop in and help you find it. I just do not see it and no time to dig out datasheet and build one.
 
mramos1 said:
Sorry, I meant 100uF on C2 only, .1 on C1. But a battery should be fine either way.

Have you actually built this? Or is it all simulation (grant it that was pretty cool)?
Yes, I have it built exactly same way. Same effect.

mramos1 said:
Did you drop the scope on the input pin and make sure it is not moving around (I see the voltage on the video says it is). Can you step through the software and get a hint where it is doing the toggle?
I'm using simplified programm, it doesn't actully uses any input. It just tries to turn 2 LEDs on at the same time. See below.

mramos1 said:
I load the list files sometimes with compiler code and step and many times see the problem right away.
I haven't figure out a vay to step through teh program yet...

mramos1 said:
Anyway when I have weird things happen with PICS, it is always something simple I missed. Not turning off something, MCLR, CMCON, ADCON1, noise, etc.
That's what I assume also. That is where I need help.

mramos1 said:
Do not give up, others will pop in and help you find it. I just do not see it and no time to dig out datasheet and build one.

Thanks, I'll try ;)

Here is the code version running on the video:
Code:
@ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,PROTECT_ON

GrnLED  VAR    GPIO.0   
RedLED  VAR    GPIO.1   

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

DISABLE INTERRUPT

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:        
    
        HIGH GrnLED
        PauseUs(10)
        HIGH RedLED
        PauseUs(500)
        
goto start
 
I d'nt know this pgm language, but you must disable comparator input and AD analog input for pins GP0 and GP1 !

CMCON.0 = 1
CMCON.1 = 1
CMCON.2 = 1

ANSEL.0 = 0
ANSEL.1 = 0
 
Ok. Finally I made it work. Thanks for all your replies! CMCON0 was the culpit. Below is the working code.

How can I convert ADC rconversion result (VAR Vin) into the actual number of volts? Is there a formula to do so? I noticed it's not a linear dependency. Could anybody point me in the right direction?

Code:
@ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,PROTECT_ON

GrnLED  CON    0        ' Green LED   
RedLED  CON    1        ' Red LED
Vin        VAR    BYTE     ' Allocate A/D variable  

DEFINE OSC 8
DEFINE ADC_BITS 8		' Use 10-bit A/D as 8-bit A/D
DEFINE ADC_CLOCK	3	' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS	50	' Set sampling time in uS   
DISABLE INTERRUPT

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

ANSEL = %00111000       ' Set AN3 analog, rest digital
CMCON0 = 7              ' Analog comparators off
                                              
'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0

PAUSE 10
start:        
    
    ADCON0.1 = 1        ' Start conversion
    WHILE ADCON0.1 = 1  ' Wait for conversion to finish           
        PAUSE 10   
    WEND
    Vin = ADRESH        'Write conversion result
    PAUSE 10 
    
    'Display results
    IF Vin < 70 THEN
        LOW GrnLED
        HIGH RedLED          
    ENDIF
    IF Vin > 69 AND Vin < 120 THEN
        HIGH GrnLED 
        HIGH RedLED
    ENDIF
    IF Vin > 119 AND Vin < 180 THEN
        HIGH GrnLED 
        LOW RedLED
    ENDIF
    IF Vin > 179 THEN
        LOW GrnLED 
        TOGGLE RedLED
    ENDIF
    PAUSE 250           
        
GOTO start
 
Last edited:
MrSpock said:
How can I convert ADC rconversion result (VAR Vin) into the actual number of volts? Is there a formula to do so? I noticed it's not a linear dependency. ]

It is a linear function, 0V should give a 0 output, and a voltage equal to Vref (5V in your case) should give 1023 out. So multiply it by 5, then divide by 1023, to give the result in volts.
 
Nigel Goodwin said:
It is a linear function, 0V should give a 0 output, and a voltage equal to Vref (5V in your case) should give 1023 out. So multiply it by 5, then divide by 1023, to give the result in volts.

Hmm... That means I'm doing something wrong again. The following code always gives me less than 2 volts reading. :confused:

Code:
@ DEVICE PIC12F683,MCLR_OFF,INTRC_OSC_NOCLKOUT,WDT_OFF,BOD_OFF
@ DEVICE PWRT_ON,FCMEN_OFF,IESO_OFF,PROTECT_ON

GrnLED  CON    0        ' Green LED   
RedLED  CON    1        ' Red LED
Vin     VAR    BYTE     ' Allocate A/D variable  
Sample  VAR    WORD

DEFINE OSC 8
DEFINE ADC_BITS 8		' Use 10-bit A/D as 8-bit A/D
DEFINE ADC_CLOCK	3	' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS	50	' Set sampling time in uS   
DISABLE INTERRUPT

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

ANSEL = %00111000       ' Set AN3 analog, rest digital
CMCON0 = 7              ' Analog comparators off
                                              
'GPIO port pins 0, 1 as outputs
TRISIO.0 = 0
TRISIO.1 = 0

PAUSE 10
start:        
    
    ADCON0.1 = 1        ' Start conversion
    WHILE ADCON0.1 = 1  ' Wait for conversion to finish           
        PAUSE 10   
    WEND
    sample = ADRESH        'Write conversion result
    PAUSE 10 

    Vin = sample * 5 / 1023    
    
    'Display results
    if Vin < 2 then                
        LOW GrnLED
        HIGH RedLED          
    endif
    if Vin > 2 AND Vin < 3 then
        HIGH GrnLED 
        HIGH RedLED
    endif
    if Vin > 3 AND Vin < 4 then
        HIGH GrnLED 
        LOW RedLED
    endif
    if Vin > 4 then
        LOW GrnLED 
        TOGGLE RedLED
    endif
    Pause 250           
        
goto start

Edit: Updated code to full version
 
Last edited:
Do you know if the voltage on that pin is over 2 volts (take a meter to it). What value is the PIC returning and what voltage do you have?
 
mramos1 said:
Do you know if the voltage on that pin is over 2 volts (take a meter to it). What value is the PIC returning and what voltage do you have?

Yes, I have a voltage dividing potentiometer attached to the input (Pin 3). It gives 0V to 5V voltage range. I confirmed it with the voltmeter.

Unfortunatelly I don't know how to debug the circuit. Would be nice to see the actual value of the conversion result while circuit is running.
 
Last edited:
MrSpock said:
Yes, I have a voltage dividing potentiometer attached to the input (Pin 3). It gives 0V to 5V voltage range. I confirmed it with the voltmeter.

Unfortunatelly I don't know how to debug the circuit. Would be nice to see the actual value of the conversion result while circuit is running.

Use a spare pin as a serial output port, squirt it out to your PC and display it in HyperTerminal.
 
Nigel Goodwin said:
Use a spare pin as a serial output port, squirt it out to your PC and display it in HyperTerminal.

Thanks Nigel, it's a good adea! Do you have any URL with details how to do that? Right now I'm researching how to hook up a serial LCD in my simulator. Has anybody seen any cirtcuits/programms for "Serial LCD Backpack"? I've seen lots of references on the web, but can't find the circuit.
 
It's easy to build your own, just a PIC feeding an LCD.

As you're using a particular BASIC compiler you're rather restricted in your choice of examples - the vast majority of the code out there is assembler.
 
Status
Not open for further replies.

Latest threads

Back
Top