Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Marco

Pages: [1] 2
1
FreescaleTM MC9S12NE64 / Initialize Timer Port on power on
« on: October 09, 2009, 05:25:40 PM »
Hi, Mark

I am trying to control a RC servo, I know it works but when i turn on the power the servo times out before the timer port is initialized.

Can you please tell me if I can initialize the timerport imediately on power up.  Initializing it in my task takes to long.

Code: [Select]
TSCR1 = 0x80;   //10000000 (Turn on the Timer port)
      TSCR2 = 0x03;   //00000011 (Set Prescale to 8)
      TIOS = 0xF0;    //11110000 (set all channels to output compare)
      TTOV = 0xF0;    //11110000 (enable Toggle output on overflow)
      TCTL1 = 0xAA;   //11111111 (OutputModeX, OutputLevelX) 0x55;//0xAA; //0xFF;

Thanks

Marco

2
FreescaleTM MC9S12NE64 / Re: 9S12Ne64 - Bus Speed
« on: October 08, 2009, 05:59:27 AM »
Thanks

3
FreescaleTM MC9S12NE64 / 9S12Ne64 - Bus Speed
« on: October 07, 2009, 10:08:37 AM »
Hi, Mark

Can you please tell me what the configured bus speed is in uTasker?

Thanks

4
FreescaleTM MC9S12NE64 / Re: Global Hardware Timer
« on: February 26, 2009, 03:20:47 PM »
Thanks Mark!

5
FreescaleTM MC9S12NE64 / Re: Global Hardware Timer
« on: February 25, 2009, 05:05:32 PM »
Hi Mark

I am trying to do a frequincy measurement from one of the timer ports, by measuring the period.  I noticed that GLOBAL_HARDWARE_TIMER in NE64.c makes use of the timer function, is this set up for utasker to function.  Or can I still configure the timer port to measure my input frequincy on PTT7?

     unsigned int intRisingEdge;
             unsigned int intFreq;
     TSCR1    = 0x80;
     TIOS    = 0x0;
     TSCR2    = 0x06;
     TCTL4    = 0x00;
     TFLG1    = 0x80;
     while (!(TFLG1 & 0x80));
     intRisingEdge = TC0;
     while (!(TFLG1 & 0x08);
     intFreq = 1 / (TC0 - intRisingEdge);


6
µTasker general / Re: about the udp use!
« on: February 24, 2009, 07:27:44 PM »
Thanks for that Mark, I'm sure that will take some load off of the CPU!

Cheers

Marco

7
µTasker general / Re: about the udp use!
« on: February 24, 2009, 02:21:53 PM »
Hi Mark, I continued to play around with UDP, I have now grouped all the ADC values along with some other variables into a char array and I'm sending out an updated packet every 50ms.

Code: [Select]
static char StrMsg[36]= "String Build - Error"; // If string is not built this messege will be sent.

#define OWN_TASK               TASK_SUDP

#define UDP_BUFFER_SIZE        37                                        // buffer size for UDP test message
#define MY_UDP_PORT            1234

#define E_TIMER_NEXT_MESSAGE   1

typedef struct stUDP_MESSAGE
{
    unsigned short usLength;
    UDP_HEADER     tUDP_Header;                                          // reserve header space
    unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];                       // reserve message space
} UDP_MESSAGE;

static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
    return 0;
}


// <<<<<<<<<<<<<<<<<<< Send UDP Function >>>>>>>>>>>>>>>>
extern void fnSUDP(TTASKTABLE *ptrTaskTable) 
{
    static USOCKET MyUDP_Socket = -1;
    static UDP_MESSAGE *ptrUDP_Frame;
    const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
    QUEUE_HANDLE        PortIDInternal = ptrTaskTable->TaskID;           // queue ID for task input
    unsigned char       ucInputMessage[HEADER_LENGTH];                   // reserve space for receiving messages
   
    if (MyUDP_Socket < 0) {                                              // only perform once
        ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
        MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
        fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
        uMemcpy(&ptrUDP_Frame->ucUDP_Message,StrMsg, UDP_BUFFER_SIZE);
        fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
        uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(0.05*SEC), E_TIMER_NEXT_MESSAGE );
    }

    while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
        case TIMER_EVENT:
            if (E_TIMER_NEXT_MESSAGE == ucInputMessage[MSG_TIMER_EVENT]) {
                uMemcpy(&ptrUDP_Frame->ucUDP_Message,StrMsg, UDP_BUFFER_SIZE);
                fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(0.05*SEC), E_TIMER_NEXT_MESSAGE );
            }
            break;

        case  TASK_ARP:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
                case ARP_RESOLUTION_SUCCESS:                             // IP address has been resolved (repeat UDP frame).
                    uMemcpy(&ptrUDP_Frame->ucUDP_Message,StrMsg, UDP_BUFFER_SIZE);
                    fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                    break;

                case ARP_RESOLUTION_FAILED:                              // IP address could not be resolved...
                    break;
            }
            break;
        }
    }
}

