Shop OBEX P1 Docs P2 Docs Learn Events
Can the BASIC Stamp be used to generate a microcontroller's clock? — Parallax Forums

Can the BASIC Stamp be used to generate a microcontroller's clock?

Hello!
New project time. Despite the fact that it would be using a BASIC Stamp, it is in the Microcontoller category and not Stamp one because it might not fit in that one. I also don't think the general one would work also.

Okay here goes: Can the BASIC Stamp be used to generate a microcontroller's clock? Basically the thing expects either an RC time constant based clock that produces a waveform with the periodic pulse of 19 microseconds. I looked over the Pulseout instruction and oddly I didn't see any guides towards selecting the right constant for that one. I have a collection of older devices, they are members of the COP400 family from when National was earnestly making chips thinking they would be able make one to save themselves from being glommed by a bigger and perhaps better device maker.

Normally I pick the right pair for this one, a COP411L device right off the bat, but since the thing will be talking to a PLD who'll be sending a data stream off to be processed and then displayed by the same stamp.....

I also thought of tricking a Propeller One board into doing the clock generation as an output function and then accepting a data stream via that same PLD and then displaying it via an LCD device, same as for the Stamp. But of course I figured on the Stamp first.

My big hurdle is figuring out how to successfully write the Propeller code to do both.

