Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Status
Not open for further replies.

eagle1109

Full Member level 6
Joined
Nov 20, 2014
Messages
384
Helped
4
Reputation
10
Reaction score
6
Trophy points
1,298
Location
Saudi Arabia
Activity points
5,866
Hello,

1. I'm trying to control the oscillator speed but I don't see any results. Where is the problem? I want to run 125kHz internal clock speed.

2. The LED also is not blinking! I don't know where is the problem, the code on the simulator is working but I can't control the oscillator speed.

3. The variables don't show on the variables window in debugging, while running debugging.
I'm using MPLAB X v3.30.

btfss or btfsc work fine for input testing to light an LED as a result, but blinking doesn't work, I increased the delay lines but its effect show on the debugger i/o window, but on the breadboard it isn't.

This is my code:

Code:
; PIC18F4550 Configuration Bit Settings

; ASM source line config statements

#include "p18F4550.inc"

; CONFIG1L
  CONFIG  PLLDIV = 1            ; PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
  CONFIG  CPUDIV = OSC1_PLL2    ; System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
  CONFIG  USBDIV = 1            ; USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)

; CONFIG1H
  CONFIG  FOSC = INTOSC_EC      ; Oscillator Selection bits (Internal oscillator, CLKO function on RA6, EC used by USB (INTCKO))
  CONFIG  FCMEN = ON            ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
  CONFIG  IESO = ON             ; Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)

; CONFIG2L
  CONFIG  PWRT = OFF            ; Power-up Timer Enable bit (PWRT disabled)
  CONFIG  BOR = OFF             ; Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
  CONFIG  BORV = 3              ; Brown-out Reset Voltage bits (Minimum setting 2.05V)
  CONFIG  VREGEN = OFF          ; USB Voltage Regulator Enable bit (USB voltage regulator disabled)

; CONFIG2H
  CONFIG  WDT = OFF             ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
  CONFIG  WDTPS = 32768         ; Watchdog Timer Postscale Select bits (1:32768)

; CONFIG3H
  CONFIG  CCP2MX = OFF          ; CCP2 MUX bit (CCP2 input/output is multiplexed with RB3)
  CONFIG  PBADEN = ON           ; PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
  CONFIG  LPT1OSC = OFF         ; Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
  CONFIG  MCLRE = ON            ; MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

; CONFIG4L
  CONFIG  STVREN = OFF          ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
  CONFIG  LVP = OFF             ; Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
  CONFIG  ICPRT = OFF           ; Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
  CONFIG  XINST = OFF           ; Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

; CONFIG5L
  CONFIG  CP0 = OFF             ; Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
  CONFIG  CP1 = OFF             ; Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
  CONFIG  CP2 = OFF             ; Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
  CONFIG  CP3 = OFF             ; Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

; CONFIG5H
  CONFIG  CPB = OFF             ; Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
  CONFIG  CPD = OFF             ; Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

; CONFIG6L
  CONFIG  WRT0 = OFF            ; Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
  CONFIG  WRT1 = OFF            ; Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
  CONFIG  WRT2 = OFF            ; Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
  CONFIG  WRT3 = OFF            ; Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

; CONFIG6H
  CONFIG  WRTC = OFF            ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
  CONFIG  WRTB = OFF            ; Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
  CONFIG  WRTD = OFF            ; Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

; CONFIG7L
  CONFIG  EBTR0 = OFF           ; Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
  CONFIG  EBTR1 = OFF           ; Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
  CONFIG  EBTR2 = OFF           ; Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
  CONFIG  EBTR3 = OFF           ; Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

; CONFIG7H
  CONFIG  EBTRB = OFF           ; Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

   
delay1 res 1
delay2 res 1
delay3 res 1 

  
RES_VECT  CODE    0x0000            ; processor reset vector

    movlw 0X08
    movwf  TRISD
    clrf  LATD
    clrf  PORTD
    movlw 0X10
    MOVWF OSCTUNE
    movlw 0X1E
    MOVWF OSCCON

    GOTO    START                   ; go to beginning of program

; TODO ADD INTERRUPTS HERE IF USED
    
    
MAIN_PROG CODE                      ; let linker place main program



 
START:


; btfsc PORTD,3
 call blink


 
    GOTO START
    
    
blink:
 bsf PORTD,2
 call Delay
 
 
 bcf PORTD,2
 call Delay


Delay:
    movlw 0xff
    movwf delay2   
