News:

;) This forum is the property of Proton software developers

Main Menu

PIC16F914 ADC0 Warning in Proteus Simulation

Started by thetrueman, Mar 27, 2022, 10:11 AM

Previous topic - Next topic

thetrueman

Hi,

I am just configuring PIC16F914 ADC with simple command ADValue = ADIn 0 but when simulate in Proteus there is continuous warning messages :[PIC16 ADC] PC=0x002B. PORTA<0> is not configured as an analog input. [U1]

What can be a problem while this code with all other program works fine on 16F887. I am sure the prblem is in Registers Configurations because this PIC has LCD Registers. Please advise. Thanks.

Device = 16F914
    XTAL = 4
   
    ASM
    CONFIG_REQ
    __CONFIG INTOSCIO & WDT_OFF & PWRTE_ON & MCLRE_OFF & CP_ON & CPD_OFF & BOD_OFF & IESO_OFF & FCMEN_OFF & DEBUG_OFF
'    __CONFIG _CONFIG2, BOD_OFF & IESO_OFF & FCMEN_OFF & DEBUG_OFF
    ENDASM
   
ALL_DIGITAL = True
PORTB_PULLUPS = True
    IOCB = %00000000    'Individual PORTB Interrupt-on-Change Selection
WPUB = %11110000    'Individual PORTB Pull-up Selection   
    On_Interrupt InterruptCheck
     
    PORTA = 0 : PORTB = 0 : PORTC = 0 : PORTD = 0 : PORTE = 0 
TRISA = %11011111   'PORTA.4 is Open Drain Output
TRISB = %11110000
    TRISC = %00000000
    TRISD = %00000000
    TRISE = %00001000   'Bit4 can be Reset or GPIO Pin.   
PORTA = 0 : PORTB = 0 : PORTC = 0 : PORTD = 0 : PORTE = 0 

 
'===General Variables
    Dim MemOffset As Word       'General Purpose Byte Variable 
    Dim ADValue As Word         'General Purpose Word Variable

'--------------------------------------
    DelayMS 20 : Clear
'--------------------------------------
       
'===Interrupts Configuration
    OPTION_REG.3 = 0    'PSA      'Timer0 Pre-Scaler Select Bit, 0 = Timer0, 1 = WDT
    OPTION_REG.5 = 0    'T0CS     'Timer0 Clock Source Select Bit, 0 = Internal, 1 = External T0CKI
    OPTION_REG.6 = 0    'INTEDG   'RB0/INT Interrupt on Edge, 0 = Falling Edge, 1 = Rising Edge
    Symbol PS0 = OPTION_REG.0     'Pre-Scaler Rate Seletion Bit 0
    Symbol PS1 = OPTION_REG.1     'Pre-Scaler Rate Seletion Bit 1
    Symbol PS2 = OPTION_REG.2     'Pre-Scaler Rate Seletion Bit 2
    PS0 = 0 : PS1 = 0 : PS2 = 0   '1:2 Ratio of Timer 0 Counting
    Symbol RBIF = INTCON.0        'PORTB (RB4-7) Change Interrupt Flag, 1 = PORTB Pin Change Interrupt Occurred (must be cleared in software)   
    Symbol INTF = INTCON.1        'External Interrupt Flag, 1 = External Interrupt Occurred (must be cleared in software)
    Symbol T0IF = INTCON.2        'Timer0 Overflow Interrupt Flag
    Symbol RBIE = INTCON.3        'PORTB (RB4-7) Change Interrupt, 1 = Enable, 0 = Disable
    Symbol INTE = INTCON.4        'RB0/INT External Interrupt, 1 = Enable, 0 = Disable
    Symbol T0IE = INTCON.5        'Timer0 Interrupt, 1 = Enable, 0 = Disable
    Symbol PIE  = INTCON.6        'Peripheral Interrupt, 1 = Enable, 0 = Disable 
    Symbol GIE  = INTCON.7        'Global Interrupt, 1 = Enable, 0 = Disable

'===Timer 1 Interrupt Variables
    Symbol T1INTE  = PIE1.0     'Timer1 Interrupt Enable
    Symbol T1INTF  = PIR1.0     'Timer1 Interrupt Flag
    Symbol T1ON    = T1CON.0    'Timer1 ON/OFF
    Symbol TMR1CS  = T1CON.1    'TMR1 Clock Source Select   
    Symbol T1SYNC  = T1CON.2    'Timer1 External Clock Input Synchronization Control Bit 
    Symbol T1OSCEN = T1CON.3    'LP Oscillator Enable Control Bit
    Symbol T1CKPS0 = T1CON.4    'Timer1 Input Clock Prescale Select bits
    Symbol T1CKPS1 = T1CON.5    'Timer1 Input Clock Prescale Select bits
    Symbol Timer1  = TMR1L.Word 'Timer1 Value Symbol
    Dim TimerOffset As Word
    T1CON = %00000100           'Bit0=T1 Enable, Bit1=Ext. Clk, Bit2=No Clk Syncronization
    T1CKPS0 = 1 : T1CKPS1 = 1   '1:8 Ratio of Timer 1 Counting

'===Timer 2 Interrupt Variables
    Symbol T2INTE  = PIE1.1     'Timer2 Interrupt Enable
    Symbol T2INTF  = PIR1.1     'Timer2 Interrupt Flag
    Symbol T2ON    = T2CON.2    'Timer2 ON/OFF
    Symbol T2CKPS0 = T2CON.0    'Timer2 Input Clock Prescale Select bits
    Symbol T2CKPS1 = T2CON.1    'Timer2 Input Clock Prescale Select bits
    Symbol T2OTPS0 = T2CON.3    'Timer2 Output Postscale Select bits
    Symbol T2OTPS1 = T2CON.4    'Timer2 Output Postscale Select bits
    Symbol T2OTPS2 = T2CON.5    'Timer2 Output Postscale Select bits
    Symbol T2OTPS3 = T2CON.6    'Timer2 Output Postscale Select bits
    T2CKPS0 = 1 : T2CKPS1 = 1
    T2OTPS0 = 1 : T2OTPS1 = 1 : T2OTPS2 = 1 : T2OTPS3 = 1
    PR2 = 243                   '130 = 30Hz and 244 = 16Hz Frequency 

'===Analog to Digital Converter Constants
    ADIN_RES = 10
    ADIN_TAD = FRC
    ADIN_STIME = 100
    CMCON0 = 7               'Disable Comparators
    CMCON1 = 1               'Comparator Output Control
    VRCON  = %00000000       'Comparator Voltage Reference Control
    ADCON0 = %10000001       'A/D Bit0 for A/D Enable
    ADCON1 = %01110000       'Bit4-6 for A/D Oscillator FRC
    ANSEL  = %00000001       'A/D Selection PIN Configuration
   
'===Seven Segment Data LED Display     
'    Data $C0,$F9,$A4,$B0,$99,$92,$82,$F8,$80,$90      'For Common Anode Display
    Data $3F,$06,$5B,$4F,$66,$6D,$7D,$07,$7F,$6F      'For Common Cathode Display

'===Seven Segment Data LCD Display     
    LCDCON = 0     'LCD Control Register 0=Disable 1=Enable
    LCDPS  = 0     'LCD PreScaler Register
    LCDSE0 = 0     'LCD Segments Register
    LCDSE1 = 0     'LCD Segments Register
    LCDSE2 = 0     'LCD Segments Register

    GoTo Initialise

'===Initialise the Program...   
Initialise:
    DelayMS 50 : Clear
'===Reading EEPROM Parameters.
    MemOffset = ERead 0      '1 Byte(s)
    If MemOffset > 250 Then MemOffset = 0   
       
DelayMS 50     'This Delay should be for Finalizing the EEPROM Operation.
'--------------------------------------
    TimerOffset = 34286      '3035 = 2Hz or 1 Pulse per Half Second
    '34286=4Hz - 40536=5Hz - 44703=6Hz - 49911=8Hz - 53035=10Hz                                     
    '57202=15Hz - 59285=20Hz - 61369=30Hz - 62410=40Hz - 63035=50Hz 
           
