Page 3 of 3 FirstFirst 123
Results 41 to 54 of 54

Thread: PropCS - a small project

  1. #41

    Default Re: PropCS - a small project

    I would suggest doing a shorter test first to determine if you have the 6% error or 0.3% error. In 1000 seconds (about 17 minutes) you will see a 60-second error at 6%, or a 3-second error at 0.3%. If the larger error is due to daylight savings you could set the date/time for March 9, 2012 at 23:59:55, and see what happens after it rolls over to March 10. You have to have daylight savings enabled for it to do the adjustment.

  2. #42

    Default Re: PropCS - a small project

    Quote Originally Posted by Rsadeika View Post
    ... they all re-boot PropCS when the USB is plugged back in. Now, I am not sure what I have to do to overcome this, let alone understand what is really happening, an explanation would be appreciated.
    Ray, the reset is caused by the computer's USB identification sequence.

  3. #43

    Default Re: PropCS - a small project

    I have just tried the DST again, using Dave Hine's suggestions. Primarily, I used 23:59:55 as the time. I tried 3/9/2012, 3/10/2012, and 3/11/2012, none of these settings showed moving forward an hour. I also tried 11/3/2012, 11/4/2012, and 11/5/2012, none of these settings showed moving back an hour. And still shows on a normal time run, using DST, when it passes midnight it moves time an hour forward. At this point I am not sure if there are problems with the DST setting in the library, or if there is something more to it. I thought I saw an AM/PM setting in the library, but now I am not sure.

    Ray

  4. #44

    Default Re: PropCS - a small project

    Quote Originally Posted by Rsadeika View Post
    I have just tried the DST again, using Dave Hine's suggestions. Primarily, I used 23:59:55 as the time. I tried 3/9/2012, 3/10/2012, and 3/11/2012, none of these settings showed moving forward an hour. I also tried 11/3/2012, 11/4/2012, and 11/5/2012, none of these settings showed moving back an hour. And still shows on a normal time run, using DST, when it passes midnight it moves time an hour forward. At this point I am not sure if there are problems with the DST setting in the library, or if there is something more to it. I thought I saw an AM/PM setting in the library, but now I am not sure.

    Ray
    It is very unclear, do you enable DST when you set the time?

  5. #45

    Default Re: PropCS - a small project

    Yes, I enable DST.

    Ray

  6. #46

    Default Re: PropCS - a small project

    Quote Originally Posted by Rsadeika View Post
    I have just tried the DST again, using Dave Hine's suggestions. Primarily, I used 23:59:55 as the time. I tried 3/9/2012, 3/10/2012, and 3/11/2012, none of these settings showed moving forward an hour. I also tried 11/3/2012, 11/4/2012, and 11/5/2012, none of these settings showed moving back an hour. And still shows on a normal time run, using DST, when it passes midnight it moves time an hour forward. At this point I am not sure if there are problems with the DST setting in the library, or if there is something more to it. I thought I saw an AM/PM setting in the library, but now I am not sure.
    What time zone do you have it set to? You do know that you have to have a TZ variable set in the environment, right?

  7. #47

    Default Re: PropCS - a small project

    Is the program below still the best way to use the serial device? Has anything changed since the last time I tried this a few months ago? Unfortunately, the program below is not displaying anything out of that port.


    Code:
    /*
     * @file PropCS_C3_sa.c
     * This is the main PropCS_C3_sa program start point.
     */
    #include <stdio.h>
    #include <propeller.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <sys/rtc.h>
    #include <cog.h>
    #include <ctype.h>
    #include <sys/stat.h>
    #include <dirent.h>
    #include <sys/sd.h>
    #include <pthread.h>
    
    /*
     * Main program function.
     */
    int main(int argc, char* argv[])
    {
    
    /*                                                   Rx  Tx */
        char *serdevice = "SSER:115200, 23, 22";
        FILE *port = fopen(serdevice, "r+");
    
        waitcnt(CNT + CLKFREQ);
    
        fprintf(port,"This is the PropCS program!\n");
        fprintf(port,"Type 'help' for Commands list.\n");
    
        while(1)
        {
    
        }
        return 0;
    }

  8. #48

    Default Re: PropCS - a small project

    I've never tried opening a serial port, but maybe you need to specify "w" in fopen to be able to output to it.

  9. #49

    Default Re: PropCS - a small project

    Quote Originally Posted by Rsadeika View Post
    Is the program below still the best way to use the serial device? Has anything changed since the last time I tried this a few months ago? Unfortunately, the program below is not displaying anything out of that port.
    Ray your code should work as is. It works for me as serdevice "SSER:115200,1,0".

    I was thinking of providing a few library functions for this to simplify things.

    I.E.
    Code:
    char *serialDeviceString(char *buffer, char *name, int baud, int rxpin, int txpin);
    Then you could do this:

    Code:
    char buffer[40];
    FILE *p = fopen(serialDeviceString(buffer, "SSER:", 115200, 1, 0), "r+");
    
    setbuf(p,0); // turn off buffering
    fprintf(p, "Hello Ray");

  10. #50

    Default Re: PropCS - a small project

    Quote Originally Posted by jazzed View Post
    Ray your code should work as is. It works for me as serdevice "SSER:115200,1,0".

    I was thinking of providing a few library functions for this to simplify things.

    I.E.
    Code:
    char *serialDeviceString(char *buffer, char *name, int baud, int rxpin, int txpin);
    Then you could do this:

    Code:
    char buffer[40];
    FILE *p = fopen(serialDeviceString(buffer, "SSER:", 115200, 1, 0), "r+");
    
    setbuf(p,0); // turn off buffering
    fprintf(p, "Hello Ray");
    Steve,

    I'm a bit confused why you're transmitting serial on pins 1 and 0 unless you have an additional serial link setup between those pins and the PC or other agent. (I'm assuming the antecedent post(s) on this topic mentioned this, but they're not in this thread.)

    Nonetheless, I think we should support directly setting the serial parameters in global memory, and I believe we may want to push this as the most desired way to do it. Basically you include the following block of code in your code and change the values as appropriate:

    Code:
    /* globals that the loader may change; these represent the default
     * pins to use
     */
    unsigned int _rxpin = 31;
    unsigned int _txpin = 30;
    unsigned int _baud = 115200;
    Three notes about this:

    1) This works today with both Simple Serial, Full Duplex Serial and the Tiny library. All that's required is to make it more visible to the users (perhaps on the http://propgcc.googlecode.com/hg/doc/Library.html page).

    2) This takes the least amount of memory. This is important for LMM, because in that mode every byte counts.

    3) Note the comment "globals that the loader may change" - I took this code from lib/driver/serialparam.c! Also note the comment in the library Wiki page:

    Like the simple serial driver, the full duplex serial driver defaults to the values in the board specific _baud, _txpin, and _rxpin variables, and these may be overridden by passing a string containing baud,rxpin,txpin.
    Square this up with Issue 24 I reported a while ago: http://code.google.com/p/propgcc/issues/detail?id=24

    Summary: It's clear that the serial I/O designer(s) did not intend for the average user to even bother with setting the tx/rx pins and baud; instead these parameters were supposed to be taken from the board config and patched by the loader into the executable; therefore your program would automatically start communicating on the proper pins with the proper baud. Additionally, propeller-load's serial terminal (or any other serial terminal proxy) would automatically know the proper baud rate to communicate to your program.

    If realized, this would be the simplest solution and avoid the most problems for the vast majority of users.

    - Ted

  11. #51

    Default Re: PropCS - a small project

    Still can not get serdevice to work. I have tried my C3, and GG PPUSB boards, still no joy. I remember that when I was doing this, using the command terminal, I would have to have something like 'propeller-load ... -t', in the SimpleIDE Build Status window, I do not see anywhere that a '-t' is being used, does that make a difference?

    What I am trying to do is, using a variation of PropCS, use a pthread that would have a serdevice in it, to keep a port open for access through an RS-232 break-out board that I have attached. Since I was not having any luck doing it using pins 31,30, I thought I would give the RS-232 idea a try.

    Ray

  12. #52

    Default Re: PropCS - a small project

    Quote Originally Posted by Rsadeika View Post
    Still can not get serdevice to work. I have tried my C3, and GG PPUSB boards, still no joy. I remember that when I was doing this, using the command terminal, I would have to have something like 'propeller-load ... -t', in the SimpleIDE Build Status window, I do not see anywhere that a '-t' is being used, does that make a difference?
    In the attachment PST is connected to P0/1 via a PropPlug on COM20. P0 is connected to PropPlug >RX, P1 is connected to PropPlug <TX, PropPlug VSS is connected to board ground (VSS). SimpleIDE loads the board via P30/31 as usual. SimpleIDE does not use the propeller-load -t. Instead it opens a separate serial terminal either by Run Console F8 or pressing the Serial Console button. SimpleIDE console will reset the board when the port is closed. The attachment I show does not use the SimpleIDE console, it uses Run F10 only.

    Quote Originally Posted by Rsadeika View Post
    What I am trying to do is, using a variation of PropCS, use a pthread that would have a serdevice in it, to keep a port open for access through an RS-232 break-out board that I have attached. Since I was not having any luck doing it using pins 31,30, I thought I would give the RS-232 idea a try.
    If you have a DB9 or other RS232 compatible port on your PC and the breakout board is properly connected it should work. Just remember that minimum 3 wires are required. Your RS232 adapter may have other power requirements.


    @Ted, the code I mentioned is the current library documented and generic way of doing things that Ray wants to do. This does of course require the stdio like driver system which automatically adds to the code.

    I guess what I should be taking from the discussion is that while it's nice to have that standard or even IOCTL manipulation, we don't really have that much memory to spare. Maybe you can help rethink this toward a general but smaller approach. It doesn't seem like redefining the console pin numbers helps Rsadeika's goal.

    BTW, I've been under the weather this last week and not able to go anywhere including the USPS.
    Attached Thumbnails Attached Thumbnails Click image for larger version