I wrote a simple program, to convert an unsigned intiger into 2 chars, I'm sure there is a simpler way to do it in C.

Code: [Select]
// <<<<<<<<<<<<<  Convert 2byte int to 2 chars >>>>>>>>>>>>>>>>>>
unsigned char IntToString(unsigned int InpInt, int ChrNum)
{
  char OutChar[3];
  char RetChar;
  OutChar[1]=(char)(InpInt / 256);
  OutChar[2] =(char)(InpInt%256);
  RetChar = OutChar[ChrNum];
  return((char)RetChar);
}

I then wrote a program which is on a timer from TaskConfig.h, which then combines all the chars into StrMsg.

Code: [Select]
extern void fnBuildPacket(TTASKTABLE *ptrTaskTable) 
{
    char StrStart[2]= "[";  //Start of Data
    char StrStop[2]= "]";   //Stop of Data
    unsigned int intTPS;
    unsigned int intSPS;
    unsigned int intSpd;
    unsigned int intRpm;
    unsigned int intTmp;
    unsigned int intPsi;
    unsigned int intAlt;
    unsigned int intOLS;
    unsigned int intFLS;
    unsigned int intTrm;
    char chrRSK = 'R';
    char chrFNR = 'N';
    char chrCrC = 'F';
    char chrSpL = 'F';
    char chrSyC = 'T';
     
    static int cntrA;  // Counter needed for endcap placement on Packet
    static int cntrB;  // Counter needed for 2byte data segment placement on packet
   
    static unsigned int cntrC = 0;

    cntrC++;   //Test Data used to check update of transmission.
   
    intTPS = ATDDR0H;  // ADC channel 0
    intSPS = ATDDR1H;  // ADC channel 1
    intSpd = ATDDR2H;  // ADC channel 2
    intRpm = ATDDR3H;  // ADC channel 3
    intTmp = ATDDR4H;  // ADC channel 4
    intPsi = ATDDR5H;    // ADC channel 5
    intAlt = ATDDR6H;    // ADC channel 6
    intOLS = ATDDR7H;  // ADC channel 7
    intFLS = cntrC;
    intTrm = cntrC;
   
// <<<<<<<<<<<<<<<<< MSG string Construction >>>>>>>>>>>>>>   
   
    // Place the endcaps on the string
    for (cntrA = 0; cntrA <= 1; cntrA++)
    {
      StrMsg[cntrA] = StrStart[cntrA]; //Add the start Bracket
      StrMsg[cntrA + 26] = StrStop[cntrA]; //Add the Stop Bracket

    }
    // Add all the 2 Byte data segments
    for (cntrB = 0; cntrB <= 1; cntrB++)
    {
      StrMsg[cntrB + 1] = IntToString(intTPS, cntrB + 1);
      StrMsg[cntrB + 3] = IntToString(intSPS, cntrB + 1);
      StrMsg[cntrB + 5] = IntToString(intSpd, cntrB + 1);
      StrMsg[cntrB + 7] = IntToString(intRpm, cntrB + 1);
      StrMsg[cntrB + 9] = IntToString(intTmp, cntrB + 1);
      StrMsg[cntrB + 11] = IntToString(intPsi, cntrB + 1);
      StrMsg[cntrB + 13] = IntToString(intAlt, cntrB + 1);
      StrMsg[cntrB + 15] = IntToString(intOLS, cntrB + 1);
      StrMsg[cntrB + 17] = IntToString(intFLS, cntrB + 1);
      StrMsg[cntrB + 19] = IntToString(intTrm, cntrB + 1);
    }
    // Add aditional Controlls
    StrMsg[21] = chrRSK;
    StrMsg[22] = chrFNR;
    StrMsg[23] = chrCrC;
    StrMsg[24] = chrSpL;
    StrMsg[25] = chrSyC;
}

I just thought its a nice thing to play around with and mabe someone might find it usefull, I also uploaded my UDP test program for windows. Which makes use of winsock32

8
FreescaleTM MC9S12NE64 / Re: Reading Analog to Digital Port
« on: February 24, 2009, 01:41:32 PM »
Thanks Mark, that really put me on the right track.  I setup the port up so that it scans continiously, and set it to multi-channel Mode.

Code: [Select]
    static int State = 0;

    if(State==0)
    {
      ATDCTL3 = 0;       // Read all 8 Channels
      ATDCTL4 = 0xf3;    // 8 bit mode suitable for our bus speed
      ATDCTL2 = ADPU;    // power up the ADC
      ATDCTL5 = 0x30;       // Multi-Channel, Scan Mode
      State = 1;
    }

I just inserted this inside a looping function, and it only runs once.

