PIC18F1220

I was looking into my pic 18F1220 and I see that it has an internal oscilator that can be used as the clock. I’m not sure how to enable this. with my pic 16F84A I just hooked up a resistor and capacitor to the clock input and it worked. I’d like to use the internal if possible since I dont have an oscillator and the RC mode seems to be a little slow. I’ve been looking at the data sheet but its still a little confusing.

Reference 16F628A

These are brilliant. I neve use external crystals any more so if you need some I have a drawrful.

Enabling the internal clock is normally just a matter of setting the appropriate config word bits. If your chip is anything like the 16F628A, the command __config _INTOSC_OSC_NOCLKOUT might do it for you. Failing that, look up the data sheet under "Oscillator Configuration."

Be aware that some of them are more complicated, offering dual speeds. They normally offer 4MHz and 8MHz with a 32kHz option. I’ve switched mine into 32kHz mode accidentally and it’s run so slow I thought it wasn’t running.

 

The datasheet says FOSC

The datasheet says FOSC <3:0> oscillator selection bits. the value I want for the internal oscillator is 1000. is FOSC something I can set or is it just a name they gave some configuration bits?

would this work?

movlw 0x08

movwf FOSC

EDIT: mplab says FOSC is not defined

it appears that FOSC<3:0> are part of CONFIGH1 which is part of the configuration bits.

it appears that I might have
it appears that I might have the internal oscillator working but it is really slow. There must be some configuration bits for selecting a frequency.

Microchip IDE 101

You also need to set OSSCON IRFC2:IRFC0. set all three bits for 8MHz.

Do yourself a BIG favour. Make sure you have

#include <p18f1220.inc>

at the start of the program. Find teh .inc file on your hard drive. Open it in a text editor. The declarations that are in there save you from referring back to the manual all the time.

 

Try

 

I haven’t looked at the include file, but try putting this at the start of your program. It’s a configuration I use for a 16F882.

__config _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTOSCIO

__config _CONFIG2, _WRT_OFF & _BOR21V

That sets the two config words up. Look in the INC file to see what all those flags mean. The most important one for you is “_INTOSCIO”

 

 

I use mplab to generate the
I use mplab to generate the hex file and then I use the software that came with the programmer to program the pic. I was wondering if those lines get put in the hex file made by mplab or not. the pogrammer I have seems to call these fuse values and has options to set them. it appears that it does this last so even if i set it in the hex file it might get overwritten by the programmer. I’ll give it a try and see what happens.

those lines gave some
those lines gave some errors


Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p18F1220 "test.asm" /l"test.lst" /e"test.err" /o"test.o" /d__DEBUG=1
Error[113] C:\DOCUMENTS AND SETTINGS\CHARLES WOLF.CHARLES-LAPTOP\MY DOCUMENTS\MY DROPBOX\PICMICRO\PIC18F1220\TESTPROG\TEST.ASM 9 : Symbol not previously defined (_CONFIG1)
Warning[230] C:\DOCUMENTS AND SETTINGS\CHARLES WOLF.CHARLES-LAPTOP\MY DOCUMENTS\MY DROPBOX\PICMICRO\PIC18F1220\TESTPROG\TEST.ASM 9 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Error[126] C:\DOCUMENTS AND SETTINGS\CHARLES WOLF.CHARLES-LAPTOP\MY DOCUMENTS\MY DROPBOX\PICMICRO\PIC18F1220\TESTPROG\TEST.ASM 9 : Argument out of range (not a valid config register address)
Error[113] C:\DOCUMENTS AND SETTINGS\CHARLES WOLF.CHARLES-LAPTOP\MY DOCUMENTS\MY DROPBOX\PICMICRO\PIC18F1220\TESTPROG\TEST.ASM 11 : Symbol not previously defined (_CONFIG2)
Warning[230] C:\DOCUMENTS AND SETTINGS\CHARLES WOLF.CHARLES-LAPTOP\MY DOCUMENTS\MY DROPBOX\PICMICRO\PIC18F1220\TESTPROG\TEST.ASM 11 : __CONFIG has been deprecated for PIC18 devices. Use directive CONFIG.
Error[126] C:\DOCUMENTS AND SETTINGS\CHARLES WOLF.CHARLES-LAPTOP\MY DOCUMENTS\MY DROPBOX\PICMICRO\PIC18F1220\TESTPROG\TEST.ASM 11 : Argument out of range (not a valid config register address)