Name:	port2pst.png‎
Views:	23
Size:	181.8 KB
ID:	91892  

  13. #53

    Default Re: PropCS - a small project

    I got the serdevice to work, hardware problems, what a headache. Now I am trying to get the serdevice to work in a thread. The pthread gets started, but for some reason it does not want to fprintf() anything to the designated port. Maybe I am going at this in the wrong way?

    Ray

    Code:
    /*
     * @file PropCS_C3_sa.c
     * This is the main PropCS_C3_sa program start point.
     */
    #include <stdio.h>
    #include <propeller.h>
    #include <unistd.h>
    //#include <stdlib.h>
    //#include <string.h>
    //#include <time.h>
    //#include <sys/rtc.h>
    //#include <cog.h>
    //#include <ctype.h>
    //#include <sys/stat.h>
    //#include <dirent.h>
    //#include <sys/sd.h>
    #include <pthread.h>
    
    
    
    void *user_1(void *argv)
    {
        waitcnt(CNT + CLKFREQ);
        fprintf(stdout, "This is the pthread\n");
        pthread_set_affinity_thiscog_np();
    
    /*                                                         Rx  Tx */
        char *serdevice = "SSER:115200, 27, 26";
        FILE *port = fopen(serdevice, "r+");
    
        setbuf(port,0);
        fprintf(port,"Port terminal screen.");  /* This does not show in the port terminal. */
        fprintf(stdout,"You are still in the pthread.\n");
    
    //    waitcnt(CNT + CLKFREQ);
      
    //    fprintf(port,"This is the PropCS program!\n");
    //    fprintf(stdout,"Type 'help' for Commands list.\n");
    //    fprintf(port,">");
    
        while(1)
        {
           
    //        int byte = fgetc(port);
     //       fprintf( port,"%c", byte);
    //        if (byte == 13)
    //        {
    //            fprintf(port,"\n");
    //            fprintf(port,">");
                usleep(5000);
     //       }
        }
    //    fclose(port);
    }
    
    
    /*
     * Main program function.
     */
    int main(int argc, char* argv[])
    {
    //    char *serdevice = "SSER:115200, 27, 26";
    //    FILE *port = fopen(serdevice, "r+");
    
    //    setbuf(port,0);
        pthread_t thr;
    
        pthread_create(&thr, NULL, user_1, NULL);
    
       
        waitcnt(CNT + CLKFREQ);
        printf("this is the main\n");   
        while(1)
        {
            usleep(5000);
        }
        return 0;
    }

  14. #54

    Default Re: PropCS - a small project

    Quote Originally Posted by Rsadeika View Post
    I got the serdevice to work, hardware problems, what a headache. Now I am trying to get the serdevice to work in a thread. The pthread gets started, but for some reason it does not want to fprintf() anything to the designated port. Maybe I am going at this in the wrong way?
    You can not use waitcnt(...) with pthreads. You must use usleep(...) or equivalent.
    Also, you can not use __simple_printf with pthreads.

    A simpler and better approach would be to use _start_cog_thread (we need a simple version of that).

    Here's an example of using _start_cog_thread blinking leds.

    Code:
    /*
     * blinkcogs.c
     *
     * Make all propeller cogs blink assigned pins at exactly the
     * same rate and time to demonstrate the precision of the
     * _start_cog_thread method. This program and method uses
     * 8 LMM C program COG "threads" of execution simultaneously.
     *
     * This program should be compiled with the LMM memory model.
     * A printf can be enabled for showing COGs started by changing DPRINTF.
     */
    
    
    /* To enable printf change this to #define DPRINTF 1 */
    #define DPRINTF 0
    
    
    #include <stdio.h>
    #include <propeller.h>
    
    
    #if DPRINTF
    #define printf __simple_printf
    #else
    #define printf
    #endif
    
    
    #define COGS 8
    #define STACK_SIZE 16
    
    
    static int cog_stack[STACK_SIZE][8];
    static _thread_state_t thread_data;
    
    
    volatile unsigned int wait_time;
    volatile unsigned int startcnt;
    volatile unsigned int pins;
    volatile int syncstart;
    
    
    /*
     * Set a pin high without affecting other pins.
     * param WCpin = pin number to set high.
     */
    void high(int WCpin)
    {
        unsigned int bits = 1 << WCpin;
        DIRA |= bits;
        OUTA |= bits;
    }
    
    
    /*
     * Set a pin low without affecting other pins.
     * param WCpin = pin number to set low.
     */
    void low(int WCpin)
    {
        unsigned int mask = 1 << WCpin;
        DIRA |= mask;
        OUTA &= ~mask;
    }
    
    
    /*
     * toggle thread function gets started in an LMM COG.
     * param arg = pin number to toggle
     */
    void do_toggle(void *arg)
    {
        int pin = (int) arg;
        unsigned int nextcnt;
    
    
        while(syncstart == 0) ; // wait for start signal from main cog
        
        nextcnt = wait_time + startcnt;
        while(1)
        {
            high(pin);
            nextcnt = waitcnt2(nextcnt, wait_time);
            low(pin);
            nextcnt = waitcnt2(nextcnt, wait_time);
        }
    }
    
    
    int main (int argc, char* argv[])
    {
        int n;
        int cog;
        int pin[] = { 16, 17, 18, 19, 20, 21, 22, 23 };
        unsigned int nextcnt;
    
    
        wait_time = CLKFREQ/20;
    
    
        syncstart = 0;
    
    
        for(n = 1; n < COGS; n++) {
            cog = _start_cog_thread(cog_stack[n] + STACK_SIZE, do_toggle, (void*)pin[n], &thread_data);
            printf("Toggle COG %d Started\n", cog);
        }
    
    
        startcnt = CNT;
        syncstart = 1;
        nextcnt = wait_time + startcnt;
        while(1)
        {
            high(pin[0]);
            nextcnt = waitcnt2(nextcnt, wait_time);
            low(pin[0]);
            nextcnt = waitcnt2(nextcnt, wait_time);
        }
        return 0;
    }

Similar Threads

  1. Small motors for a small bot and a small wallet
    By Spiral_72 in forum Robotics
    Replies: 13
    Last Post: 02-10-2011, 12:19 AM
  2. Small hydraulic servo control valves-BS2 project
    By $WMc% in forum General Discussion
    Replies: 7
    Last Post: 07-21-2009, 08:08 AM
  3. Replies: 4
    Last Post: 04-03-2008, 01:43 AM
  4. "PropScope820"-project with driver for ADC0820-chip and small keyboard on i2c w
    By Christof Eb. in forum Propeller 1 Multicore Microcontroller
    Replies: 0
    Last Post: 12-22-2006, 07:02 PM
  5. OT: Looking for Small Linier Actuators, for stamp project
    By Archiver in forum BASIC Stamps Archive
    Replies: 6
    Last Post: 02-18-2004, 08:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts