• AVR Freaks

AnsweredHot!PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled

Author
Yoi
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2021/02/23 10:48:14
  • Location: Germany
  • Status: offline
2021/02/27 09:57:53 (permalink)
0

PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled

Hi, 
when TMR2IE is enabled I cannot read from ports RA2 or RA3.
Even the external interrupt for RA2 is not working with timer 2 interrupt enabled.
To switch off the TMR2IE before reading the port doesn't help.
Any idea?
Best Georg
 
init:;------------------------------------------------------------------------------------------------------------------
;set INTOSC frequency 111=16MHz, 110=8MHz*, 101=4 MHz, 100=2MHz, 011=1MHz, 010=500kHz, 001=250kHz, 000=31kHz(LFINTOSC)
bsf OSCCON,6
bsf OSCCON,5
bsf OSCCON,4

clrf IOCAF ; interrupt on change
clrf ANSELA ; Analog port
clrf LATA ; I/O

;set I/O ports
movlw 11111100B ; I/O ports
movwf TRISA ; I/O port direction

;set interrupts
movlw 11101000B ; GIE PEIE TMR0IE INTE IOCIE
movwf INTCON ; interrupt control register
movlw 00000000B ; prescaler for tmr0, pre [1:2] ... 1:256
movwf OPTION_REG ; WPUEN, INTEDG, T0CS, T0SE, PSA+PS

movlw 00001000B ; set port RA3 to
movwf IOCAP ; positive edge interrupt
movwf IOCAN ; negative edge interrupt

movlw 01111111B ; 1:16 post, on, 64 pre
movwf T2CON ; timer 2 control

movlw 00000010B ;<- TMR2IE
movwf PIE1 ;<- periperal interrupt register

movlw 00001111B ;
movwf WPUA ; weak pull-up
main:;==========================================================================
CLRWDT

btfss RA2
bsf LATA1
btfsc RA2
bcf LATA1

goto main
#1
upand_at_them
Super Member
  • Total Posts : 788
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/01 09:18:47 (permalink)
0
Where are your configuration bits?  You know that the watchdog timer defaults to being on, right?
 
EDIT: And the external clock, not internal, is the default.
post edited by upand_at_them - 2021/03/01 09:20:33
#2
Yoi
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2021/02/23 10:48:14
  • Location: Germany
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/01 10:10:45 (permalink)
0
Yes I know:

config FOSC = INTOSC ; Internal Oscillator Selection
config BOREN = ON ; Brown-out Reset
config WDTE = ON ; Watchdog Timer
config PWRTE = ON ; Power-up Timer
config MCLRE = OFF ; MCLR Pin weak pull-up
config CP = ON ; Code Protection
config LVP = OFF ; Low-Voltage Programming
config LPBOR = ON ; Brown-out Reset Selection bits
config BORV = 27 ; Brown-out Reset Voltage Selection (20,27,40,45)
config WRT = OFF ; Flash Memory Self-Write Protection
 
To set all off has the same effect. I also cannot read from port RA0 or RA1 but this is always.
post edited by DJ Yoi - 2021/03/01 10:24:58
#3
ric
Super Member
  • Total Posts : 30244
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/01 12:26:35 (permalink)
+1 (1)
Change
config WDTE = ON ; Watchdog Timer
to
config WDTE = OFF ; Disable Watchdog Timer

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#4
Howard Long
Super Member
  • Total Posts : 908
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: online
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/01 12:41:16 (permalink) ☼ Best Answerby DJ Yoi 2021/03/02 06:08:31
+1 (1)
Meanwhile, this code seems to work fine:
 