loop1:
    movlw 0xff
    movwf delay1
loop2:    
    decfsz delay1
    goto loop2

    decfsz delay2
    goto loop1

    
    
    return
    
    END
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

You post almost undocumented code. Therefore it takes a lot of time to understand.
Don´t expect that many users will spend that much time.

Do you have a clue how long "delay" is in milliseconds?
--> write the expected values as comment into your code.

Are you aware, that we don´t see your schematic? LED connection for example.
The LED also is not blinking!
This information is amost useless. Tell us what it does. Is it OFF or ON. or is the blinking freequency just too fast for your eyes to see? --> use a scope.


Klaus
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

You post almost undocumented code. Therefore it takes a lot of time to understand.
Don´t expect that many users will spend that much time.

Do you have a clue how long "delay" is in milliseconds?
--> write the expected values as comment into your code.

Are you aware, that we don´t see your schematic? LED connection for example.

This information is amost useless. Tell us what it does. Is it OFF or ON. or is the blinking freequency just too fast for your eyes to see? --> use a scope.


Klaus

Oh well :) sorry I thought the readers would understand that I'm just testing the PIC in asm code.

1. I want to blink an LED on PORTD pin 2. And wrote the code in asm.
2. I don't know what clock the chip is running, I tried to control the internal clock prescaler but couldn't! I don't know why. So I think it's running on default 8MHz.
But what is interesting is that I see in the program debugging window for SFRs in MPLAB X that the OSCCON is set as I want but IOFS (INTOSC Frequency Stable bit) is not set, which means the oscillator is not stable. Is it necessary the bit is set so I can control the oscillator?
3. I can't show the variables I developed in the beginning of the code, delay1, delay2 .. etc. While debugging. I don't know what is the problem.
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

1) I think it is no secret how you connected the LED. So why don´t you show us? Don´t waste our time.

2) You don´t know what clock you are running.. and you don´t know what´s your expected delay time. Then how can you verify the function.
--> do your calculations first! Then you know what to expect, then you are able to verify something.

For example: calculate your delay to be 500ms for your desired clock frequency. Then you can expect a certain blink frequency (see below). And if you see a different blink frequency you can calculate back the clock frequency and with that information it´s more easy to find an error.

****
Did you step through your "blink" function? Then you should have recognized that "delay" is peforemd three times per run. I assume this is not what you want.

Klaus
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

OK, if OSCCON reads 0x48 while debugging then I think it's the same value while the chip is running.

Which means it's 1MHz and on the OSTS is set which means:
Oscillator Start-up Timer time-out has expired; primary oscillator is running.

So, how it's now running on primary oscillator and I'm configuring it to run on the internal oscillator? I think this reason is enough that the chip isn't working as I want.

And regarding the delay, so it's 1MHz which is 1us and I'm developing 16-bit delay counter so it's 65.5ms times 10 delays 655ms enough to observe the blink.
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Shouldn't there be a 'goto blink' before the delay routine?
Without it the blink will only occur once.

Brian.
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Sorry, this is my updated code.

Code:
; PIC18F4550 Configuration Bit Settings

; ASM source line config statements

#include "p18F4550.inc"

; CONFIG1L
  CONFIG  PLLDIV = 1            ; PLL Prescaler Selection bits (No prescale (4 MHz oscillator input drives PLL directly))
  CONFIG  CPUDIV = OSC1_PLL2    ; System Clock Postscaler Selection bits ([Primary Oscillator Src: /1][96 MHz PLL Src: /2])
  CONFIG  USBDIV = 1            ; USB Clock Selection bit (used in Full-Speed USB mode only; UCFG:FSEN = 1) (USB clock source comes directly from the primary oscillator block with no postscale)

; CONFIG1H
  CONFIG  FOSC = INTOSC_EC      ; Oscillator Selection bits (Internal oscillator, CLKO function on RA6, EC used by USB (INTCKO))
  CONFIG  FCMEN = ON            ; Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor enabled)
  CONFIG  IESO = ON             ; Internal/External Oscillator Switchover bit (Oscillator Switchover mode enabled)

; CONFIG2L
  CONFIG  PWRT = OFF            ; Power-up Timer Enable bit (PWRT disabled)
  CONFIG  BOR = OFF             ; Brown-out Reset Enable bits (Brown-out Reset disabled in hardware and software)
  CONFIG  BORV = 3              ; Brown-out Reset Voltage bits (Minimum setting 2.05V)
  CONFIG  VREGEN = OFF          ; USB Voltage Regulator Enable bit (USB voltage regulator disabled)

