• AVR Freaks

Helpful ReplyHot!PIC18F4580 some of the port D outputs are high for 1,2 µs after startup

Author
Daniel_Germany
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2007/10/19 06:39:32
  • Location: 0
  • Status: offline
2020/12/03 10:19:04 (permalink)
2 (1)

PIC18F4580 some of the port D outputs are high for 1,2 µs after startup

Hello,
 
some of my D ports (D4 and D7) are having for 1.2 µs high level after start up and in the normal program they are working well.
 
Has somebody an idea or hints? Thank you.
 
I attach just the first part of the code...
 
//wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww/** I N C L U D E S **********************************************************/
#include <p18f4580.h>
#include <delays.h>                        
#include <timers.h>
#include <string.h>
#include <adc.h>
#include <pwm.h>
#include"LCD\\xlcd.h"

#pragma config OSC = HS                //HS Speed  (IRCIO7 interner Takt) Internal RC with OS as RA7 and OSC2 as divide by 4 clock out
#pragma config FCMENB = OFF            //Fail-safe clock monitor disabled
#pragma config IESOB = OFF            //Internal OSC switch over bit
#pragma config PWRT = ON            //Power up timer ON
#pragma config BOR = BOACTIVE        //enabled whenever part is active, SBOREN disabled
#pragma config BORV = 42            //Reset if Vcc smaller 4,2V; 2,7V; 2,0V
#pragma config WDT = ON                //Watchdog ON
#pragma config WDTPS = 16384        //after 65,5 s reset
#pragma config PBADEN = ON            //Pins are configured as analog input channels on Reset
#pragma config LPT1OSC = OFF        //bei 0; Timer1 configured for higher power operation
#pragma config MCLRE = ON            //Reset at MCLR ON
#pragma config LVP = OFF            //LVP OFF    


void InterruptHandlerHigh (void);
void InterruptHandlerLow (void);



void DelayFor18TCY( void )
{
 int i_18;
 for( i_18=0;i_18<36;i_18++ )
 {
   Nop();
 }
}
//---------------------------------------------------------
void DelayPORXLCD( void )
{
Delay1KTCYx(75); //Delay of 15ms (war 200 bei 4 MHz)     //75
return;
}
//---------------------------------------------------------
void DelayXLCD( void )
{
Delay1KTCYx(25); //Delay of 5ms (war 100 bei 4 MHz)        //25
return;
}
//---------------------------------------------------------


volatile unsigned int AN0;                            // 0 -> 65535 GAS
volatile unsigned char AN0_offset = 200;            // 0 -> 255 Offset Wert Gas ist 180 plus Sicherheit
                                                    // Gas kann max. 858 bei 5.12 V (858-200= 658 Teile zur Verfügung)
                                                    // 1024 / 658 Teile = 1,556  / 1,55* 658 = 1020
volatile unsigned float AN0_DC =1.55;                // Kommazahl Umrechnung ANO zu Duty cycle

volatile unsigned short ERG;                        // 0 -> 65535 ANO entspricht DC

volatile unsigned int AN2;                            // 0 -> 65535 BATTERIE
volatile unsigned int BAT_WERT;                        // 0 -> 65535 BATTERIE

volatile unsigned int DC_max = 1010;                // 0 -> 65535
volatile unsigned int DC_alt = 0;                    // 0 -> 65535
volatile unsigned int DC_act = 0;                    // 0 -> 65535
volatile unsigned char DC_speed = 20;                // 0 -> 255        Schrittweite Erhöhung DC

volatile unsigned int SW_Z = 0;                        // 0 -> 65535 Zähler Intervall
volatile unsigned int SW_Intervall = 290;            // 0 -> 65535 Intervallwert 1/5000* Wert = Intervall    

volatile unsigned char Gas = 0;                        // 0 -> 255