// PIC10F322 Configuration Bit Settings
// 'C' source line config statements
// CONFIG
#pragma config FOSC = INTOSC // Oscillator Selection bits (INTOSC oscillator: CLKIN function disabled)
#pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
//#pragma config MCLRE = ON // MCLR Pin Function Select bit (MCLR pin function is MCLR)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
//#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
#pragma config LPBOR = OFF // Brown-out Reset Selection bits (BOR disabled)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#define _XTAL_FREQ 8000000
void __interrupt() isr(void)
{
// First deal with the software UART, the most time critical service
if (PIR1bits.TMR2IF && PIE1bits.TMR2IE && INTCONbits.PEIE)
{
PIR1bits.TMR2IF=0;
LATAbits.LATA1=PORTAbits.RA3; // Copy RA3 input to RA1 output
}
if (INTCONbits.INTF)
{
INTCONbits.INTF=0;
LATAbits.LATA0=!LATAbits.LATA0; // Toggle RA0 output on RA2/INT falling edge
}
}
int main(void)
{
TRISA=0b00001100; // RA0,1 outputs; RA2,3 inputs
WPUA=0b00001100; // pull ups enabled on RA2,3
OPTION_REGbits.nWPUEN=0;
ANSELA=0;

OPTION_REGbits.INTEDG=0; // 0 => falling edge
INTCONbits.INTF=0; // INT is on RA2 GPIO input
INTCONbits.INTE=1;

T2CONbits.T2CKPS=0b01; // 0b01 -> div-by-4 prescaler
T2CONbits.TOUTPS=0b0000; //0b0000 -> div-by-1 postscaler
PR2=255;
PIR1bits.TMR2IF=0;
PIE1bits.TMR2IE=1;
T2CONbits.TMR2ON=1;

INTCONbits.PEIE=1;
INTCONbits.GIE=1;

while (1)
{
NOP();
}
return 0;
}

 

Attached Image(s)

#5
Yoi
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2021/02/23 10:48:14
  • Location: Germany
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/02 06:30:56 (permalink)
0
Hi Howard,
I can agree your code is running but when I change it to read from RA0 or RA1 and output to [RAx3x] RA2 it's not working.
But this is not related to TMR2.
I found out that the timer interrupts are disturbing the read of the NMRA-DCC signal on [RAx3x] RA2 (I need to save and restore W and STATUS and then the timers are giving wrong readings), therefore I poll the TMR2IF for the long timer in the main routine and check also the TMR0IF in the int on change (IOCIF) routine. 
That seems to work in the simulator, need to check it live.
I have attached an Excel sheet to generate the stimuli file for NMRA-DCC in SCL format.
 
post edited by DJ Yoi - 2021/03/02 10:30:20
#6
mbrowning
USNA79
  • Total Posts : 1889
  • Reward points : 0
  • Joined: 2005/03/16 14:32:56
  • Location: Melbourne, FL
  • Status: online
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/02 09:20:50 (permalink)
+2 (2)
g.zi@gmx.de
output to RA3 it's not working.

Ummm, isn't RA3 input only?
#7
Yoi
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2021/02/23 10:48:14
  • Location: Germany
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/02 10:15:08 (permalink)
0
I mean RA2, sorry
 
post edited by DJ Yoi - 2021/03/02 10:49:51
#8
Howard Long
Super Member
  • Total Posts : 908
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: online
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/03 06:32:41 (permalink)
0
g.zi@gmx.de
I mean RA2, sorry

 
Looks fine to me.
 
Check your programmer/debugger isn't pulling RA0.
 
https://youtu.be/0-5L480ZzwU
 
 
#9
Yoi
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2021/02/23 10:48:14
  • Location: Germany
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/03 09:49:17 (permalink)
0
Yes, when I am push pull the ports its reading.
The buttons I want to use are connected to ground via 1k.
It seems that the pull-ups are not working.
 
http://g-zi.de/PIC/test.png
 
#10
Howard Long
Super Member
  • Total Posts : 908
  • Reward points : 0
  • Joined: 2005/04/04 08:50:32
  • Status: online
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/03 14:34:44 (permalink)
0
Still works OK for me, 1k to ground or via an open drain output.
 
Yellow trace is RA0 input, blue is RA2 output. The input is driven via a 1k from an open drain signal generator. If I disconnect the signal generator, it also goes high.
 
However, if the PGD of the PICkit4 is connected to RA0/ICSPDAT, it holds the pin low.
 
Edit: I measured the pull up current on RA0, it's about 100uA with Vdd=3.5V, equivalent to about 35k.
post edited by Howard Long - 2021/03/03 14:45:09

Attached Image(s)

#11
Yoi
New Member
  • Total Posts : 25
  • Reward points : 0
  • Joined: 2021/02/23 10:48:14
  • Location: Germany
  • Status: offline
Re: PIC10F322 Port RA2 or RA3 not readable when TMR2IE is enabled 2021/03/04 05:25:39 (permalink)
+1 (1)
> However, if the PGD of the PICkit4 is connected to RA0/ICSPDAT, it holds the pin low
That's it. By unplugging the PICkit4 it's working fine.
Thanks a lot!
#12
Jump to:
© 2021 APG vNext Commercial Version 4.5