voltage monitor


Closed Thread
Results 1 to 16 of 16

Thread: voltage monitor

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Question 12C672 code for your opinion

    Hello friends,

    I am posting this code for 12C672 which are OTP pics.
    I do not have the 12C672JW and UV eraser--not for armature like me !

    I have added my questions "???". I would appreciate your answers on these questions
    Each error will cost me one 12C672, so please see if these are OK:
    [ code ] code here [ /code ]
    Code:
    '**********************************************START*******
    '-----------------------------------------
    'Pic 12C672 TEST adopted from Rentron.com
    '
    'Trying to get 4 channel A/D conversion
    '
    ' and the book "Programming PIC Microcontroller with PicBasic"
    '
    ' and code samples in the great user forum of picbasic.co.uk
    '
    ' Will program in JDM board with IC-Prog 1.05e,Win98SE, Tecra CDM750 with com port - does not work in inspiron 700m e USB--RS232
    '
    ' WHICH OPTIONS DO I SELECT in IC-Prog:
    '  a) Oscillator-->"IntRC GP4" or "IntRC CLOCKOUT" ; I want to use the onboard 4MHz osc. ???
    '  b) Fuses---> "WDT" unchecked, "PWRT" checked, MCLR unchecked; Are these OK ???
    '
    ' Can it also be programmed with PonyProg--I am asking because there are less options than IC-Prog and
    ' it does not show the OSCCAL value for pic12C672<----???
    '-----------------------------------------
    
    
    
    '..8.......5
    '.-|-|-|-|-.
    '|PIC12C672|
    ''*|-|-|-|-'
    '..1.......4
    '
    'PIN Name  Use/Connection
    '1 Vdd  +5VDC
    '2 GPIO.5 N/C Serial output to PC/ another PIC
    '3 GPIO.4 (Channel 3) 1K Resistor to center of 5K Pot // 33k resistor between +ve and -ve of 1.5v battery OR a voltage divider with <= 5v
    '4 GPIO.3 N/C Not Connected
    '5 GPIO.2 (Channel 2) Same as GPIO.4
    '6 GPIO.1 (Channel 1) Same as GPIO.4
    '7 GPIO.0 (Channel 0) Same as GPIO.4
    '8 VSS  Ground
    
    '---------------INCLUDE FILES-------------
    
    Include "modedefs.bas"          'Include serial modes//Not mentioned in Rentron
    
    
    '--------------------FUSES---------------
    @ device pic12c672, INTRC_OSC_NOCLKOUT    	;4MHz internal oscillator
    @ device pic12C672, WDT_OFF			; Watch Dog Timer is OFF
    @ device pic12C672, PWRT_ON			;Power On RESET On ??? is it OK ??
    
    
    '???<---Any more fuses to setup--????
    '
    'TRISA <---? how to declare it here ?? Is it needed ?
    '
    
    '----------------DEFINITIONs and VARIABLES and SETUPS--------------
    Define OSCCAL_2K 1  'Set OSCCAL for PIC12C672 // for 12C671 it is OSCCAL_1k
    
    '???WHAT is the use/need of the following line IF I use the above line ---???
    OSCCAL = $58 'Got this by READING the PIC12C672 using IC-PROG;PonyProg does NOT show this <---EXTRA(???)
    
    DEFINE CHAR_PACING 100 'SEROUT pacing 0.1 millisecond
    
    RESULT var byte[4] 'Array for FOUR channels
    
    J var byte 'A/D channel number byte variable, this shortens the code
    
    ADCON1 = %00000000  'Set GPIO.0, GP1, GP2 and GP4 (NB NOT GP3) to ANALOG input, Vref=VDD, No pins left for DIGITAL I/O
    
    
    '-------------------PROGRAM STARTS HERE-------------------
    
    MAIN:
    
    FOR J = 0 to 3    		'Count 4 channels
    
    	'???<-->Shouldn't I set the ADCON0 as %11000001 to use the internal OSC, I want to use the internal OSC
    	'ADCON0=%10000001    	'Set A/D Fosc/32,[4MHz],Channel-0 = on <----???? For External clock?
    
    	ADCON0=%11000001        'Use the internal clock
    					'Do I need to do this every time a channel is read ????
    					'Any alternate ???
    					' %11xxxxxx  <---This means ADCS1(bit7)=1 and ADCS0(bit6)=1; see table by Rentron/data sheet
    					' %xxxxxxx1  <---This means ADON (bit0) = 1 ie. turn the A/D on
    	pauseus 10 'Wait for 10 u Sec for channel setup <---??? is the time OK?
    
    					'ADCON0.2 is bit2 which is the GO/DONE bit; see table by Rentron/data sheet
    	ADCON0.2=1			'Start conversion by setting GO/DONE-bit to HIGH
            '???Can ADCON0.2=1 be substituted with ADCON0=%11000101 <----?????
    
    	LOOP:
    		IF ADCON0.2 = 1 THEN 'Check if conversion completed
    			pauseus 5  'Wait for 5 micro second <---Is this time OK or should I increase it ??
    			GOTO LOOP
    		ENDIF
    	
    	RESULT[J] = ADRES
    
    NEXT
    		
            Pause 250              'Pause 1/4th sec so that conversion setup is done
            'In what format will the output go to pc ? Binary, floating, integer, hex ????
            'Is it possible to send in a format of xx.xxx volt(e.g. 3.456v or 11.123) ? i.e. with 3 points after decimal ?
            '
    	SEROUT GPIO.5,N2400,["@",RESULT[0],"#",RESULT[1],"#",RESULT[2],"#",RESULT[3],"#"]    'Send the value of conversion to PC Serial port; @ will be used in PIC-PIC serout/serin2
                                    'If you want to use baud rate above 2400, use external oscillator.
            Pause 250              'Pause 1/4th sec to let the Serial communication to complete; it takes much less than 1 sec
    GoTo MAIN
    
    
    
    '********************************************END*********
    Last edited by aftab; - 16th August 2007 at 04:44. Reason: pic12c62 corrected to pic12c672

  2. #2
    Join Date
    Apr 2007
    Posts
    26


    Did you find this post helpful? Yes | No

    Smile adcon0 not yet ok

    some modifications:
    Code:
    MAIN:
    
    FOR J = 0 to 3    		'Count 4 channels
    
    	'???<-->Shouldn't I set the ADCON0 as %11000001 to use the internal OSC, I want to use the internal OSC
    	'ADCON0=%10000001    	'Set A/D Fosc/32,[4MHz],Channel-0 = on <----???? For External clock?
    
            
    	'ADCON0= 65 + (J*8)  'Set A/D Fosc/8, and Set a/d = on (This is actually ADCON0=%01000001
    	        '65 = 1000001 channel 0,(GP0/AN0)
    		'73 = 1001001 channel 1,(GP1/AN1)
    		'81 = 1010001 channel 2,(GP2/AN2)
    		'89 = 1011001 channel 3,(GP4/AN3)
    
            '".....if you're using the internal ADC RC oscillator, you need to set the ADCON0 bits ADCS1, ADCS0 to 11.
            'Using the internal ADC clock is only desirable when running the PIC at low clock frequencies to conserve 
    	'power.  If you're using a 4MHz ceramic resonator, crystal or other clock source, you'll need to set these
    	' bits to either 01, or 10."--Rentron
    
    		
    	
       	'ADCON0= 129 + (J*8)  'Set A/D Fosc/32 Use internal 4MHz clock(8 usec to acquire data), and Set a/d = on
    		'129 = %10000001
    
       	ADCON0= 193 + (J*8)  'Use internal 4MHz clock(2-6usec to acquire data), and Set a/d = on
    		'193 = %11000001
    
    
    	'ADCON0=%11000001        'Use the internal clock
    					'Do I need to do this every time a channel is read ????
    					'Any alternate ???
    					' %11xxxxxx  <---This means ADCS1(bit7)=1 and ADCS0(bit6)=1; see table by Rentron/data sheet
    					' %xxxxxxx1  <---This means ADON (bit0) = 1 ie. turn the A/D on
    	pauseus 10 'Wait for 10 u Sec for channel setup <---??? is the time OK?

Similar Threads

  1. Voltage monitor and PWM control
    By StoneColdFuzzy in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th May 2009, 16:11
  2. Voltage monitor for car battery
    By passion1 in forum mel PIC BASIC Pro
    Replies: 50
    Last Post: - 23rd April 2008, 21:47
  3. Expanded Scale Voltmeter
    By Pic_User in forum Schematics
    Replies: 6
    Last Post: - 8th February 2008, 20:32
  4. Help with final project
    By OvERKiLL in forum General
    Replies: 4
    Last Post: - 15th December 2006, 20:35
  5. Help with DS2436 Voltage monitor
    By vladimir059@hot in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th October 2006, 16:39

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts