PDA

View Full Version : Simple PIC18F4550 Test Fails



Kirk Fraser
- 9th February 2011, 15:29
The attached circuit and program to blink LED's on a PIC18F4550 failed. I posted this on the Microchip forum and got answers I mostly don't understand. What is needed to set up or program my beginning system to work? One guy said I should write to LAT registers instead of PORT registers but another said it should be visible. Is there a problem with the 48MHz crystal or does it need a special setup command? I get nothing, like a short or something.

The idea was to have the program activate every possible pin for blinking to test the duration of the loop. I don't show LED's for every free pin in the diagram but only in the program so I could use a couple of spare LED's to plug into random open pins on my proto board to make sure it works before developing the next part of the circuit. The chip still appears good (free of destruction by static) because it can still be programmed.

Can anyone please tell me how to make it work? Since PicBasic Pro provides Parallax Stamp programming capabilities for PIC Microchips, is there a way to make testing as easy as on a Stamp? Thank you.

rmteo
- 9th February 2011, 15:46
The maximum crystal frequency (FOsc) for a PIC18F4550 is 25MHz - see Table 28-8 (param. 1-A) of the data sheet.

mackrackit
- 9th February 2011, 15:56
is there a way to make testing as easy as on a Stamp?

If these chips had the limited capabilities of a stamp then maybe, but these chips are so much more advanced than the ones used on a stamp.

First, the 4550 has several ADC ports that need to be shut off when using them as digital.
Second, the configs will need to be setup properly.

You will need the data sheet.
You may also want to look at the internal OSC.

mackrackit
- 9th February 2011, 16:04
If I am not too loopy this morning this is what the configs should look like for the internal OSC.
Read here to see more about setting the configs.
http://www.picbasic.co.uk/forum/showthread.php?t=543


DEFINE OSC 8
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L
OSCCON = %01110000

Kirk Fraser
- 28th February 2011, 19:53
Read here to see more about setting the configs.
http://www.picbasic.co.uk/forum/showthread.php?t=543


DEFINE OSC 8
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H
@ __CONFIG _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L &_XINST_OFF_4L
OSCCON = %01110000


Ok, I've tried and conclude there is something way wrong with your software and documentation.
Perhaps you ought to try the usual strategy of providing software updates. You know, when a new
PIC is available, make an update button on your MicroCode Studio to go to your website and get the
new code for it.

The above "Define" means nothing to me and I can't find anywhere to learn about
it. Your URL is maybe for someone at your level of expertese but I need more handholding. Can
you please provide it or tell me what PIC programming system I need to learn and use? Maybe the
C or ASM products? Currently PicBasic PRO doesn't work for my simplest example.

Ioannis
- 1st March 2011, 11:50
Why not post your entire setup?

PBP version, programmer, Program and see what you have so far not working.

The compiler is working fine, and for this chip you need to use the assembler of the MPLAB and not the one of the PBP.

5240

Oh, and do not confusse Melabs (maker of PBP), with Mecanique (maker of MicroCode Studio), Microchip (maker of the PIC chips and MPLAB) and us here, members of the forum that try to help each other.

Credits also to Lester that is hosting this forum for free.

Ioannis

ScaleRobotics
- 1st March 2011, 12:38
Hello Kirk,

I have tried your code from post1 using the configs that Mackrackit gave you. It seems to work fine over here. Since you don't have a pause between your on and off, the pulses will occur at about 15000 times per second. "Should scope to > 200Hz" indeed! If you were trying to make a blink (and be able to see it with your naked eye, the common way is to: (Page 6 of the PBP manual)


Loop1:
portb.0 = 1
pause 500
portb.0 = 0
pause 500
goto Loop1
This will make your LED turn on once per second for half a second.



Ok, I've tried and conclude there is something way wrong with your software and documentation.
Perhaps you ought to try the usual strategy of providing software updates. You know, when a new
PIC is available, make an update button on your MicroCode Studio to go to your website and get the
new code for it.

Not sure what you mean about updates. Are you missing some chips in Micro Code Studios drop down menu?



The above "Define" means nothing to me and I can't find anywhere to learn about
it. Your URL is maybe for someone at your level of expertese but I need more handholding.
(See page 33 of the PBP manual, under section 4.16). The define OSC 8 tells PBP what speed your oscillator is set to run at. Without this, PBP assumes you are using a 4 mhz osc, and a pause 1000 will not be one second if you are using a different osc speed.The configs are settings for that particular chip. Each project you do, may need different settings for these configuration fuses, depending on what you are trying to do. You can find them in the data sheet for the chip, but I find it easier to look in the Microchip include files here: C:\Program Files\Microchip\MPASM Suite. If you look at the bottom of the include file for your particular chip, it shows:



;----- CONFIG1L Options --------------------------------------------------
_PLLDIV_1_1L EQU H'F8' ; No prescale (4 MHz oscillator input drives PLL directly)
_PLLDIV_2_1L EQU H'F9' ; Divide by 2 (8 MHz oscillator input)
_PLLDIV_3_1L EQU H'FA' ; Divide by 3 (12 MHz oscillator input)
_PLLDIV_4_1L EQU H'FB' ; Divide by 4 (16 MHz oscillator input)
_PLLDIV_5_1L EQU H'FC' ; Divide by 5 (20 MHz oscillator input)
_PLLDIV_6_1L EQU H'FD' ; Divide by 6 (24 MHz oscillator input)
_PLLDIV_10_1L EQU H'FE' ; Divide by 10 (40 MHz oscillator input)
_PLLDIV_12_1L EQU H'FF' ; Divide by 12 (48 MHz oscillator input)

_CPUDIV_OSC1_PLL2_1L EQU H'E7' ; [Primary Oscillator Src: /1][96 MHz PLL Src: /2]
_CPUDIV_OSC2_PLL3_1L EQU H'EF' ; [Primary Oscillator Src: /2][96 MHz PLL Src: /3]
_CPUDIV_OSC3_PLL4_1L EQU H'F7' ; [Primary Oscillator Src: /3][96 MHz PLL Src: /4]
_CPUDIV_OSC4_PLL6_1L EQU H'FF' ; [Primary Oscillator Src: /4][96 MHz PLL Src: /6]

_USBDIV_1_1L EQU H'DF' ; USB clock source comes directly from the primary oscillator block with no postscale
_USBDIV_2_1L EQU H'FF' ; USB clock source comes from the 96 MHz PLL divided by 2

;----- CONFIG1H Options --------------------------------------------------
_FOSC_XT_XT_1H EQU H'F0' ; XT oscillator (XT)
_FOSC_XTPLL_XT_1H EQU H'F2' ; XT oscillator, PLL enabled (XTPLL)
_FOSC_ECIO_EC_1H EQU H'F4' ; EC oscillator, port function on RA6 (ECIO)
_FOSC_EC_EC_1H EQU H'F5' ; EC oscillator, CLKO function on RA6 (EC)
_FOSC_ECPLLIO_EC_1H EQU H'F6' ; EC oscillator, PLL enabled, port function on RA6 (ECPIO)
_FOSC_ECPLL_EC_1H EQU H'F7' ; EC oscillator, PLL enabled, CLKO function on RA6 (ECPLL)
_FOSC_INTOSCIO_EC_1H EQU H'F8' ; Internal oscillator, port function on RA6, EC used by USB (INTIO)
_FOSC_INTOSC_EC_1H EQU H'F9' ; Internal oscillator, CLKO function on RA6, EC used by USB (INTCKO)
_FOSC_INTOSC_XT_1H EQU H'FA' ; Internal oscillator, XT used by USB (INTXT)
_FOSC_INTOSC_HS_1H EQU H'FB' ; Internal oscillator, HS oscillator used by USB (INTHS)
_FOSC_HS_1H EQU H'FC' ; HS oscillator (HS)
_FOSC_HSPLL_HS_1H EQU H'FE' ; HS oscillator, PLL enabled (HSPLL)

_FCMEN_OFF_1H EQU H'BF' ; Fail-Safe Clock Monitor disabled
_FCMEN_ON_1H EQU H'FF' ; Fail-Safe Clock Monitor enabled

_IESO_OFF_1H EQU H'7F' ; Oscillator Switchover mode disabled
_IESO_ON_1H EQU H'FF' ; Oscillator Switchover mode enabled

;----- CONFIG2L Options --------------------------------------------------
_PWRT_ON_2L EQU H'FE' ; PWRT enabled
_PWRT_OFF_2L EQU H'FF' ; PWRT disabled

_BOR_OFF_2L EQU H'F9' ; Brown-out Reset disabled in hardware and software
_BOR_SOFT_2L EQU H'FB' ; Brown-out Reset enabled and controlled by software (SBOREN is enabled)
_BOR_ON_ACTIVE_2L EQU H'FD' ; Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
_BOR_ON_2L EQU H'FF' ; Brown-out Reset enabled in hardware only (SBOREN is disabled)

_BORV_0_2L EQU H'E7' ; Maximum setting
_BORV_1_2L EQU H'EF' ;
_BORV_2_2L EQU H'F7' ;
_BORV_3_2L EQU H'FF' ; Minimum setting

_VREGEN_OFF_2L EQU H'DF' ; USB voltage regulator disabled
_VREGEN_ON_2L EQU H'FF' ; USB voltage regulator enabled

;----- CONFIG2H Options --------------------------------------------------
_WDT_OFF_2H EQU H'FE' ; WDT disabled (control is placed on the SWDTEN bit)
_WDT_ON_2H EQU H'FF' ; WDT enabled