void main(void)
{
char LCDdata1[40];

#define LCD_ON                 LATCbits.LATC4            // output
#define LED                     LATBbits.LATB4            // output
#define Eingang                PORTBbits.RB3            // input
#define ADC                    PORTAbits.RA0            // input
#define BAT                    PORTAbits.RA2            // input

#define D7                     LATDbits.LATD7            // output
#define D6                     LATDbits.LATD6            // output
#define D5                     LATDbits.LATD5            // output
#define D4                     LATDbits.LATD4            // output

#define C5                     LATCbits.LATC5            // output
#define C6                     LATCbits.LATC6            // output
#define C7                     LATCbits.LATC7            // output PIN 26

TRISCbits.TRISC4 = 0;                                 // set PORTC4 as output port       LCD_ON
TRISBbits.TRISB4 = 0;                                 // set PORTB4 as output port       LED
TRISBbits.TRISB3 = 1;                                 // set PORTB3 as input port       

TRISCbits.TRISC2 = 0;                                 // set PORTC2 as output port       PWM
TRISAbits.TRISA0 = 1;                                 // set PORTA0 as input port       Eingang
TRISAbits.TRISA2 = 1;                                 // set PORTA2 as input port       Eingang

TRISDbits.TRISD7 = 0;                                 // set PORTD7 as output port
TRISDbits.TRISD6 = 0;                                 // set PORTD6 as output port
TRISDbits.TRISD5 = 0;                                 // set PORTD5 as output port
TRISDbits.TRISD4 = 0;                                 // set PORTD4 as output port

TRISCbits.TRISC5 = 0;                                 // set PORTC5 as output port
TRISCbits.TRISC6 = 0;                                 // set PORTC6 as output port
TRISCbits.TRISC7 = 0;                                 // set PORTC7 as output port

D7=0;
D6=0;
D5=0;
D4=0;
LED=0;  


OSCCONbits.SCS1    = 0;                                // SCS<1:0>: System Clock Select bits    00 für PLL
OSCCONbits.SCS0    = 0;                                // 1x = Internal oscillator block
                                                    // 01 = Timer1 oscillator
                                                    // 00 = Primary oscillator
    

OSCTUNEbits.PLLEN = 0;                                // PLLEN: Frequency Multiplier PLL for INTOSC Enable bit(1)
                                                    // 1 = PLL enabled for INTOSC (4 MHz and 8 MHz only)
                                                    // 0 = PLL disabled
 
and so on.....
#1
crosland
Super Member
  • Total Posts : 2142
  • Reward points : 0
  • Joined: 2005/05/10 10:55:05
  • Location: Warks, UK
  • Status: online
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/03 11:30:10 (permalink)
0 (2)
What's connected to the pins?
 
All port pins are input by default so their level will be controlled by whatever is connected to them, e.g., pull-ups or inputs to other devices that have internal pull-ups.
#2
NorthGuy
Super Member
  • Total Posts : 6464
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/03 11:57:42 (permalink) ☄ Helpfulby Jim Nickerson 2020/12/03 12:02:47
+2 (2)
As soon as you set TRISx to '0', the latch will start driving the pin and if LATx contains '1', the pin will go high. Therefore, set the LATx register to the desired value before releasing TRISx.
#3
Daniel_Germany
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2007/10/19 06:39:32
  • Location: 0
  • Status: offline
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/03 12:24:12 (permalink)
0
Hi and thanks all of you for your feedback. 10k pull downs are also connected to the ports.
 
Just to avoid missunderstandings from my side:
 
void main(void)
{
1:)
LATDbits.LATD7=0;
LATDbits.LATD6=0;
LATDbits.LATD5=0;
LATDbits.LATD4=0;
 
then
 
2:)
#define D7                     LATDbits.LATD7            // output
#define D6                     LATDbits.LATD6            // output
#define D5                     LATDbits.LATD5            // output
#define D4                     LATDbits.LATD4            // output
 
then
 
3:)
TRISDbits.TRISD7 = 0;                                 // set PORTD7 as output port
TRISDbits.TRISD6 = 0;                                 // set PORTD6 as output port
TRISDbits.TRISD5 = 0;                                 // set PORTD5 as output port
TRISDbits.TRISD4 = 0;                                 // set PORTD4 as output port
 
correct ?
 
Thank you very much.
Daniel
#4
ric
Super Member
  • Total Posts : 29435
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: online
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/03 12:30:16 (permalink)
0 (2)
It would be a lot more efficient just to write an 8 bit value to LATD, then an 8 bit value to TRISD, rather than a pair of instructions for every pin.
Which compiler are you using? If it is XC8, then
#include <p18f4580.h>
should be
#include <xc.h>
and you shouldn't need to include delays.h
 
Also make sure the XLCD code is not also doing something to PORTD bits during startup.
post edited by ric - 2020/12/03 12:31:21

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!
#5
NorthGuy
Super Member
  • Total Posts : 6464
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/03 12:34:53 (permalink)
+1 (1)
Daniel_Germany
#define D7                     LATDbits.LATD7            // output



This doesn't do anything. This is a macro. It only instructs the compiler (pre-processor actually) to replace all occurrences of "D7" with "LATDbits.LATD7" later in the text. Normally you put macros on top of the file where they're easy to find.
#6
Daniel_Germany
Starting Member
  • Total Posts : 60
  • Reward points : 0
  • Joined: 2007/10/19 06:39:32
  • Location: 0
  • Status: offline
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/04 11:56:16 (permalink)
0
Hi all of you. I really appreciate your help. It works right now. Many thanks.
 
One more question regarding  INT0 interrupt. Its a high priority...
Can I change between falling and rising edge in the ISR ?
 
I connected the PWM output to INT0. I want to measure the current min and max. in the PWM circuit with this solution
 
Thanks.
#7
NKurzman
A Guy on the Net
  • Total Posts : 19106
  • Reward points : 0
  • Joined: 2008/01/16 19:33:48
  • Location: 0
  • Status: online
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/04 12:23:31 (permalink)
0
Yes you can change between falling And rising edge in the interrupt.
#8
NorthGuy
Super Member
  • Total Posts : 6464
  • Reward points : 0
  • Joined: 2014/02/23 14:23:23
  • Location: Northern Canada
  • Status: offline
Re: PIC18F4580 some of the port D outputs are high for 1,2 µs after startup 2020/12/04 15:58:08 (permalink)
+1 (1)
You can also use CCP or ECCP module to capture edges, which is more accurate.
#9
Jump to:
© 2021 APG vNext Commercial Version 4.5