Because the ADC scans continiously, I can just use ATDDR0H~ATDDR7H to aquire the ADC values.  I have tested all the ATD ports symoultaniously on the NeCore12Board, and it seems to work quite well.

9
FreescaleTM MC9S12NE64 / Reading Analog to Digital Port
« on: February 16, 2009, 04:53:22 PM »
Hi

I'm trying to figure out how to read analogue on the PAD on the MC9S12NE64, can someone please point me in the right direction?

Cheers

Marco

10
µTasker general / Re: about the udp use!
« on: February 16, 2009, 03:51:46 PM »
Thank you so much!  It works, I realy apprechiate all the help!

Thanks again

Marco

11
µTasker general / Re: about the udp use!
« on: February 16, 2009, 07:58:49 AM »
Hi Mark

Thanks for that I realy apprechiate the help! Am i suposed to remove the following from TaskConfig.h?

Code: [Select]
  { "fnFBWOE", fnFBWOE, NO_QUE, (DELAY_LIMIT)(5 * SEC), (DELAY_LIMIT)(2 * SEC), UTASKER_STOP},  // fnFBWOE Task run after 5s and run periodically every 2 seconds.

Do I have to change anything else in TaskConfig.h?

I put "uTaskerStateChange(fnFBWOE, UTASKER_ACTIVATE);" just after "uTaskerStateChange(TASK_DEBUG, UTASKER_ACTIVATE);" in application.c.  I'm getting an error "expected signed char, given void".  Is there anything else I'm suposed to do in application.c?

Cheers

Marco

12
µTasker general / Re: about the udp use!
« on: February 15, 2009, 06:27:45 PM »
Hi Mark

I'm now getting loads of compile errors, it still has a problem with static UDP_MESSAGE *ptrUDP_Frame;.  The error is "2450: Expected: ,"

By the way am I suposed to change extern void fnFBWOE(TTASKTABLE *ptrTaskTable)  to extern void fnFBWOE(void)  as that also gives me compile errors.

Code: [Select]
#include "config.h"


static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
  return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable) 
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  unsigned char       ucInputMessage[HEADER_LENGTH];                  // reserve space for receiving messages
  static USOCKET MyUDP_Socket;
  static UDP_MESSAGE *ptrUDP_Frame;
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
  ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
 
  while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
      switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
      case  TASK_ARP:
          fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
          switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
          case ARP_RESOLUTION_SUCCESS:                                 // IP address has been resolved (repeat UDP frame).
              fnSendUDP(MyUDP_Socket, ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
              break;

          case ARP_RESOLUTION_FAILED:                                  // IP address could not be resolved...
              break;
          }
          break;
      }
  }


}

Cheers

Marco

13
µTasker general / Re: about the udp use!
« on: February 15, 2009, 06:05:57 AM »
Hi Mark

I have actually tried "static UDP_MESSAGE *ptrUDP_Frame;" im getting an error "C2540: Expected: ,".  I'm not sure why that is.

Code: [Select]
#include "config.h"


static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
  return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable)
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  static USOCKET MyUDP_Socket;
  UDP_HEADER     tUDP_Header;
  static UDP_MESSAGE *ptrUDP_Frame;
  ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame
 
  unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
}

Cheers

Marco

14
µTasker general / Re: about the udp use!
« on: February 14, 2009, 12:53:26 PM »
Hi Mark

Thanks I got that part to work, and I aslo figured out how to define MyUDP_Socket, I now have problems with ptrUDP_Frame.  Can you please tell me how to define ptrUDP_Frame.  I searched for it, but could not find it.

Code: [Select]
#include "config.h"


static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
  return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable)
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  static USOCKET MyUDP_Socket;
  UDP_HEADER     tUDP_Header;
 
  unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
}

Cheers

Marco

15
µTasker general / Re: about the udp use!
« on: February 11, 2009, 05:12:00 PM »
Hi Mark

Sorry, I'm stuck again.  Ok this is what I got so far, how ever the compiler sais fnUDPListner is not declared.

Code: [Select]
#include "config.h"


extern void fnFBWOE(TTASKTABLE *ptrTaskTable)
{
  #define OWN_TASK    fnFBWOE
  static USOCKET MyUDP_Socket;
 
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
  fnBindSocket(MyUDP_Socket, 1234);
 
  const unsigned char ucIP[] = {192,168, 0, 101};
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", 11);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, 1234, (unsigned char*)&ptrUDP_Frame->tUDP_Header, 11, OWN_TASK);
}

I tried to declare it as the following, but the compiler sais its an ileagal storage class.

Code: [Select]
  static int  fnUDPListner(USOCKET c, unsigned char uc, unsigned char *ucIP, unsigned short us, unsigned char *data, unsigned short us2);

What should I declare fnUDPListner as?


Cheers

Marco

Pages: [1] 2