'----------Peripheral Interrupts----------'
    INTCON = 0          'All Interrupts Disabled   
    INTE = 0            'PortB.0 Interrupt Enable
    RBIE = 0            'PortB.4-7 Interrupt on Change Enable 
    T0IE = 0            'Timer 0 Interrupt Enable
    T1ON = 0            'Timer 1 ON/OFF
    T1INTE = 0          'Timer 1 Interrupt Enable
    T2ON = 1            'Timer 2 ON/OFF
    T2INTE = 1          'Timer 2 Interrupt Enable
    PIE = 1             'Peripheral Interrupt Enable, 1 = Enable, 0 = Disable
    GIE = 0             'Global Interrupt Enable, 1 = Enable, 0 = Disable 
'----------Peripheral Interrupts----------'   

    DelayMS 10 
    GoTo Start
   
Start:

    GoSub ReadADC
    GoTo Start
'--------------------------------------

'--------------------------------------     
'===Getting Pressure...
ReadADC:
    ADValue = ADIn 0 'Conversion of AD Channel 0

    Return     
   
'--------------------------------------

InterruptCheck:     
    If INTF = 1 Then INTF = 0       
    If RBIF = 1 Then RBIF = 0
    If T1INTF = 1 Then T1INTF = 0
       
    If T2INTF = 1 Then
       T2INTF = 0       
    EndIf

    Context Restore 
End

Maxi


RGV250

Hi,
QuoteAll digital= true line problem i think
Should not be a problem as the analog pin is set up later.
QuoteADCON0 = %10000001       'A/D Bit0 for A/D Enable

Have you tried another pin such as A.5 which does not have anything to do with LCD.

Bob

top204

Remember, since about 6 or 7 years ago, the compiler sets all pins to digital before a user program starts, and disables comparators etc... The SFRs can be seen at the end of each device's .def file. For example, on the PIC16F914 device, the .def file has:

'
'-----------------------------------------------------------------------------------
' Make the device's I/O pins digital (if required) before the main program starts
' This can be added too by the user and shared on the forum
'
#IfnSym __SYSCOM_LIBRARY_OFF_       ' Has the library been disabled in the compiler?
    ANSEL = $00
    CMCON0 = $07
#EndIfSym

The Adin command does not set a pin to analogue, it sets up the channel to use and performs the mechanism to read the ADC. This means that to use a pin as analoge, it must be set up as analogue using, whatever, SFR is required for that particular device. For the PIC16F914 device, it looks like it is the SFR ANSEL.

The All_Digital declare has not been valid for quite a few year now, and the compiler ignores it, because the pins are already set for digital mode.


Maxi

Hi @top204
Les, have any list ignores old commands like all_digital?

thetrueman

Hi,

Thanks for suggestions. I did experiments and found that All Digital = True is not a problem.
The Problem is ADIN 0 command which don't work correctly even by changing ADC channel.

Quote from: top204 on Mar 27, 2022, 01:45 PM'-----------------------------------------------------------------------------------
' Make the device's I/O pins digital (if required) before the main program starts
' This can be added too by the user and shared on the forum
'
#IfnSym __SYSCOM_LIBRARY_OFF_      ' Has the library been disabled in the compiler?
    ANSEL = $00
    CMCON0 = $07
#EndIfSym

I could not found above code and .def file but I used bit bang method to read the ADC and it removed the error in simulation and got the correct ADC reading in simulation.

ANSEL  = %00000001
DelayUS 50 : GoDone = 1
While GoDone = 1 : Wend

The ADC problem almost solved but new problem arrived and ERead command is not working to get data from internal EEPROM. Is there any bit bang way to read EEPROM? Thanks.

tumbleweed

I don't know how you even got the code in post #1 to compile.
Maybe that syntax was valid at some point in the past, but not now.

Anyway, just so you're clear, this code:
ANSEL  = %00000001
DelayUS 50 : GoDone = 1
While GoDone = 1 : Wend
doesn't select ADC channel 0... it relies on the current setting of ADCON0

