News:

Let's find out together what makes a PIC Tick!

Main Menu

Problem inte 16f1705

Started by Giuseppe, Mar 07, 2025, 10:57 AM

Previous topic - Next topic

Giuseppe

Once the various registers are set to enable pin 11 or the RA2 port remains at a voltage of 0.7 Volts even if the internal pull-up is enabled. I also tried putting an external 4.7K pull-up and the voltage remains at 0.84 Volts. I'll put the list below to help you understand what I did wrong,

TDevice = 16F1705
Xtal = 8
Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_OFF, BOREN_ON, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PPS1WAY_OFF, ZCDDIS_OFF, PLLEN_OFF, STVREN_OFF, BORV_LO, LPBOR_OFF, LVP_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Dim tic As Byte
Dim chiamate As Bit

TMR0 = 100       
'--------------Set port----------
OSCCON = %01110010       
OPTION_REG = %00001111   
LATA  = %00000000
LATC  = %00000000
PORTA = 0
TRISA = %00001100 
RA2PPS = %00000010
TRISC = %00100000 
WPUA = %00001100   
Symbol led_R = PORTA.5       
Symbol led_V = PORTA.1

Clear
'--------Set Reg. Interrupt----------
IOCAP = %00000000
IOCAN = %00000000
IOCAF = %00000000
INTCON = %00010000 
PIE1 = %00000000     
PIE2 = 0
PIE3 = 0
PIR1 = %00000000             'bit5 Flag Rx interrupt
Symbol GIE = INTCON.7        'on globale interrupt
Symbol INTE = INTCON.4       'on interrupt Inte
Symbol INTIF = INTCON.1      'flag interrupt Inte
Symbol INTEDG = OPTION_REG.6 'INTE pag.245
Symbol TMR0IE = INTCON.5
Symbol TMR0IF = INTCON.2

'------------Set interrupt---------------------------
INTEDG = 0 '
Set INTE
Clear INTIF
Set GIE
'---------------------------------------------------------------------------------

On_Interrupt GoTo int

Low led_V             
Low led_R             
'----------------------------------------------------------------------------------------------------
Do
test_1:

If chiamate = 1 Then
   Clear chiamate   
   Toggle led_R
EndIf 
 
Loop
End
'-------------------------------------------------------------------------------------------------------------------------------
int:
Context Save
If INTIF = 1 Then     
  If INTEDG = 0 Then
   Set TMR0IE
   Clear INTIF
   Set INTEDG     
  Else
   Clear TMR0IE   
   TMR0 = 100     
   Clear TMR0IF   
   Clear INTEDG   
   Clear tic     
  EndIf 
EndIf
If TMR0IF = 1 Then
   TMR0 = 100
   Clear TMR0IF
   tic = tic + 1   
   If tic > 9 Then
    Clear tic
    Clear TMR0IE
    Clear TMR0IF
    Set chiamate
   EndIf
EndIf
Context Restore
End
hanks

trastikata

RA2PPS = %00000010 will set the pin as invalid or "reserved" output and your TRISA register suggests that you are looking for PPS input set-up...

Pepe

#2
demo proteus

Giuseppe

I noticed a mistake. I had to set the register like this OPTION_REG = %00000111. The 3rd bit must be 0 because the prescaler must be dedicated to tmr0. So if I understood correctly, just set the trisa and there is no need to move RA2PPS

trastikata

Incorrect, RA2PPS = %00000010 sets the pin as an output and more than that it is a "reserved" settings - thus nothing usable.

However looking at your code you want to set-up the pin as a some peripheral input? Then it is another PPS register, look more careful in the datasheet.

I am in a hurry now, but I also did not check if you enable the PPS change in your code.

Pepe

;-------------------------------------------------------------------------------
;**** Added by Fuse Configurator ****
; Use the Fuse Configurator plug-in to change these settings

Device = 16F1705

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PPS1WAY_ON, ZCDDIS_ON, PLLEN_OFF, STVREN_OFF, BORV_LO, LPBOR_OFF, LVP_OFF

;**** End of Fuse Configurator Settings ****
;-------------------------------------------------------------------------------
Xtal = 8
Declare Optimiser_Level = 3
Declare Create_Coff On
Declare Watchdog = Off

Dim tic As Byte
Dim chiamate As Bit

TMR0 = 100
'--------------Set port----------
OSCCON = %01110010
OPTION_REG = %00001111
LATA  = %00000000
LATC  = %00000000
PORTA = 0
TRISA = %00001100

TRISC = %00100000
WPUA = %00001100
Symbol led_R = PORTA.5
Symbol led_V = PORTA.1

Clear
'--------Set Reg. Interrupt----------
IOCAP = %00000000
IOCAN = %00000000
IOCAF = %00000000
INTCON = %00010000
PIE1 = %00000000
PIE2 = 0
PIE3 = 0
PIR1 = %00000000             'bit5 Flag Rx interrupt
Symbol GIE = INTCON.7        'on globale interrupt
Symbol INTE = INTCON.4       'on interrupt Inte
Symbol INTIF = INTCON.1      'flag interrupt Inte
Symbol INTEDG = OPTION_REG.6 'INTE pag.245
Symbol TMR0IE = INTCON.5
Symbol TMR0IF = INTCON.2