Comments

  • A Stamp could do it, but not very well. First of all the Stamp can only do one thing at a time. If you sandwich in code to quickly do something else, that messes up the timing of the clock. 19 microseconds is about as fast as a Stamp can handle. You'd do better with a BS2p or even BS2px.

    A Propeller would be a better choice except for the 3.3V logic levels. You'll need a buffer that converts from 3.3V levels to 5V levels. The Propeller can do very precise timing of generated clock pulses.
  • That's what I thought Mike. I never got into the others in the BS2 family. As for the Prop, that was my big hangup. Writing the code for that purpose I mean. Translating from 3.3v to 5v is reasonably easy, as there are devices to do that.

    I see what else I can do. Thanks always.
  • kwinnkwinn Posts: 8,697
    That's what I thought Mike. I never got into the others in the BS2 family. As for the Prop, that was my big hangup. Writing the code for that purpose I mean. Translating from 3.3v to 5v is reasonably easy, as there are devices to do that.

    I see what else I can do. Thanks always.

    What big hangup? There are objects in the OBEX to do pretty much everything you mentioned. Just a matter of adding a few lines of code to tie the objects together.
  • Mike GreenMike Green Posts: 23,101
    edited 2017-09-12 14:50
    The simplest routine to generate a clock using a cog looks like
    con
        _clkfreq = 80_000_000  ; assume usual 80MHz system clock
        _clkmode = xtal1 + pll16x
    
        microsecond = clkfreq / 1000000  ; clock ticks per microsecond
        phase1 = 19 * microsecond / 2  ; ticks for "on" phase
        phase2 = 19 * microsecond / 2  ; ticks for "off" phase
        thePin = 0  ; I/O pin number
    
    var 
        long stack[16]  ; minimal stack space for clockIt
    
    pub main  ; your main routine
        cognew(clockIt,@stack)  ; start clockIt in a cog
        ; here you could do other stuff
        
    pri clockIt
        outa[ thePin] := 0  ; start with clock off
        dira[ thePin] := 1
        repeat
           outa[ thePin]!  ; toggle pin on
           waitcnt(phase1 + cnt)  : wait length of phase1
           outa[ thePin]!  ; toggle pin off
           waitcnt(phase2 + cnt)  ; wait length of phase 2
    
    For very short clock phase times the time needed to do the outa and waitcnt will start to be significant. You can always adjust the phase1 and phase2 counts to compensate.
  • jmgjmg Posts: 15,140
    Normally I pick the right pair for this one, a COP411L device right off the bat, but since the thing will be talking to a PLD who'll be sending a data stream off to be processed and then displayed by the same stamp.....

    I also thought of tricking a Propeller One board into doing the clock generation as an output function and then accepting a data stream via that same PLD and then displaying it via an LCD device, same as for the Stamp....
    The PLD could generate the clock at the desired rate ?

    Or a Counter/Adder in P1 can be set up to generate a NCO clock out, so you can do fine clock speed adjustments, if you wanted this more dynamic.

    https://www.parallax.com/downloads/an001-propeller-p8x23a-counters


    Coming from the Stamp, you could also look at PropBASIC ?
    http://forums.parallax.com/discussion/166954/propbasic-update-june-2017
  • jmg wrote: »
    Normally I pick the right pair for this one, a COP411L device right off the bat, but since the thing will be talking to a PLD who'll be sending a data stream off to be processed and then displayed by the same stamp.....

    I also thought of tricking a Propeller One board into doing the clock generation as an output function and then accepting a data stream via that same PLD and then displaying it via an LCD device, same as for the Stamp....
    The PLD could generate the clock at the desired rate ?

    Or a Counter/Adder in P1 can be set up to generate a NCO clock out, so you can do fine clock speed adjustments, if you wanted this more dynamic.

    https://www.parallax.com/downloads/an001-propeller-p8x23a-counters


    Coming from the Stamp, you could also look at PropBASIC ?
    http://forums.parallax.com/discussion/166954/propbasic-update-june-2017

    Okay thanks Mike. And you as well Kwinn.

    Not exactly jmg. The PLD is the target. the output lines of the COP411L are also connected to it, as well as a pair of Hex displays. There's also a pair connected to the output lines of the PLD. The big black box below is the Parallax device both sending up a clock signal to the COP411L and then interpreting a serial stream coming from a single output line and translating the binary stream into ASCII characters on an LCD display.

    As for PropBASIC it's also a thought.

  • My next big hurdle was after considering what device to use; was that of powering it. Since Mike suggested an excellent Prop 1 program, I then spent time earlier tracking through the threads on powering the well known
    Quick Start board.

    Since I'm a five volt logic shop, with exceptions, I figured I might be able to directly power the QS from the breadboard's own power supply.

    I have the sample code for the chosen LCD display, who is a "Parallax 2 x 16 Serial LCD (Backlit)" for both the Stamp and the Prop.

    I'm going to spend the rest of the week studying those samples.

    And Mike? Look for your favorite deli and have a good sandwich on me.
  • Hello!
    Next issue now, this is the Stamp2 program I use for extracting meaningful information from that running example,
    ' {$STAMP BS2}
    ' {$PBASIC 2.0}
     T2400       CON     396
     T9600       CON     84
     T19K2       CON     32
    LcdBaud CON T2400
    
    'TX  PIN 15
    
    
    'PL0  PIN     0    '
    'PL1  PIN     1    '
    LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
    LcdBLoff        CON     $12             ' backlight off
    LcdOff          CON     $15             ' LCD off
    LcdOn1          CON     $16             ' LCD on; cursor off, blink off
    LcdOn2          CON     $17             ' LCD on; cursor off, blink on
    LcdOn3          CON     $18             ' LCD on; cursor on, blink off
    LcdOn4          CON     $19             ' LCD on; cursor on, blink on
    '
    '
      X VAR Word
      Z VAR Word
      Z1 VAR Word
      X2 VAR Word
    'SEROUT 15, LcdBaud, [LcdBLoff, LcdOn1, LcdCls]
    '  PAUSE 5
    
    FOR X=1 TO 192
    SERIN 0, LcdBaud, [Z]
    'DEBUG Z, X
    SEROUT 1, LcdBaud, [Z]
    SEROUT 15, LcdBaud, [Z]
    'PULSOUT 14,50
    'PULSOUT 14, X
    'SEROUT 15, LcdBaud, [X]
    SEROUT 1, LcdBaud, [X]
    'PAUSE 250
    Z1=Z -128
    X2=Z1 +128
    SERIN 0, LcdBaud, [Z]
    SEROUT 1, LcdBaud, [Z1]
    SEROUT 15, LcdBaud, [Z1]
    SEROUT 1, LcdBaud, [X2]
    SEROUT 15, LcdBaud, [X2]
    SEROUT 15, LcdBaud, [Z]
    'DEBUG Z1, X
    NEXT
    

    It uses a cable such as the ones desktops did use for supporting CD-(DVD)-ROM drives and soundcards, to bring serial data into the stamp. From the stamp it gets displayed on the one described above. The cable for that one is one of the three-leaded ones that the firm does sell. The board they use is of course one of the firm's regular BOE Boards.

    My next step will be to use that on the Stamp board to do all of that, while the clock program is running on the QS. However my problem here on the QS, is that of combining the steps such that the clock on cog program that Mike contributed, also does the same as my BASIC code does is being stymied by the lack of a template which I used on the Stamp to create that.

    I'd say I've gotten a heck of a lot of work done here, and this confirms this is indeed a good group of people. Now all that remains is to try it all out.
  • Can I ask a not so silly question? Why would you want to start any new project with a COP device? Those parts are nearly 30 years old, and yeah you might have some that fell behind the desk and you swept up. But Really?

    SO assuming they didn't get zapped somewhere along the way, they might be about ready to fail and would be relatively hard to find a source for a new one. Yes Digikey still has the COP8 devices in stock but at nose bleed prices (like > $10). Even a P1 would be a better solution.
  • Yes you can indeed ask a silly question. The answer is one of because they are here. These are COP411L devices. They were programmed for a particular function. I picked up a traditional anti-static storage container of these and the COP420 designs, knowing that they contained someone else's programming and related problems. And every few years I sit down with these to better understand them.

    As for failing, I doubt that. You are aware that certain utilities are running their power plants on PDP-11s? And that there are some industries who are using S-100 systems for controlling their equipment? The list is endless. In fact four times a year, a Vintage Computer Festival meets in four such places, and the midwestern event just concluded.

    The Eastern one meets next spring in a place in NJ, and with the blessing of the Moderators, I'll post it then.
  • Well have fun. I am also a pack rat and can't seem to part with things running from i960s to 68000 to 68HC11s. I just can't throw them away and haven't found a good home for them.

    But rather than deal with all the limitations of those old chips I'll spend a buck or two and start with something easier to program with more memory and builtin features.

    Yes the FAA was using S-100 systems for air traffic control well past their lifetime. Gee did I feel safe when I learned that, not really. When I was working at Univac outside Philly (70s) they still had an ENIAC running, doing low priority printing or something. Those antique systems are interesting, but really a support nightmare for the maintenance people.
  • Thank you all for the advice, but I've decided, based on Mike Green's excellent advice, that the BASIC Stamp is the wrong vehicle for this job.

    And while a Prop would be an excellent one for it, I'm not that fluent in the programming languages available for the device.

    And since that Stamp program I shared is normally used to collect and display information generated via a completely different board/device it definitely wouldn't work for the controller described above.
Sign In or Register to comment.