_WDTPS_1_2H EQU H'E1' ; 1:1
_WDTPS_2_2H EQU H'E3' ; 1:2
_WDTPS_4_2H EQU H'E5' ; 1:4
_WDTPS_8_2H EQU H'E7' ; 1:8
_WDTPS_16_2H EQU H'E9' ; 1:16
_WDTPS_32_2H EQU H'EB' ; 1:32
_WDTPS_64_2H EQU H'ED' ; 1:64
_WDTPS_128_2H EQU H'EF' ; 1:128
_WDTPS_256_2H EQU H'F1' ; 1:256
_WDTPS_512_2H EQU H'F3' ; 1:512
_WDTPS_1024_2H EQU H'F5' ; 1:1024
_WDTPS_2048_2H EQU H'F7' ; 1:2048
_WDTPS_4096_2H EQU H'F9' ; 1:4096
_WDTPS_8192_2H EQU H'FB' ; 1:8192
_WDTPS_16384_2H EQU H'FD' ; 1:16384
_WDTPS_32768_2H EQU H'FF' ; 1:32768

;----- CONFIG3H Options --------------------------------------------------
_CCP2MX_OFF_3H EQU H'FE' ; CCP2 input/output is multiplexed with RB3
_CCP2MX_ON_3H EQU H'FF' ; CCP2 input/output is multiplexed with RC1

_PBADEN_OFF_3H EQU H'FD' ; PORTB<4:0> pins are configured as digital I/O on Reset
_PBADEN_ON_3H EQU H'FF' ; PORTB<4:0> pins are configured as analog input channels on Reset

_LPT1OSC_OFF_3H EQU H'FB' ; Timer1 configured for higher power operation
_LPT1OSC_ON_3H EQU H'FF' ; Timer1 configured for low-power operation

_MCLRE_OFF_3H EQU H'7F' ; RE3 input pin enabled; MCLR pin disabled
_MCLRE_ON_3H EQU H'FF' ; MCLR pin enabled; RE3 input pin disabled

;----- CONFIG4L Options --------------------------------------------------
_STVREN_OFF_4L EQU H'FE' ; Stack full/underflow will not cause Reset
_STVREN_ON_4L EQU H'FF' ; Stack full/underflow will cause Reset

_LVP_OFF_4L EQU H'FB' ; Single-Supply ICSP disabled
_LVP_ON_4L EQU H'FF' ; Single-Supply ICSP enabled

_ICPRT_OFF_4L EQU H'DF' ; ICPORT disabled
_ICPRT_ON_4L EQU H'FF' ; ICPORT enabled

_XINST_OFF_4L EQU H'BF' ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
_XINST_ON_4L EQU H'FF' ; Instruction set extension and Indexed Addressing mode enabled

_DEBUG_ON_4L EQU H'7F' ; Background debugger enabled, RB6 and RB7 are dedicated to In-Circuit Debug
_DEBUG_OFF_4L EQU H'FF' ; Background debugger disabled, RB6 and RB7 configured as general purpose I/O pins
This gives a short description of the configuration fuses. For things you have not heard of before, a little research in the data sheet is recommended. See post #5 from the link Mackrackit gave you for some more details about commenting out other configs, if you chose to put the configs in your codespace. http://www.picbasic.co.uk/forum/showthread.php?t=543&p=6775#post6775



Can
you please provide it or tell me what PIC programming system I need to learn and use? Maybe the
C or ASM products? Currently PicBasic PRO doesn't work for my simplest example. I really like PBP for its ease of programming, and its capabilities. But yes, configs are a pain for the more complex chips. The same pain will be had for C, etc. No matter what language you choose, you will have to learn to set the configs and of course do some data sheet reading.;)

Kirk Fraser
- 2nd March 2011, 20:43
It works! Thanks to everyone for the help. I made a really dumb newbie mistake, trying to follow the documentation (printed near a ream of paper) and figure out where to insert the code in the compiler subdirectory (failed to locate) instead of simply adding the Define by mackrackit to my simple program. After I posted, I got inspired with that idea and it works (fast) with the 48Mhz crystal.

Yes there are some chips missing in my drop down menu. I chose the PIC18F4550 as it has USB and is in the menu. But the 12 bit A/D versions PIC18F2458, PIC18F2553, PIC18F4458, PIC18F4553 do not show in the menu.

My main goal is to make a circuit to do a PID loop to control a proportional hydraulic valve via the USB interface with a computer. I've seen the Microchip site has a PID program in Assembler. Is there one in Basic? Is there a sample USB interface in Basic?

ScaleRobotics
- 2nd March 2011, 20:54
There is a PID heater control example.
http://www.picbasic.co.uk/forum/showthread.php?t=5874

And there is a USB sample interface here: http://www.picbasic.co.uk/forum/showthread.php?t=5418&p=98010#post98010

mackrackit
- 2nd March 2011, 21:42
Here is a CDC example
http://www.picbasic.co.uk/forum/content.php?r=272-USB-SD-LOGGING