Yasin

This is registers check.
LCDPS = 0
LCDSE0...5 = 0
This is registers disabled you are sure. Check them again please.

thetrueman

Quote from: tumbleweed on Mar 28, 2022, 03:43 PMdoesn't select ADC channel 0... it relies on the current setting of ADCON0
It depends on ANSEL Register to select Channel. ADCON0 is Control Register.

@Yasin Yes all LCD Registers are 0 as shown in Post #1.

Analog Reading matter is now clear by Bit Banging BUT now ERead command is not working. Can anybody elaborate on this matter. Thanks.

tumbleweed

QuoteIt depends on ANSEL Register to select Channel. ADCON0 is Control Register.
No it doesn't. ANSEL sets the pin mode to analog or digital.
The ADC channel select is in bits CHS2:CHS0 of the ADCON0 register.

Yasin

PIC16F914 item I simulate. There is two important error. This a simulation error. Compile for Same core PIC16F916 thats ok. No problem. Other error, defect using interrupt. "Context Save" none.

InterruptCheck:   

    <<<Context Save>>>

    If INTF = 1 Then INTF = 0     
    If RBIF = 1 Then RBIF = 0
    If T1INTF = 1 Then T1INTF = 0
     
    If T2INTF = 1 Then
      T2INTF = 0     
    EndIf

    Context Restore
End

thetrueman

Quote from: tumbleweed on Mar 28, 2022, 09:20 PMNo it doesn't. ANSEL sets the pin mode to analog or digital.
The ADC channel select is in bits CHS2:CHS0 of the ADCON0 register.

Oh sorry you are right. Things were mixed-up in mind. But in my first post I set AD Registers properly but "ADIn 0" command did not worked which I solved different way. Thanks.

@Yasin these syntax type errors are handled now and ADC problem also solved BUT at the moment only problem is EEPROM reading with ERead Command. Thanks for support.

Yasin

I actually meant the "EREAD" command. When you simulate the file you compiled for 16F914 using 16F916, everything works correctly. I think this problem is a simulation error.
Note: I assume you are running the simulation with ISIS.

top204

#13
I have ran tests and it looks like Yasin is correct, and the Proteus/Isis simulator is at fault. Never, never trust simulators 100%. I just wish there were more simulators available, because Isis seems to be getting worse at simulating the finer parts of microcontrollers as time goes by. :-(

Just to make sure, I created a procedure to read on-board EEPROM, and it does not work in the Isis simulator, yet it follows the code in the device's datasheet to the letter, as does the compiler's Eread library routine. It returns a value of 128, instead of 1. I have listed my test code below. It also shows the ADin command working as expected:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
    Device = 16F914                             ' Tell the compiler what device is being compiled for
    Declare Xtal = 4                            ' Tell the compiler what speed the device will be operating at
'
' Setup USART1
'   
    Declare Hserial_Baud = 9600
    Declare HRSOut_Pin = PORTC.6
'
' Create some variables
'  
    Dim wADC_Result As Word
    Dim ByteOut As Byte
'
' Create some data in on-board EEPROM
'
EData 1, 2, 3, 4
  
'-------------------------------------------------------------------
Main: 
    ADCON0bits_ADFM = 1                     ' Right justify the ADC result for 10-bit operation
    ADCON1 = %01110000                      ' ADC Frc clock    
    ANSELbits_AN0 = 1                       ' Make PORTA.0 analogue
       
    ByteOut = EERead(0)                     ' Read from EEPROM offset address 0
    HRSOutLn "EE Address 0 = ", Dec ByteOut ' Transmit the decimal value to a serial terminal
          
    Do                                      ' Create a loop
        wADC_Result = ADIn 0                ' Read AN0
        HRSOutLn "ADC = ", Dec wADC_Result  ' Transmit the decimal ADC value to a serial terminal (0 to 1023)      
        DelayMS 500                         ' A delay so the serial terminal does not get flooded with values
    Loop                                    ' Do it forever   

'-------------------------------------------------------------------
' Read a byte from on-board EEPROM
' Input     : pOffset holds the EEPROM offset address to read
' Output    : Returns the byte read from EEPROM
' Notes     : Follows the specs in the datasheet
'
Proc EERead(pOffset As Byte), Byte
    EEADRL = pOffset                    ' Offset address to read from
    EECON1 = 0                          ' Setup to access on-board EEPROM
    EECON1bits_RD = 1                   ' Set to read the EEPROM
    Result = EEDATL                     ' Return the EEPROM Data
    EECON1bits_EEPGD = 1                ' Setup to access flash memory before leaving the procedure
EndProc

thetrueman

Quote from: Yasin on Mar 29, 2022, 07:42 AMI actually meant the "EREAD" command. When you simulate the file you compiled for 16F914 using 16F916, everything works correctly. I think this problem is a simulation error.
Note: I assume you are running the simulation with ISIS.

I checked in ISIS and found that 16F913 and 16F914 are not reading EEPROM but 16F916 and 16F917 are reading and writing EEPROM.

Also I found one thing about ADIn 0 that why it was not working. The reason was in the following code in the first post.

'===Initialise the Program... 
Initialise:
    DelayMS 50 : Clear

Here Clear command clears all the Registers and when I removed this command the good old ADIn command works normally. BUT same code is running fine with 16F887 with Clear command. Sometimes strange things happens without any clue but definitely have some logic. Now only to focus on EEPROM.

@top204 I could not guess which compiler your code is for because in good old ProtonBasic 3.2.5.5, it does not seem to be compatible. Thanks for all support.  :)