Symbols

OKay, so the symbols like _config1, etc. don’t exist in the include file for that chip. I think that if yo look in the include file, it will all become clear.

Once you have created the hex file, that information is included, which is why it appears in thefuses of the programmer.

the include file is really

the include file is really helpful. If i hadent looked there I wouldn’t have gotten the solution.

to get the internal clock in my programmer software I have to choose one of the IRC (internal RC?) modes for the oscillator.

adding these lines to the code sped up the clock a lot.
BSF OSCCON,IRCF2
BSF OSCCON,IRCF1
BSF OSCCON,IRCF0
the led used to flash on/off every 4 or so seconds now it flashes about twice a second.

thanks for your help. now i can figur out how the pwm works.

PWM

I’ve been reading the datasheet and slowly its comming together.

So far I think i’ll need to set the folowing things

CCP1CON

P1M1:P1M0 (have to figure out the values here)

CCp1M3:CCP1M0 (I think this should be 1100)

 

According to the datasheet the period is the product of the following PR2+1,4,TOSC,TMR2

and the duty cycle is the product of the following CCPR1L:CCP1CON<5:4>,TOSC,TMR2



an example would be really helpful here.

Excellent

Ah, you’re going for the hardware PWM. I’m afraid I’ve never used it. Like you, I started with the 84A and it was actuially a really long time before I considered using other chips, by which time I’d developed my own routines for a lot of the stuff the newer chips do in hardware.

I’m certain that you’ll find an “application note” on the Microchipwebsite which gives an example. I’m quite surprised there’s not one in the data sheet.

I found a code example from

I found a code example from microchip’s website http://ww1.microchip.com/downloads/en/DeviceDoc/pwm.zip

I think the code sets up the pwm and then reads a duty cycle from the table they set up. i think i’ll see if i cant modify this to what i want.

i’ve been modifying that

i’ve been modifying that code but I cant seem to get it to work. I was trying to chage it from port c since i dont have port c and I was also trying to remove the data table since they way the coded it doesn’t work with my pic.

sort of working
well it is sort of working. I’m still not 100% sure how everything works but for now I have an led that starts dim and goes bright. now i’m going to see if i can get one led to go bright while another goes dim.

Heh!
Go with a bi-colour LED and get it to fade from one colour to the other!

Genius! I have an idea for a
Genius! I have an idea for a robot that will detect colors and sort caps (soda caps I have thousands of them). I can make it use an RGB LED and have it try to mimic the color! The only problem is one color’s anode is another colors cathode… may have to use 3 LEDs and cover them with something to make all 3 blend.

Pain in the Ass

You’re a pain in my ass! That’s where I was going with this.

My own sensor actually, shines each of R,G and B (full brightness) then detects the amount of reflected light. The principle being that a red Lego brick will reflect more red light than a blue Lego brick. I’m all set to prime WOLFC to do the I2C interface…!

I have an actual RGB LED where anodes and cathodes of all three elements are available…

more than one PWM output

I’ve read that you can have more than one PWM output as long as they both have the same frequency. I havent seen where to configure a duty cycle for the 2nd output. does anyone know?


EDIT: I think the pic 18F1220 has only one CCP module therefore it can only have 2 pwm. (one pwm and its complement).

Maybe

It’s possible, but I wouldn’t really worry about it. If you’re using it to control two similar motors, you probably want them at the same frequency. It’s the mark to space ratio which is important rather than the speed of the PWM.

Most folk round here use Picaxe which has a different set of contraints. I programmed my PWM manually, so I can have an many frequencies and ratios as I want within reason.