View previous topic :: View next topic |
Author |
Message |
curt2go
Joined: 21 Nov 2003 Posts: 200
|
Fastest way to set pin output |
Posted: Thu Jul 06, 2017 3:07 pm |
|
|
Ok. I know I always have weird questions but I am still playing around with outputting data to a CODEC chip.
I am running a 24EP512GP810 at 140MHz
I am outputting a 705kHz PWM out to the CODEC chip to synchronise as well looking at the OC1 interrupt. I was sending it to an external interrupt but was since playing with the OC1 interrupt.
If I am ready to send out bits to the CODEC I want them to clock out with the PWM. But I need to send the output to the pin as fast as possible to stay in sync with the PWM to clock the bit out.
I am also taking a 16bit variable and shifting left so I have the MSB to send out the PIN.
I may be doing this completely backwards but let me know if you have any thoughts.
Below is taking 4 instructions to output to the pin in the interrupt. It takes the same to set the PORTA.0 Latch as well.
Is there a way to set the pin high or low in the main and then in the interrupt just set the pin to the latch?
Code: | unsigned int pp = 0xAAAA;
#bit bit0 = pp.15
#byte PORTA = 0x0E22
#bit bitOut = PORTA.0
#bit LATA0 = 0x0E04.0
int1 ppBits = 0;
#INT_OC1
void rrr(){
bitOut = bit0;
}
/// this is in MAIN
//ppBits = bit_test(pp,15);
pp = pp<<1; |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 06, 2017 9:18 pm |
|
|
Post the manufacturer and part number of the codec, so we can consider
the whole problem. A lot of times, if we take the poster's method and
try to optimize it, it may be a mistake. There may be a lot simpler way
to do it if we are given full information. |
|
|
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Thu Jul 06, 2017 9:27 pm |
|
|
Thanks PCM its AK4637.
I can either that the BICK and FCK from it or generate them myself.Either way I am also having an issue with the interrupt taking too long to even fire. The BICK will be at 32x22.05KHz. So by the time the interrupt fires I will be out of sync by about 1/2 bit.
I have been just playing with different configurations to see what is possible. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 06, 2017 10:03 pm |
|
|
Quote: | I am running a 24EP512GP810 at 140MHz |
I can't find this PIC, so I assume you must mean "GU" instead of GP.
This PIC has a DCI interface, which is designed to work with an audio codec. See this section of the 24EP512GU810 data sheet:
Quote: | 24.0 DATA CONVERTER INTERFACE (DCI) MODULE |
|
|
|
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Thu Jul 06, 2017 10:07 pm |
|
|
Yes. Sorry. I always get them mixed. But my production units will be using the 24EP256GP206. Its does not have the DCI module. I have the big Mikroe test board EasyPic Fusion 7 that I proto stuff on for new ideas. That is why I am using the bigger part. I am running the production part at the same speed though. Hope that's not too confusing. |
|
|
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Thu Jul 06, 2017 10:42 pm |
|
|
Just some more info. I am doing nothing in the main except for a output_toggle(PIN_G0); The frequency of this is only 4.39MHz. This does seem low?
Here is my fuses.
Code: |
#fuses NOJTAG, IESO, PROTECT, NOWDT, DEBUG,OSCIO
#fuses NOWINDIS, NOIOL1WAY, IESO//,FRC_PS,FRC_PLL
#use delay(clock=140000000,internal=140000000) |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Jul 07, 2017 5:31 am |
|
|
Perhaps a silly question and I don't use the 24 series but... are you using fast_io() or standard_IO() ?
Where speed is required fast_io is, well, faster..... |
|
|
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Jul 07, 2017 7:28 am |
|
|
Well. There is no such thing as a silly question.
The silly answer though is NO. I am not. Don't know how i forgot that.
I will put that in, like it should be and give it a shot. I will let you know.
Man I feel a little stupid right now. :( |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1354
|
|
Posted: Fri Jul 07, 2017 8:02 am |
|
|
curt2go wrote: | Just some more info. I am doing nothing in the main except for a output_toggle(PIN_G0); The frequency of this is only 4.39MHz. This does seem low?
Here is my fuses.
Code: |
#fuses NOJTAG, IESO, PROTECT, NOWDT, DEBUG,OSCIO
#fuses NOWINDIS, NOIOL1WAY, IESO//,FRC_PS,FRC_PLL
#use delay(clock=140000000,internal=140000000) |
|
Even without fast_io, that frequency is too slow. Can you post a small fully compilable example of your toggling (so others can take exactly what you are using and put into their own test beds)? That should only be <= 20 lines of code so it should be easy to generate.
I don't know that chip specifically, but some of them cannot start with the PLL running right off the bat. They will start up on the internal FRC (no PLL) instead and you have to put in the code to switch the clock source. What you are seeing sounds more like that. |
|
|
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Fri Jul 07, 2017 11:29 am |
|
|
I edited this. I was playing and forgot to comment out the FRC_DIV_BY_16
Code: | #include <24EP512GU810.h>
#DEVICE icd=1
#device PASS_STRINGS=IN_RAM
#device CONST=ROM
#device adc=10 *=16
// Setup configuration bits
#fuses NOJTAG, IESO, PROTECT, NOWDT, DEBUG,OSCIO
#fuses NOWINDIS, NOIOL1WAY, IESO//FRC_DIV_BY_16//,FRC_PS,FRC_PLL
#use delay(clock=140000000,internal=140000000)
void main(){
enable_interrupts(INTR_GLOBAL);
while(1){
output_toggle(PIN_G0);
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Jul 08, 2017 5:52 am |
|
|
hmm..
OK maybe another silly thing...
I see this" icd=1 ", does that mean the ICD IS enabled ? I do not use ICDs or debuggers so not sure what the syntax means.
IF so that may slow down things.
Also I assume program is compiled in 'release' mode not 'debug'...
There's only so many straws in a bale but eventually we'll pull the right one !
Jay |
|
|
Alphada
Joined: 19 Jun 2017 Posts: 27
|
|
Posted: Sat Jul 08, 2017 3:44 pm |
|
|
Code: | #byte PORTA = 0x0E22 |
Is that the address of that register? am I correct?
Where do i find those addresses? on the chip datasheet or is found on the chip .h driver?
Excuse me I'm learning. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sat Jul 08, 2017 6:18 pm |
|
|
In the datasheet; every PIC has 100s of pages of 'need to know' information located there.
While there is a 'core' of technology that is common to all, each series or family of PICs have specialty features....so reading is very,very important if you want to 'play with PICs'. |
|
|
Alphada
Joined: 19 Jun 2017 Posts: 27
|
|
Posted: Sat Jul 08, 2017 6:49 pm |
|
|
temtronic wrote: | In the datasheet; every PIC has 100s of pages of 'need to know' information located there.
While there is a 'core' of technology that is common to all, each series or family of PICs have specialty features....so reading is very,very important if you want to 'play with PICs'. |
Thx |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Sat Jul 08, 2017 7:13 pm |
|
|
Alphada wrote: | Code: | #byte PORTA = 0x0E22 |
|
The compiler has a very nice feature, "getenv" that saves you from looking up the addresses of the special function registers (SFRs). Use it like this:
Code: | #byte PORTA=getenv("sfr:PORTA") |
|
|
|
|