InitPPS()
'------------Set interrupt---------------------------
INTEDG = 0 '
Set INTE
Clear INTIF
Set GIE
'---------------------------------------------------------------------------------

On_Hardware_Interrupt GoTo int

Low led_V
Low led_R
'----------------------------------------------------------------------------------------------------

Do
test_1:

If chiamate = 1 Then
   Clear chiamate
   Toggle led_R
EndIf

Loop
End
'-------------------------------------------------------------------------------------------------------------------------------
int:
Context Save
If INTIF = 1 Then
  If INTEDG = 0 Then
   Set TMR0IE
   Clear INTIF
   Set INTEDG
  Else
   Clear TMR0IE
   TMR0 = 100
   Clear TMR0IF
   Clear INTEDG
   Clear tic
  EndIf
EndIf
If TMR0IF = 1 Then
   TMR0 = 100
   Clear TMR0IF
   tic = tic + 1
   If tic > 9 Then
    Clear tic
    Clear TMR0IE
    Clear TMR0IF
    Set chiamate
   EndIf
EndIf
Context Restore

Proc InitPPS()
    PPS_UnLock()
    RA2PPS = 0x2  'INT(RA2) Input to EXT_INT
    PPS_Lock()
EndProc


End

trastikata

@Giuseppe , @Pepe

To setup a PPS pin as an input for a given peripheral, INT for RA2 in this case different register should be used:

Proc InitPPS()
    PPS_UnLock()
    INTPPS = 0x02  'INT(RA2) Input to EXT_INT
    PPS_Lock()
EndProc

As I mentioned earlier in this topic, RA2PPS = 0x2 sets the PPS pin to an output and even more in this case 0x02 is not a valid address for a peripheral output.

Regards.

Pepe

So the positron studio pps configurator and the proteus simulator are wrong? because in proteus it simulates it well.

trastikata

Quote from: Pepe on Mar 08, 2025, 02:52 PMSo the positron studio pps configurator and the proteus simulator are wrong? because in proteus it simulates it well.

I don't know about Proteus and Positron Studio, but it's always good to check the datasheets when in doubt, RxyPPS will set the pin as peripheral Output which is wrong assuming you want an Interrupt input:

Input.jpg

Output.jpg

JohnB

I will have a look at the PPS Wizard, I use the Microchip XML files in MPLABX but I may well have got it wrong in some instances.
JohnB

Pepe

#10
Chatgpt

Device 16F1705
Declare Xtal = 16

' Configuration fuses
Config1 FCMEN_OFF, IESO_OFF, CLKOUTEN_OFF, BOREN_ON, CP_OFF, MCLRE_OFF, PWRTE_ON, WDTE_OFF, FOSC_INTOSC
Config2 WRT_OFF, PLLEN_OFF, STVREN_ON, BORV_LO, LVP_OFF

' Set internal oscillator to 16 MHz
OSCCON = %01111010

' Configure RA2 as digital input
TRISA.2 = 1     
ANSELA.2 = 0   
WPUA.2 = 1     

' Configure RC5 as output (for LED)
TRISC.5 = 0     
LATC.5 = 0     

' Unlock PPS, assign INT to RA2, and lock PPS
PPS_Unlock()
INTPPS = $02   
PPS_Lock()

' Set interrupt edge (1 = rising edge, 0 = falling edge)
INTCON.2 = 1   

' Enable interrupts
INTCON.7 = 1   
INTCON.6 = 1   
PIE0.6 = 1     

Dim flag As Bit

' Set hardware interrupt routine
On_Hardware_Interrupt GoTo ISR

' Main loop
Do
    If flag = 1 Then
        LATC.5 = 1    ' Turn LED on
        DelayMS 500
        LATC.5 = 0    ' Turn LED off
        DelayMS 500
        flag = 0      ' Reset flag
    EndIf
Loop

' Interrupt Service Routine (ISR)
ISR:
    Context Save
    If PIR0.6 = 1 Then
        flag = 1      ' Set flag on interrupt
        PIR0.6 = 0    ' Clear interrupt flag
    EndIf
    Context Restore



JohnB

@Pepe
QuoteSo the positron studio pps configurator and the proteus simulator are wrong?

I have just checked my PPS Wizard in Positron Studio and it is generating the correct code but there is a problem when repainting the image after unassigning a pin.

Proc InitPPS()
   PPS_UnLock()
   INTPPS = 0x2  'INT(RA2) Input to EXT_INT
   PPS_Lock()
EndProc

On first loading the pinout is correct with all ports properly allocated to the appropiate pin.
Selecting RA2 (pin 11)and assigning it to Int generates the correct code and the image changes pin 11 to INT.
However, if you unassign pin 11 the diagram is redrawn with Pin 11 showing as RC4 which is alread assigned to pin 6.
This will be fixed in the next release of Positron Studio.



JohnB

JohnB

JohnB

keytapper

Quote from: JohnB on Mar 11, 2025, 09:40 AMPPS Wizard now fixed - See Positron Studio for update.
You might involve AI to help the discovery of the MCU  ;D
Ignorance comes with a cost

Giuseppe

I'll try now and keep you posted, thank you very much