strahd_von_zarovich
Advanced Member level 4
Hi , i want to know how fast i can change my output pin's state. It's system clock is 80MHz and peripheral clock is 10 MHz .
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <plib.h>
#define SYSCLOCK ( 80000000UL )
#define PERCLOCK ( 10000000UL )
#define cntMsDelay 1
#pragma config FNOSC = PRIPLL
#pragma config POSCMOD = EC
#pragma config FPLLIDIV = DIV_2
#pragma config FPLLMUL = MUL_20
#pragma config FPLLODIV = DIV_1
#pragma config FPBDIV = DIV_8
#pragma config FWDTEN = OFF
#pragma config CP = OFF
#pragma config BWP = OFF
#pragma config PWP = OFF
void DelayInit()
{
unsigned int tcfg;
/* Configure Timer 1. This sets it up to count a 10Mhz with a period of 0xFFFF
*/
tcfg = T1_ON|T1_IDLE_CON|T1_SOURCE_INT|T1_PS_1_1|T1_GATE_OFF|T1_SYNC_EXT_OFF;
OpenTimer1(tcfg,0xFFFF); //FFFF
}
void DelayMs(int cms)
{
int ims;
for (ims=0; ims<cms; ims++) {
WriteTimer1(0);
while (ReadTimer1() < cntMsDelay);
}
}
int main()
{
DelayInit();
PORTSetPinsDigitalOut (IOPORT_B, BIT_10|BIT_11| BIT_12|BIT_13);
PORTClearBits(IOPORT_B, BIT_10|BIT_11| BIT_12|BIT_13);
while(1){
PORTWrite(IOPORT_B, BIT_10);
PORTClearBits(IOPORT_B, BIT_10);
}
return 0;
}
PORTWrite(IOPORT_B, BIT_10);
PORTClearBits(IOPORT_B, BIT_10);
Hi , i want to know how fast i can change my output pin's state. It's system clock is 80MHz and peripheral clock is 10 MHz .
#pragma config POSCMOD = EC
// enable cacheability for KSEG0
CheKseg0CacheOn();
// configure the cache for prefetch and 2 wait-state operation */
mCheConfigure(CHE_CONF_WS2 | CHE_CONF_PF_C);
Possibly 5MHz toggle speed with Assembly Code.
Code:#pragma config POSCMOD = EC
Are you using external clock ?
while(1)
{
LATB = 0xFFFFFFFF;
LATB = 0x00000000;
...
.
....
.
.
.
..
LATB = 0xFFFFFFFF;
LATB = 0x00000000;
}
#define cntMsDelay 1
void DelayInit()
{
unsigned int tcfg;
/* Configure Timer 1. This sets it up to count a 10Mhz with a period of 0xFFFF
*/
tcfg = T1_ON|T1_IDLE_CON|T1_SOURCE_INT|T1_PS_1_1|T1_GATE_OFF|T1_SYNC_EXT_OFF;
OpenTimer1(tcfg,0xFFFF); //FFFF
}
void DelayMs(int cms)
{
int ims;
for (ims=0; ims<cms; ims++) {
WriteTimer1(0);
while (ReadTimer1() < cntMsDelay);
}
}
It's difficult to decide if your intended application is feasible without knowing all details. But there's room for optimization in many regards, e.g. using the core timer for delays, not writing the timer.
PIC32/MIPS is a complex device, it takes more than a few days to understand how to utilize it. By the way, did you check the prefetch/cache point?
Hi and thank you for your replies. Using LATB i can see 2 MHz , but what i need to do is bitbanging at speed of at least 1 MHz which looks look like nearly impossible. Because i need to use other functions like delay(first Data then clock ....) . Is there a way to do this, my delay functions run to slowly.
Code:#define cntMsDelay 1 void DelayInit() { unsigned int tcfg; /* Configure Timer 1. This sets it up to count a 10Mhz with a period of 0xFFFF */ tcfg = T1_ON|T1_IDLE_CON|T1_SOURCE_INT|T1_PS_1_1|T1_GATE_OFF|T1_SYNC_EXT_OFF; OpenTimer1(tcfg,0xFFFF); //FFFF } void DelayMs(int cms) { int ims; for (ims=0; ims<cms; ims++) { WriteTimer1(0); while (ReadTimer1() < cntMsDelay); } }
Can't you use hardware SPI instead of bit-banging to send the data?
My suggestion was to try the settings in post #6. If they have any effect you are probably motivated to read about prefetch and caching.
The way SPI works is to take the value you place into the buffer which is then used as a shift-register and clocked out, one bit at a time (normally MSB first). The 'other' device' uses the clock pulses to know when to read the signal from the first device which it loads into a shift register. AS both devices do the same thing (i.e. they send and receive a bit on each clock pulse), SPI is typically seen as an 'exchange' process.I can use SPI , but isnt it a protocol , can i use it for loading data to shift register ?