top204

#15
I can only give advice and code samples for the Positron compilers. The Proton compilers do not exist anymore.

The compilers have come a long way since they were Proton, and the Clear command is one of the many improvements made, so it clears the user RAM before a user's program starts and does not disturb any variables given values prior to it being issued in the program. The Clear command has never cleared any SFRs, but it used to clear some compiler system variables that were "sometimes" needed with some commands, because they resided in RAM.

Now, the Clear command can be placed anywhere in the listing, and as long as it comes into the view of the compiler's parser, RAM will be cleared at the very start of a program's operation and not disturb anything used by the library or the user's program.

Yasin

Quote from: thetrueman on Mar 29, 2022, 07:41 PMI checked in ISIS and found that 16F913 and 16F914 are not reading EEPROM but 16F916 and 16F917 are reading and writing EEPROM.

Also I found one thing about ADIn 0 that why it was not working. The reason was in the following code in the first post.
...
...
Now only to focus on EEPROM.

If I'm not mistaken, the problem is in the simulation. This is finalized. So in reality, there is no test you do. If that's the case, you're wasting your time. Because this is totally ISIS simulation error. Don't rely too much on the simulation. Physically test the hardware. If you persistently want to simulate with 16F914. Make sure model 16F916 is working. Then solve model 16F916 in the schematic drawing. Rearrange the pin numbers, create a new model file named 16F914. Use this. But remember this is just deceiving yourself.

Yasin

Quote from: thetrueman on Mar 29, 2022, 07:41 PMI could not guess which compiler your code is for because in good old ProtonBasic 3.2.5.5, it does not seem to be compatible. Thanks for all support.

@thetrueman Oh my god, that means 2007 year. You should now upgrade to an updated version. I think there is nothing that can be done for the version 15 years ago. Moreover, the problem is not even the compiler. The simulation is incorrect.

SeanG_65

If there is one aspect of simulations on a computer, it is DON'T TRUST THEM. They'll get you in the ballpark but not a home run.

There is NO substitute for the old "click, bang test" meaning, when your design is so catastrophically wrong, simulations lack the dramatic results which tell you to go back and re-check your calculations.

Dompie

QuoteThe Problem is ADIN 0 command which don't work correctly even by changing ADC channel.
Why is it a compiler error. The ADIN command works perfectly with the Positron compiler.
For support for YOUR Proton compiler, this link is where you need to be.

But you can also order the latest version of the Positron Compiler by sending an email to: StoryPainter(at)hotmail(dot)com
After you buy the latest compiler, we can help you much better here.

Johan