PortCounter

Technical questions regarding the XTC tools and programming with XMOS.
Paco
Member
Posts: 8
Joined: Thu Apr 11, 2013 7:25 pm

PortCounter

Post by Paco »

Hello,

I got porblems with the pourtcounter. My aim is to create a DataFrame with one Startbit, Databits and two Endbits. I used the port counter like in the tutorial of the UART to create it. It works good till i reach the Endbits. I want to create two of them but just get one, even if i give the instruction twice. Its the last instruction bevor the function ends. When I add a instruction at the end then this one is ignored...it seems like the last instruciton of a function is ignored. Is there a thing which i don't get so far? Or something which i have to know about the Portcounter? Maybe it would help me if someone just shortly explain how this timer works:S?

I would be glad for help...it takes my sleepless nights;)

With friendly greetings
Paco


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

You didn't show your code, so we cannot say for sure; but your
problem sounds like a common problem with timed ports.

When you do "P @ T <: X;", it does _not_ mean "wait until time T,
and then output X to P". It means "at time T, output X to P". So
there is no waiting, the code will keep running. When you attempt
an output while there is still one pending it _does_ block however,
until that pending one is done.

In your case, perhaps after the function that ends with those two
stop bits you immediately do a non-timed output to the port, without
waiting for the pending output to finish first. At the end of your
function, call "sync(P);" to make it wait.
Paco
Member
Posts: 8
Joined: Thu Apr 11, 2013 7:25 pm

Post by Paco »

Okay, here is my code. I read out the array "transmit" with three bytes.
I already try the instruction sync(txd) but it still don't work.
Whats confusing me is, if i add another instruction like " time += BIT_TIME; txd @ time<: 0;" under my Stop bits, i suddenly get my two stopbits but the instuction which i add is not seen on the waveform...

Code: Select all

#include <platform.h>
 
#include <xs1.h>
#include <stdio.h>
#define BIT_RATE 250000
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE

void takeByte(out port txd, char b[]);
 
void seriByte(out port txd, int byte);
 
out port txd = XS1_PORT_1H;
 

int main (void){
 
char transmit[] = {0b00110101, 0b00110011, 0b00001111 };
 
takeByte(txd, transmit);
txd <: 0;
 
 
return 0;
 
}
 
void takeByte(out port txd, char b[]){
 
        for (int i = 0; i < 3; i ++)
 
            seriByte(txd, b[i]);
}
 
void seriByte(out port txd, int byte){
 
        int z;
        unsigned time;

        txd <:0 @ time;        
 
        for( z=0; z<22; z++){
 
        time += BIT_TIME;            //BREAK
 
        txd  @ time <: 0;
 
        }
 
        time += BIT_TIME;               //MAB
 
        txd @ time<: 1;
 
        time += BIT_TIME;               //HOLD
 
        txd @ time<: 1;
 
 
 
        time += BIT_TIME;               //STARTBIT
 
        txd @ time <: 0;
 
 
 
        for (z = 0; z < 8; z++) {       //DATA-BITS
 
          time += BIT_TIME;
 
          txd @ time <: >> byte;
 
        }
 
        time += BIT_TIME;               //STOP
 
        txd @ time<: 1;
 
        time += BIT_TIME;               //STOP
 
        txd @ time<: 1;
 
}
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

I think I see your problem.

When you write

Code: Select all

        time += BIT_TIME;               //STOP
 
        txd @ time<: 1;
it seems you expect this to mean "take txd high for duration BIT_TIME".
But instead it means "when BIT_TIME has passed, take txd high".

If you write everything like this:

Code: Select all

        txd @ time<: 1;               //STOP
 
        time += BIT_TIME;
(with the @ at the other side for the first bit, and ending with an extra
"txd @ time<: 1;"), things will probably work better.
Paco
Member
Posts: 8
Joined: Thu Apr 11, 2013 7:25 pm

Post by Paco »

You were right, i missunderstood the function. Now it works!:) Thanks for your help, now it makes sense.

Greez Paco