; CONFIG2H
  CONFIG  WDT = OFF             ; Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
  CONFIG  WDTPS = 32768         ; Watchdog Timer Postscale Select bits (1:32768)

; CONFIG3H
  CONFIG  CCP2MX = OFF          ; CCP2 MUX bit (CCP2 input/output is multiplexed with RB3)
  CONFIG  PBADEN = ON           ; PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset)
  CONFIG  LPT1OSC = OFF         ; Low-Power Timer 1 Oscillator Enable bit (Timer1 configured for higher power operation)
  CONFIG  MCLRE = ON            ; MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)

; CONFIG4L
  CONFIG  STVREN = OFF          ; Stack Full/Underflow Reset Enable bit (Stack full/underflow will not cause Reset)
  CONFIG  LVP = OFF             ; Single-Supply ICSP Enable bit (Single-Supply ICSP disabled)
  CONFIG  ICPRT = OFF           ; Dedicated In-Circuit Debug/Programming Port (ICPORT) Enable bit (ICPORT disabled)
  CONFIG  XINST = OFF           ; Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

; CONFIG5L
  CONFIG  CP0 = OFF             ; Code Protection bit (Block 0 (000800-001FFFh) is not code-protected)
  CONFIG  CP1 = OFF             ; Code Protection bit (Block 1 (002000-003FFFh) is not code-protected)
  CONFIG  CP2 = OFF             ; Code Protection bit (Block 2 (004000-005FFFh) is not code-protected)
  CONFIG  CP3 = OFF             ; Code Protection bit (Block 3 (006000-007FFFh) is not code-protected)

; CONFIG5H
  CONFIG  CPB = OFF             ; Boot Block Code Protection bit (Boot block (000000-0007FFh) is not code-protected)
  CONFIG  CPD = OFF             ; Data EEPROM Code Protection bit (Data EEPROM is not code-protected)

; CONFIG6L
  CONFIG  WRT0 = OFF            ; Write Protection bit (Block 0 (000800-001FFFh) is not write-protected)
  CONFIG  WRT1 = OFF            ; Write Protection bit (Block 1 (002000-003FFFh) is not write-protected)
  CONFIG  WRT2 = OFF            ; Write Protection bit (Block 2 (004000-005FFFh) is not write-protected)
  CONFIG  WRT3 = OFF            ; Write Protection bit (Block 3 (006000-007FFFh) is not write-protected)

; CONFIG6H
  CONFIG  WRTC = OFF            ; Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected)
  CONFIG  WRTB = OFF            ; Boot Block Write Protection bit (Boot block (000000-0007FFh) is not write-protected)
  CONFIG  WRTD = OFF            ; Data EEPROM Write Protection bit (Data EEPROM is not write-protected)

; CONFIG7L
  CONFIG  EBTR0 = OFF           ; Table Read Protection bit (Block 0 (000800-001FFFh) is not protected from table reads executed in other blocks)
  CONFIG  EBTR1 = OFF           ; Table Read Protection bit (Block 1 (002000-003FFFh) is not protected from table reads executed in other blocks)
  CONFIG  EBTR2 = OFF           ; Table Read Protection bit (Block 2 (004000-005FFFh) is not protected from table reads executed in other blocks)
  CONFIG  EBTR3 = OFF           ; Table Read Protection bit (Block 3 (006000-007FFFh) is not protected from table reads executed in other blocks)

; CONFIG7H
  CONFIG  EBTRB = OFF           ; Boot Block Table Read Protection bit (Boot block (000000-0007FFh) is not protected from table reads executed in other blocks)

  
; delay variables   
delay1 res 1	
delay2 res 1
delay3 res 1 

  
RES_VECT  CODE    0x0000            ; processor reset vector

    movlw 0X40	     ; configure oscillator to run at 125kHz
    MOVWF OSCCON
    movlw 0X10	    ; configure Frequency Tuning bits for minimum frequency
    MOVWF OSCTUNE
    
    movlw 0X02    
    movwf  TRISD    ; configure PORTD as output
    clrf  LATD	    ; clearing the LAT bits
    clrf  PORTD	    ; clearing the PORT bits

    clrf INTCON
    movlw 0XA0
    movwf INTCON
    movlw 0X80
    MOVWF T0CON
    
        
    GOTO    START                   ; go to beginning of program

