Hi, I've been using GCB a bit using a pic16F1825 and pic12F1840 always using the internal oscillator at 32mhz. I am working on a project where timing seems to be somewhat important and it is recommended that I run my pic at 20mhz. Looking at the data sheet and chip data in GBC, this doesn't seem to be an option when using the internal oscillator, so I will use a 20mhz crystal and two 22pf caps.
Here is my dilema... I have looked but can't find an example of what the configuration should look like. I have always only used...
chip 16f1825, 32
and thats it.
Also, I have seen where you can use a slower crystal and somehow multiply the clock rate internally to the pic, but can't seem to figure that out at this point.
Where can I find some info on how the config should look when using an external oscillator and configurations in general. I can't find any info on what should be defined (or the actual syntax to do so) for the pic to work correctly other than what I have always used (internal oscillator).
Thanks!!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Refer to the PIC 18F1825 Datasheet Page 54 (Figure 5.1). This shows a block diagram of the oscillator module. With this we can see that there is only one practical way to acheive 20 MHz. That is with a 20 Mhz crystal or ceramic oscillator and with the PLL turned off.
Reading on you will see that as a general rule, for Frequencies above 16MHz, HS mode should probably be used.
So the Configuration setting will be for an external crystal with the PLL turned off.
At this point I usually open up the GCB chipdata file for the chip in question. This will be 16F1825.dat in the chipdata folder. Then look in the [ConfigOps] section towards the end of the file.
For HS:.......... #Config OSC = HS
For PLL ........: #Config PLLEN = OFF
Therefore the basic Congiuration will be:
#chip 16F1825, 20
#config OSC = HS, Pllen = OFF
To confirm that things were written correctly you can create a .gcb file with only the lines above. The click on the ASM button in the IDE to create an ASM file. Then External Tools > Open ASM.
The configuration section at the top of the ASM file should show your config settings along with some other default settings. Should look like this:
Thanks Bill. That is exactly what I was looking for. Where can I find information like this?
I am working on a project and need to be able to manipulate registers and the like and I am trying to find some information specifically on the syntax used by GCB to do this. For instance, the receive status and control register uses 8 bits to enable and disable certain functions. So the register is called RCSTA. Lets say I want to enable SPEN (bit 7), SREN (bit5) and CREN (bit 4) and disable the rest of the bits. Can you use SPEN = 1, SREN = 1 and CREN = 1, or do you write a hex value of B0 to the RCSTA register, and what is the GCB syntax for doing things like this? Can you point me in the right direction? Resgister manipulation is new to me and I can't seem to find alot of syntax examples yet.
Thanks for your help!!!!!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using the RCSTA as the example you have a number of methods to update.
Update the complete register
RCSTA = 0x55 or RCSTA = 0b01010101 or RCSTA = 86 will update the all eight bits, the byte, of the register.
Update a specfic bit via bit alias
Registers are mapped to bits within the memory map via an alias. The chipfile (the .DAT file) contains these mapping. Again using RCSTA as the example. This is the register from a 16f1939.
This shows the 8 bits. You can set any bit register alias as follows:
Set FERR On (or Off) or FERR = 1 (or = 0).
Update a specfic bit via bit addressing
If you want update a single bit. Ensure you know your bit addressing. This is NOT good practice as follows:
RCSTA.7 = 1
RCSTA.6 = 0
Update a register bit with another bit
You can only do this with Great Cow BASIC v.0.95.000 or greater.
You can set a bit with a bit using SetWith(). As follows:
IF ( something = something_else ) THEN **SetWith ( SPEN , myByte.7 ) **
Note
If you write to a register that does not exist.... Great Cow BASIC will simply create a byte variable. So, you can always check your ASM for Byte variable of the register you 'thought' existed.
Also, you do not need to state the Register and the Register Bit alias. This is bad practice. While this helps you remember the register and the bit there are cases where this is not portable between microcontrollers.
RCSTA.CREN = 1
Hope this helps.
What to write a device driver to gain some experience? :-)
Last edit: Anobium 2016-03-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Evan, this is GREAT information, exactly what I was looking for. I will give this a whirl. Thank you for this. If one needs to check a register status, do you do something like this...
if FERR = 1 then... or would you do...
if RCSTA.FERR = 1 then... or would you do...
if RCSTA.1 = 1 then...
Thanks again!
Last edit: viscomjim 2016-03-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In this same situation, I need to set the baudrate of the hardware uart to 250k and I am transmitting only. In doing a bunch of googling, I find that I have to change the spbgr register to a value of 4 to achieve this (from what I can gather) when using a 20Mhz crystal. Can I assume that if I set the baud rate like this..
#define usart_baud_rate 250000
that I don't have to fiddle with the spbgr register?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
An advantage of HSer routines is that any baud can be used including non standard bauds. I have not tested non standard bauds because the terminal I used only had the standards ones. 250000 is one of the dropdowns on my terminal. I have run HSer routine up to 2 megabaud with a 16 mhz internal osc. The spgbr should be set correctly by the compiler.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I've been using GCB a bit using a pic16F1825 and pic12F1840 always using the internal oscillator at 32mhz. I am working on a project where timing seems to be somewhat important and it is recommended that I run my pic at 20mhz. Looking at the data sheet and chip data in GBC, this doesn't seem to be an option when using the internal oscillator, so I will use a 20mhz crystal and two 22pf caps.
Here is my dilema... I have looked but can't find an example of what the configuration should look like. I have always only used...
chip 16f1825, 32
and thats it.
Also, I have seen where you can use a slower crystal and somehow multiply the clock rate internally to the pic, but can't seem to figure that out at this point.
Where can I find some info on how the config should look when using an external oscillator and configurations in general. I can't find any info on what should be defined (or the actual syntax to do so) for the pic to work correctly other than what I have always used (internal oscillator).
Thanks!!!!
Hi Jim,
Refer to the PIC 18F1825 Datasheet Page 54 (Figure 5.1). This shows a block diagram of the oscillator module. With this we can see that there is only one practical way to acheive 20 MHz. That is with a 20 Mhz crystal or ceramic oscillator and with the PLL turned off.
Reading on you will see that as a general rule, for Frequencies above 16MHz, HS mode should probably be used.
So the Configuration setting will be for an external crystal with the PLL turned off.
At this point I usually open up the GCB chipdata file for the chip in question. This will be 16F1825.dat in the chipdata folder. Then look in the [ConfigOps] section towards the end of the file.
You will see:
For HS:.......... #Config OSC = HS
For PLL ........: #Config PLLEN = OFF
Therefore the basic Congiuration will be:
To confirm that things were written correctly you can create a .gcb file with only the lines above. The click on the ASM button in the IDE to create an ASM file. Then External Tools > Open ASM.
The configuration section at the top of the ASM file should show your config settings along with some other default settings. Should look like this:
Good Luck
Bill
Last edit: William Roth 2016-03-14
Great answer,
Thanks Bill, not sure about the OP but I certainly just learn a lot of useful info.
Cheers
Chris
Thanks Bill. That is exactly what I was looking for. Where can I find information like this?
I am working on a project and need to be able to manipulate registers and the like and I am trying to find some information specifically on the syntax used by GCB to do this. For instance, the receive status and control register uses 8 bits to enable and disable certain functions. So the register is called RCSTA. Lets say I want to enable SPEN (bit 7), SREN (bit5) and CREN (bit 4) and disable the rest of the bits. Can you use SPEN = 1, SREN = 1 and CREN = 1, or do you write a hex value of B0 to the RCSTA register, and what is the GCB syntax for doing things like this? Can you point me in the right direction? Resgister manipulation is new to me and I can't seem to find alot of syntax examples yet.
Thanks for your help!!!!!
And... we have a lot standard libraries for this specific register.
What comms method are you planning? We have hardware serial, I2C, I2C2, SPI etc and more built in. We also have many user contributed comms libraries.
Always worth asking here before starting a project.
Using the RCSTA as the example you have a number of methods to update.
Update the complete register
RCSTA = 0x55 or RCSTA = 0b01010101 or RCSTA = 86 will update the all eight bits, the byte, of the register.
Update a specfic bit via bit alias
Registers are mapped to bits within the memory map via an alias. The chipfile (the .DAT file) contains these mapping. Again using RCSTA as the example. This is the register from a 16f1939.
RX9D,RCSTA,0
OERR,RCSTA,1
FERR,RCSTA,2
ADDEN,RCSTA,3
CREN,RCSTA,4
SREN,RCSTA,5
RX9,RCSTA,6
SPEN,RCSTA,7
This shows the 8 bits. You can set any bit register alias as follows:
Set FERR On (or Off) or FERR = 1 (or = 0).
Update a specfic bit via bit addressing
If you want update a single bit. Ensure you know your bit addressing. This is NOT good practice as follows:
RCSTA.7 = 1
RCSTA.6 = 0
Update a register bit with another bit
You can only do this with Great Cow BASIC v.0.95.000 or greater.
You can set a bit with a bit using SetWith(). As follows:
IF ( something = something_else ) THEN **SetWith ( SPEN , myByte.7 ) **
Note
If you write to a register that does not exist.... Great Cow BASIC will simply create a byte variable. So, you can always check your ASM for Byte variable of the register you 'thought' existed.
Also, you do not need to state the Register and the Register Bit alias. This is bad practice. While this helps you remember the register and the bit there are cases where this is not portable between microcontrollers.
RCSTA.CREN = 1
Hope this helps.
What to write a device driver to gain some experience? :-)
Last edit: Anobium 2016-03-14
Evan, this is GREAT information, exactly what I was looking for. I will give this a whirl. Thank you for this. If one needs to check a register status, do you do something like this...
if FERR = 1 then... or would you do...
if RCSTA.FERR = 1 then... or would you do...
if RCSTA.1 = 1 then...
Thanks again!
Last edit: viscomjim 2016-03-15
**Conditions **
When using conditions use the single alias. There is no requirement to use ByteAlias.BitAlias
The following is a valid conditional test.
If FERR = 1 THEN
....
END IF
Again, do not use constants like .1. Using constants can cause issues when adapting to other microcontrollers.
Perfect!!! Thanks Evan!!!!
One more question on the oscillator... Looking through the example files on using the software serial I found this...
; ----- Configuration
#chip 12f1840, 4
'Set internal oscillator to 4 MHz
Set IRCF = b'1101'
Assuming the #chip line tells GCB to run the 12f1840 at 4 MHz, why is the line Set IRCF = b'1101" used? Is this line necessary to run at 4MHz?
Thanks!!!!
No that line is not required. Great Cow BASIC should set the frequency bits for you. I will remove from the demo.
There are cases where the bits are not set correctly. If this happens please let us know, as, the intent is to have these bits set automatically.
In this same situation, I need to set the baudrate of the hardware uart to 250k and I am transmitting only. In doing a bunch of googling, I find that I have to change the spbgr register to a value of 4 to achieve this (from what I can gather) when using a 20Mhz crystal. Can I assume that if I set the baud rate like this..
that I don't have to fiddle with the spbgr register?
An advantage of HSer routines is that any baud can be used including non standard bauds. I have not tested non standard bauds because the terminal I used only had the standards ones. 250000 is one of the dropdowns on my terminal. I have run HSer routine up to 2 megabaud with a 16 mhz internal osc. The spgbr should be set correctly by the compiler.
Excellent, thanks mmotte!