; TODO ADD INTERRUPTS HERE IF USED
    
    
MAIN_PROG CODE                      ; let linker place main program

START:

    call blink

    GOTO START
      
blink:
 bsf PORTD,2
 call Delay
 call Delay
 call Delay 
 call Delay 
 
 bcf PORTD,2
 call Delay
 call Delay
 call Delay 
 call Delay 
 
 return

Delay:
    movlw 0xff
    movwf delay2   
loop1:
    movlw 0xff
    movwf delay1
loop2:    
    decfsz delay1
    goto loop2

    decfsz delay2
    goto loop1

    return
    
    END
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Making OSCCON= 0x40 selects 1MHz internal oscillator.
If you want 125KHz (post #1) use OSCCON = 0x10.

You also have the timer 0 interrupts enabled but no ISR to service them. It will make the program crash the first time TMR0 overflows.

Brian.
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

I uploaded my problem to YouTube.

 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

I don´t see any power supply capacitor at the PIC.
What about reset/MCLR connections?
Did you read the PIC datasheet about what else is needed for basic operation?
--> show us your complete schematic.

Klaus
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

OK, I connected two 100nF ceramic caps.

The MCLR is OK and is active low, so it's pulled high by the pickit 3 all the time. The pickit3 resets the chip automatically during programming the chip I guess.

I think everything else is fine, because it's a simple task.

pic.png

Pretty much similar to this one, adding the power caps you told me about and the LED is on PORTD pin 2. Very simple! But surprised that after all this time I get a problem with blinking an LED. I did multiplexing 4-digit seven segment module.
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

I´m tired to ask for a complete schematic again.
But without it:
* We can´t verify capacitor connection
* We can´t verify LED connection.
Both is urgent for your desired function.
I recommended to use a scope to see the LED port function.
* If you don´t show us, we can´t verify this.

It´s on you to motivate or discourage people who want to help you.

Klaus
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

blink_ckt.png

The problem solved yesterday, I'm sorry LOL it's an embarrassing mistake to forget the MCLR resistor, it should be there all the time.

I thought pickit3 is taking care of pulling the pin up and down during programming.

While the pickit3 pulls the MCLR up, but I don't know I think it's not enough.

But what happens during programming the chip? Does the pickit3 pulls the MCLR down anytime during programming process? Because if the LED is on and I uploaded another code, the LED goes off and returns on is the code sets it on again.
 

Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

Like so often:
* In post#2 I asked for a schematic for the first time
* In post#10 I especially asked for the MCLR connection.

--> Do you recognize now: your behaviour is stealing our time....and your's too.
We don't ask for a schematic to keep you busy .... we do this to help you.

Klaus
 
Re: LED blink, variables on debugger window & Oscillator settings problems PIC18F4550

Hi,

Like so often:
* In post#2 I asked for a schematic for the first time
* In post#10 I especially asked for the MCLR connection.

--> Do you recognize now: your behaviour is stealing our time....and your's too.
We don't ask for a schematic to keep you busy .... we do this to help you.

Klaus

I'm sorry, I was confused I didn't think it was the MCLR resistor because it's been a while working with the PIC microcontroller, I was mainly working with Arduino dev boards where I don't have to care about basic connections like the MCLR resistor.

I really don't want to waste anoyone's time, that's absolutely not in my goals I'm too an electronics trainer and I just moved to another work unit and I'm busy doing plans and evaluation designs.

I'm also working on developing a theory course about microprocessors and microcontrollers because our corporation provided a new plan for the college diploma but didn't provide the copy of course for its new topics.

In microprocessors and microcontrollers theory part, I have to write about 8086 microprocessor in theoretical aspect, where they of course require the practical part but we don't want to work with the 8086 kits, because:
1. The available kits are 8085.
2. They are hard to program.
3. The 8086 kits are not available.

So, in the workshop for the practical exercises we work with PIC16F877A with flowcode v4. It's enough for trainees to understand about microcontrollers.


So, of course I appreciate anoyone's time and I appreciate your intention to help me and thank you very much. I just feel a lot of pride for the people I contact on forums.

Hope to work with you for more advanced topics in the future :)

Regards,
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top