Shop OBEX P1 Docs P2 Docs Learn Events
ALPHA testing thread for Co-Pro Mega48 — Parallax Forums

ALPHA testing thread for Co-Pro Mega48

metron9metron9 Posts: 1,100
edited 2007-06-26 16:06 in General Discussion
ALPHA TESTING
A very early version of a software product that may not contain all of the features that are planned for the final version. Typically, software goes through two stages of testing before it is considered finished. The first stage, called alpha testing, is often performed only by users within the organization developing the software. The second stage, called beta testing , generally involves a limited number of external users.


I have designed a program that runs on an ATMEL Mega48 that interfaces to a basic stamp via the shiftout and shiftin commands using 2 wires.
It is written using 100% Assembly Language and runs at 20MHZ.
It has Memory features to store in 256 bytes of SRAM, dump SRAM to FLASH in 256 byte blocks and read and write EEPROM on the MEGA48 with automatic byte pointers. like a PUSH and POP command to store data in a buffer.
It has 6 8 bit ADC's A real time 24 hour Clock with seconds minutes and hours, 18 - input pins with or without internal pullups,
it has 12 - latching pins both high and low latches can be setup to handle situations where for example a momentary button is pressed and the stamp can not read the pin during the button press. Various other features.
I plan to post the code in the projects section for those that want to program their own AVR's but I need someone with experience programming stamps to test the features on some of the faster Basic Stamps. I only have the BS2.

I could also use input from others on new features that you would like implemented. Counting pulses, timed high and low pin commands. Basically functions you can't do using a basic stamp alone or functions that just take up too much program space of processor time that would best be offloaded to a co-processor.

An example of reading one of the ADC's would be

shiftout 0,1,1[noparse][[/noparse]COMMANDBYTE]
shiftiin 0,1,0,[noparse][[/noparse]ADCVALUE]

would read one of the ADC's and put the value in ADCVALUE

Setting a pin to input with a pullup enabled would be

shiftout 0,1,1[noparse][[/noparse]COMMANDBYTE,PINNUMBER]


Saving a variable in external SRAM would be

shiftout 0,1,1, [noparse][[/noparse]commandbyte,BYTEVALUE]

Reading a byte from SRAM would be

shiftout 0,1,1,[noparse][[/noparse]commandbyte]
shiftin 0,1,0, [noparse][[/noparse]BYTEVALUE]

writing 256 bytes stored in SRAM to FLASH memory would be

shiftout 0,1,1,[noparse][[/noparse]commandbyte,addresstostoreinflash]

The above command would take 30mS to complete on the co-processor but only the time the shiiftout command takes from the stamps point of view, much faster than writing 256 bytes to EEPROM using PBASIC commands to do the writing.

Hope this doesn't step on anyones toes but I have run out of projects to do and I like programming in assembler so much I just can't stop writing code.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!

Post Edited (metron9) : 6/18/2007 6:24:24 AM GMT
«1

Comments

  • BeanBean Posts: 8,129
    edited 2007-05-08 16:50
    Metron9,
    I wish I had the time, I would help you out.
    A couple suggestions:

    If you use serial instead of SPI you will only need 1 stamp pin, plus your device can take as long as it needs to get the requested data.

    I2C and 1-Wire interfaces would be nice since the BS2 doesn't have these built-in (I2C can be done, but takes a fair bit of code).

    Think about making the device a "piggy back". Where the stamp would plug into your device, and your device would have the same stamp 24 pin footprint. And would plug into the BOE or PDB.

    Get as much documentation as possible so the testers know what to do.

    Serial input buffer, I2C, 1-Wire, PWM outputs, ADC inputs, Counters, Timers, Latches, keypad interface, etc. It's all good...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-08 17:14
    Terry,

    My own thoughts on Serial VS SPI; these are things to take into consideration. I prefer an SPI interface for many reasons, but a big one is that you retrieve the data when you want it. With Serial the BASIC Stamp often has to frequently check the serial line for data, or worse yet, sit there waiting (possibly with a timeout). An SPI device forces the host controller to retrieve the data on its own, leaving the host controller free to do this whenever it wants to or has time to. 2 pins is a small sacrifice for that ability and for the speed to be device independent. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • BeanBean Posts: 8,129
    edited 2007-05-08 17:34
    Good points Chris. With SPI the BS2 doesn't have to worry about "missing" data, because the device can't send it until the BS2 clocks it out.

    What does an SPI device do if you request data and it's hasn't acquired the requested data yet ? Does it just return zeros ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Educate your children to self-control, to the habit of holding passion and prejudice and evil tendencies subject to an upright and reasoning will, and you have done much to abolish misery from their future and crimes from society"

    Benjamin Franklin
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-08 18:14
    It really depends on the device. Typically these devices hold the last values they were commanded to get. Typically when you want current data you SHIFTOUT the command and SHIFTIN the data right after. But if the device is semi-autonomous then SPI would give you that extra freedom. And, as I said, the speed is device independent. It will usually go as fast as the host can talk up to the device/host maximum communication speed. With serial you usually have a set baud rate which may be slower and increase latency in getting data. Again, there are a lot of factors that affect this and it is mostly an opinion based on working with dozens of serial and SPI devices, some mixed within the same system/project. And now we return to our regularly scheduled thread, already in progress…Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • metron9metron9 Posts: 1,100
    edited 2007-05-08 22:56
    Ok Here is the documentation so far, I plan to make sample programs as well. This is a work in process however I am just about out of programming space in the MEGA48 to leave room for the Flash memory to store data.

    The SPI interface is nice I think as well. I have implemented a timeout strategy however to eliminate bad data from locking the chip up in an endless loop. When using shiftin after shiftout it must be the next line on the stamp or the co-processor will simply end the output and go back to waiting for a new command. As far as speed I think it will go as fast as the fastest stamp. The writing of flash and eeprom are the only two things one needs to be aware of. For example the co-processor will not see any new commands if a command is sent within 30mS of a 256 byte SRAM transfer to Flash.

    The push and pop instructions work just like asswmbly language except I reversed the direction to going up in memory instead of down. That way the push command can be used to store arrays of data without sending the address because it automatically increments the address. The readsram automatically increments the pointer as well so you can set the pointer to any byte and read in bytes. I may add a read command to specify pointer and number of bytes for string data as well.

    On using 2 pins from the stamp. No worries mate, There are 18 new pins to use for I/O as you wish so basically you double the pins on the BS2 to 32 pins instead of 16. The latching pins are cool both latch lows and latch highs (6 pins of each) This was very easy to implement as all the pins have a pin change interrupt.

    I use a 20MHZ crystal to keep the timing for the clock function. I could implement a simple date function that would work like a DS1302 but the basic 1 second timer that keeps track of seconds , minutes and hours can be used as the basic structure for the stamp to do its own longer term time stamps. I always missed the number of seconds past midnight function the old qbasic and most PC languages implemented when I started writing programs on the stamp.

    This is the command set so far, some not documented yet in the PDF.

    As far as the Motor PWM controll, I think I will make that a dedicated chip. I want to make it glitch free so it will work for dimming LED's , running servos and PWM voltage control for motors. I am thinking of buffering the commands from the stamp to this chip that in turn will feed the PWM chip. That way the input to the PWM chip can be interrupt driven communication between this chip and the PWM while this chip simply buffers the commands. This is a fun project. Remember I once wrote a full 6502 Editor Assembler for the commodore 64 that was much faster than commodors own macro assembler using what was called HES-MON. That was 20 years ago and my brain cells still work!




    _INIT           CON   $FFAA 'INITIALIZE COPROCESSOR
    _ERRORS         CON   $FE 'Get Error Flags
    _LOW            CON   $B0 'SET PIN OUTPUT LOW
    _HIGH           CON   $B1 'SET PIN OUTPUT HIGH
    _INPUT          CON   $B2 'SET PIN TO INPUT
    _INPUTP         CON   $B6 'SET PIN TO INPUT WITH PULLUP
    _PUSH           CON   $D0 'PUSH ONE BYTE ON STACK at the current sram pointer and increment pointer
    _POP            CON   $D1 'decrement sram pointer and POP ONE BYTE OFF STACK
    _ZSTACK         CON   $D2 'ZERO THE STACK POINTER
    _CLRBL          CON   $B7 'CLEAR THE BLATCH REGISTER
    _CLRCL          CON   $B8 'CLEAR THE CLATCH REGISTER
    
    _RPINSA         CON   $C0 'READ PINS  0...5
    _RPINSB         CON   $C1 'READ PINS  6..11
    _RPINSC         CON   $C2 'READ PINS 12..18
    _PINSBL         CON   $C3 'READ LATCHED LOW PINS   6..11
    _PINSCL         CON   $C4 'READ LATCHED HIGH PINS 12..18
    _SECONDS        CON   $C5 'Read seconds
    _MINUTES        CON   $C6 'Read Minutes
    _HOURS          CON   $C7 'Read Hours
    _TIME           CON   $C8 'Read seconds,minutes,hours
    _ADC0           CON   $A0 'READ ADC0
    _ADC1           CON   $A1 'READ ADC1
    _ADC2           CON   $A2 'READ ADC2
    _ADC3           CON   $A3 'READ ADC3
    _ADC4           CON   $A4 'READ ADC4
    
    _WRITEFLASH     CON   $D3 'write 255 bytes from SRAM to FLASH memory
    _READFLASH      CON   $D4 'Read 255 bytes from FLASH to SRAM memory
    _Readsram       CON   $D5 'Read a byte at the current sram pointer and increment pointer
    _setstack       CON   $D6 'Set the Sram pointer
    _EWRITE         CON   $D7 'wRITE A BYTE TO EEPROM
    _EREAD          CON   $D8 'Read  a byte from EEPROM
    _SETTIME        CON   $D9 'Set seconds,minutes,hours,days
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 6/16/2007 10:53:22 PM GMT
  • metron9metron9 Posts: 1,100
    edited 2007-05-09 01:01
    Let me be more specific. I will mail this co-processor for free to the first 5 people who would like to test this chip with any basic stamp.
    The chip is a 28 pin DIP. Simply plug it into a breadboard with +5V from the stamp and ground.

    I want at least one total newbe to the basic stamps and one person that has advanced experience as well.

    I will include the 20MHZ Crystal and capacitors.

    Folks, this is a very easy to use multi function chip. You will be up and running in 2 minutes.

    The chip only costs me a buck so don't even worry about blowing it up just give it a go and see what you learn from it.

    This is some code I was testing functions with. You can see how easy it is to use.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM2}
    
    _INIT           CON   $FFAA 'INITIALIZE COPROCESSOR
    _ERRORS         CON   $FE 'Get Error Flags
    _LOW            CON   $B0 'SET PIN OUTPUT LOW
    _HIGH           CON   $B1 'SET PIN OUTPUT HIGH
    _INPUT          CON   $B2 'SET PIN TO INPUT
    _INPUTP         CON   $B6 'SET PIN TO INPUT WITH PULLUP
    _PUSH           CON   $D0 'PUSH ONE BYTE ON STACK at the current sram pointer and increment pointer
    _POP            CON   $D1 'decrement sram pointer and POP ONE BYTE OFF STACK
    _ZSTACK         CON   $D2 'ZERO THE STACK POINTER
    _CLRBL          CON   $B7 'CLEAR THE BLATCH REGISTER
    _CLRCL          CON   $B8 'CLEAR THE CLATCH REGISTER
    
    _RPINSA         CON   $C0 'READ PINS  0...5
    _RPINSB         CON   $C1 'READ PINS  6..11
    _RPINSC         CON   $C2 'READ PINS 12..18
    _PINSBL         CON   $C3 'READ LATCHED LOW PINS   6..11
    _PINSCL         CON   $C4 'READ LATCHED HIGH PINS 12..18
    _SECONDS        CON   $C5 'Read seconds
    _MINUTES        CON   $C6 'Read Minutes
    _HOURS          CON   $C7 'Read Hours
    _TIME           CON   $C8 'Read seconds,minutes,hours
    _ADC0           CON   $A0 'READ ADC0
    _ADC1           CON   $A1 'READ ADC1
    _ADC2           CON   $A2 'READ ADC2
    _ADC3           CON   $A3 'READ ADC3
    _ADC4           CON   $A4 'READ ADC4
    
    _WRITEFLASH     CON   $D3 'write 255 bytes from SRAM to FLASH memory
    _READFLASH      CON   $D4 'Read 255 bytes from FLASH to SRAM memory
    _Readsram       CON   $D5 'Read a byte at the current sram pointer and increment pointer
    _setstack       CON   $D6 'Set the Sram pointer
    _EWRITE         CON   $D7 'wRITE A BYTE TO EEPROM
    _EREAD          CON   $D8 'Read  a byte from EEPROM
    
    
    page      VAR   Byte
    TEMP      VAR   Word
    BUFFER    VAR   Byte
    Seconds   VAR   Byte
    Minutes   VAR   Byte
    Hours     VAR   Byte
    
    PAUSE 1000
    DEBUG "CO-PRO-M48 Command Test Program",CR
    
    
    
    'Initialize Coprocessor
    
    SHIFTOUT 0,1,1,[noparse][[/noparse]_INIT\16] ': DEBUG "Initializing Co-Processor",CR
    
    
    
    'Test EEPROM Write and READ
    TEMP=0
    SHIFTOUT 0,1,1,[noparse][[/noparse]_EWRITE,TEMP,TEMP]
    PAUSE 1
    SHIFTOUT 0,1,1,[noparse][[/noparse]_EREAD,TEMP]
    SHIFTIN 0,1,0, [noparse][[/noparse]buffer]
    DEBUG DEC temp," ",DEC buffer,CR
    
    
    'Test flash memory storage
    SHIFTOUT 0,1,1,[noparse][[/noparse]_zSTACK]
    FOR page=0 TO 5
    DEBUG "STORING",DEC page,CR
    FOR TEMP=0 TO 255
    SHIFTOUT 0,1,1,[noparse][[/noparse]_PUSH,temp]
    NEXT
    
    SHIFTOUT 0,1,1,[noparse][[/noparse]_setstack,127]
    FOR temp=0 TO 255
     SHIFTOUT 0,1,1,[noparse][[/noparse]_readsram]
     SHIFTIN 0,1,0, [noparse][[/noparse]buffer]
     DEBUG DEC temp," ",DEC buffer,CR
    NEXT
    
    
    DEBUG "WRITEFLASH",CR
    SHIFTOUT 0,1,1,[noparse][[/noparse]_WRITEFLASH,page]
    PAUSE 30
    NEXT
    
    
    FOR page=0 TO 5
    SHIFTOUT 0,1,1,[noparse][[/noparse]_READFLASH,page]
    DEBUG "READFLASH",DEC  page,CR
    PAUSE 40
    DEBUG "READING sRAM"
    
    FOR TEMP=0 TO 5
    SHIFTOUT 0,1,1,[noparse][[/noparse]_POP]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    DEBUG DEC BUFFER,CR
    NEXT
    NEXT
    
    SHIFTOUT 0,1,1,[noparse][[/noparse]_READFLASH,1]
    DEBUG "READFLASH",CR
    PAUSE 40
    
    DEBUG "READING sRAM"
    FOR TEMP=0 TO 255
    SHIFTOUT 0,1,1,[noparse][[/noparse]_POP]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    DEBUG DEC BUFFER,CR
    NEXT
    
    END
    
    SHIFTOUT 0,1,1,[noparse][[/noparse]_POP]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    DEBUG DEC BUFFER,CR
    
    
    END
    
    
    
    
    
    
    ttt:
    SHIFTOUT 0,1,1,[noparse][[/noparse]_TIME]
    SHIFTIN 0,1,0,[noparse][[/noparse]Seconds,Minutes,Hours]
    DEBUG DEC Hours," ",DEC Minutes," ",DEC Seconds,CR
    SHIFTOUT 0,1,1,[noparse][[/noparse]_SECONDS]
    SHIFTIN 0,1,0,[noparse][[/noparse]Seconds]
    SHIFTOUT 0,1,1,[noparse][[/noparse]_MINUTES]
    SHIFTIN 0,1,0,[noparse][[/noparse]MINUTES]
    SHIFTOUT 0,1,1,[noparse][[/noparse]_HOURS]
    SHIFTIN 0,1,0,[noparse][[/noparse]HOURS]
    DEBUG DEC Hours," ",DEC Minutes," ",DEC Seconds,CR
    PAUSE 1000
    GOTO ttt
    
    
    END
    
    
    'Set a pin High
    'SHIFTOUT 0,1,1,[noparse][[/noparse]_HIGH,1]  :  DEBUG "Pin 1 is HIGH",CR :PAUSE 1000
    'Set a pin low
    SHIFTOUT 0,1,1,[noparse][[/noparse]_LOW,1]   :  DEBUG "Pin 1 is LOW",CR  :PAUSE 1000
    'Set a pin to Input
    'SHIFTOUT 0,1,1,[noparse][[/noparse]_INPUT,1] :  DEBUG  "Pin 1 is INPUT",CR :PAUSE 1000
    'Set a pin to Input with a Pullup
    'SHIFTOUT 0,1,1,[noparse][[/noparse]_INPUTP,1] :  DEBUG  "Pin 1 is INPUT with Pullup",CR :PAUSE 1000
    
    'Set the stack pointer to Zero
    'SHIFTOUT 0,1,1,[noparse][[/noparse]_ZSTACK]
    
    
    
    
    cc:
    'Push a byte on the stack
    SHIFTOUT 0,1,1,[noparse][[/noparse]_PUSH,$AA]
    'Pop a byte from the stack
    SHIFTOUT 0,1,1,[noparse][[/noparse]_POP]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    DEBUG DEC buffer,CR
    GOTO cc
    
    'Clear the Blatch register
    SHIFTOUT 0,1,1,[noparse][[/noparse]_CLRBL]
    'clear the Clatch register
    SHIFTOUT 0,1,1,[noparse][[/noparse]_CLRCL]
    'Read pins A
    SHIFTOUT 0,1,1,[noparse][[/noparse]_RPINSA]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    'Read pins B
    SHIFTOUT 0,1,1,[noparse][[/noparse]_RPINSB]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    'Read pins C
    SHIFTOUT 0,1,1,[noparse][[/noparse]_RPINSC]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    'Read the Blatch Register
    SHIFTOUT 0,1,1,[noparse][[/noparse]_PINSBL]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    'Read the Clatch Register
    SHIFTOUT 0,1,1,[noparse][[/noparse]_PINSCL]
    SHIFTIN 0,1,0,[noparse][[/noparse]BUFFER]
    
    'Read error register
    SHIFTOUT 0,1,1,[noparse][[/noparse]_ERRORS]
    SHIFTIN 0,1,0,[noparse][[/noparse]buffer]
    DEBUG CR,"Errors ", BIN8 buffer,CR
    
    END
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • boeboyboeboy Posts: 301
    edited 2007-05-16 18:12
    What kind of feed back do you want? And how many more people are you accepting and last of all what kind of equipment will i need?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    lets see what this does... KA BOOM (note to self do not cross red and black)
  • metron9metron9 Posts: 1,100
    edited 2007-05-18 18:18
    So far I am a bit perplexed as there are over 200 people that have read this thread and only three people so far have shown any interest one from all the way in Africa. I would like 2 or 3 more at this time.

    As far as feedback, I guess I want to see how well the coprocessor performs in different projects. I would like feedback from people that need additional functions not implemented in other chips things that take up Pbasic program space, or difficult to implement procedures like counting longer pulses I just read in another post.

    Your feedback asking the question what equipement do you need is good feedback as well.

    You dont need anything but a breadboard and two wires from the any basic stamp, SX or propeller. (and two resistors for pulldowns)

    That gives you 18 new input and oututput pins so it doubles from 16 to 32 the pins available on a BS2 for example.

    Their are 12 pins that allow latching input, 6 high and 6 low. A good use for these would be for example a button press where the stamp can poll once per second or at any polling rate and still get button input.
    This just gave me the idea of turning on a timer to allow the stamp to know just how long the button has been pressed for example.

    The ADC's are so simple to use, for example a resistor and a 10kpot connected to the chip and two simple shiftout and shiftin commands can tell you the position of the POT from 0 to 255. No setups no long drawn out code or calculations.

    I just think if some people were using this chip in their projects they would have all kinds of feedback.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • skylightskylight Posts: 1,915
    edited 2007-05-19 04:17
    I would be interested to help, though i'm in the UK
  • phil kennyphil kenny Posts: 233
    edited 2007-05-20 01:52
    Hello Metron9,

    I'll offer my assistance in being a beta for you. Put me down as
    having mid level ability, so far as Stamps are concerned.

    phil
  • phil kennyphil kenny Posts: 233
    edited 2007-05-20 02:12
    phil kenny said...
    Hello Metron9,

    I'll offer my assistance in being a beta for you. Put me down as
    having mid level ability, so far as Stamps are concerned.

    I have both BS2P and BSX modules available.

    phil
  • Curtis BrooksCurtis Brooks Posts: 38
    edited 2007-05-20 14:35
    I'd be interested in testing for you as well.· Actually, I'll get my new to stamps, and aspiring Einsteins, daughters to help (11 & 7).
  • metron9metron9 Posts: 1,100
    edited 2007-05-21 05:26
    Ok I have 7 beta testers now from total newbe to high level programmers/circuit design folks, that should do it to get started. It is my hope that I will learn many new things working directly with these people. I did not get a chance to go to MIT where students collaborated on projects and this is like a group project now, it should be fun and interesting. My wife just rolls her eyes when I try and tell her how it works.

    I suppose we could just use this thread for all questions and answers so others can follow along and add their own input along the way as long as it's ok with the folks at Parallax.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-21 14:12
    metron,

    Definitely post follow-up questions and answers in the thread if you want others interested in the chip to be able to ask questions, offer advice or make suggestions. It may also help make its functions more clear to some. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Rob7Rob7 Posts: 275
    edited 2007-05-22 13:25
    Metron9,

    I see you have 7 Beta testers. Need any more ?

    I am "very" interested.

    Rob7
  • metron9metron9 Posts: 1,100
    edited 2007-05-23 20:18
    OK Rob7 since I have not sent out all of them yet i will put you on the list (I hope I have enough in stock, i think I do) send your address PM me.

    Here is the layout of the chip, I will make a eagle layout when I get the chance, when I find time that is hint hint...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
    2271 x 1677 - 180K
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-05-26 03:45
    I am testing this chip and trying to get a good understanding of the required shift timing for communication with it. Right now I am able to Push and Pop from the stack but am only reading zeros from the ADC. (Those are the only commands I have tested so far.) I am also using an SX instead of a Basic Stamp.

    Despite the fact that my software is presently reading zeros from the ADC my logic analyzer is picking up some 500ns pulses immediately following the rising edge of the clock. Do I need to sample the data that fast? I think the data should at least hold steady until the clock signal drops. Correct?

    I am trying to discern if these 500ns pulses are real data or just noise. I have hooked the chip up according to the image you posted (as far as I can tell) and have just over half a volt going into Pin12. I am wondering if I am really seeing zeros out of the chip or if I need to be sampling the data faster.

    I will try to attach an image showing the pulse widths I am seeing. For reference each normal clock pulse is 16.5us in duration. I will try to attach the code that I am using as well. In it I use small pauses to more easily identify the various transactions on the logic analyzer screen. I can remove them if you think they might be causing a problem.

    I will be leaving this at work so it will be Tuesday or later before I get back to it again.

    Enjoy the holiday!

    - Sparks
  • metron9metron9 Posts: 1,100
    edited 2007-05-26 05:48
    I have an SX28 so I will load up your program and try it.

    It looks like you read the value ok from the POP command

    My initial thought is you are going 5 times faster then the stamp, I have to look at the timing in the code to see how much time the ADC takes to complete, I think I set it up for slowest speed and the tiny blips are odd because the same routine that outputs the value you receive from the POP command outputs data for all routines. If there is a high bit it should output the same as the high bits in the previous command. This will be interesting to find out what is going on to make those tiny blips.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • metron9metron9 Posts: 1,100
    edited 2007-05-26 06:24
    This is a plot of the basic stamp2 reading the number 230 from the ADC.

    The blue line is the data. Where the blue line goes high is where the data becomes ready. Roughly its 260uS before the data is ready.

    I think the small pulses have to do with the fact that the chip uses the sleep mode while processing the ADC value for better accuracy. I think what is happening is the chips hardware is processing the ADC and your clock is waking it up. I will investigate further for the exact cause of the blips but I think it's safe to say if you wait 300uS before reading the data it will work.

    Remember , the timeout window starts when the data becomes ready in the case of the ADC because the chip is sleeping while the adc hardware is processing the value. That's why I think waiting 300uS should work. I actually think I am reading the ADC twice at the slowest speed possible because I was experimenting with the code. I know I can tweek this to run as fast as the datasheet will allow for a 20mhz clock but I will have to work with it.

    So, so far looks like you have found the first slice of code for modification. My plan is to add a 10 bit mode as well as add the VCC reference mode too.

    Now I bet you wish you had it on your bench at home so you could test it. If it was not 1:30AM I would try the sx now but I did have a few beers tonight so I think I will call it a night.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
    871 x 584 - 19K
  • metron9metron9 Posts: 1,100
    edited 2007-05-26 17:55
    Ok , tested the SX code. I was correct, attached is a 300us delay plot and a plot without 300us delay between the command to read the ADC and the actual clocking out of the data.

    One other thing you need to change as well for initialization

    The initialization creates a window of time for the data to be clocked in after a command has been given to the co processor to send data. This window starts at the end of the shiftout commands last bit and goes to the last bit of the next 8 bits sent (The $AA in the initialization command)

    Your code sends the $FF then the $AA with no delay between and then uses a delay between the shiftout and shiftin.

    I tested at 4mhz sx speed with no delay and that works fine.

    I don't know if the shiftout command for the sx is timed different at higher clock speeds but if is and you ran it at 50mhz the co processor could not keep up. I think 10MHZ would work but there would have to be a delay between reads and writes of a few uS I would think.

    So that problem is solved and I will work on the code to speed the process up.

    I forgot one thing on using the internal reference on this chip. Instead of connecting VCC to AREF like I show in the diagram use just a .1 capacitor to ground from that pin. That will provide external decoupling for the internal reference voltage of 1.1V

    If you do connect VCC to AREF then the ADC uses VCC as a reference through the AREF pin. I tested this and it seems to work but I don't think it should be used that way, I will have to check but the normal way to use VCC as a reference is for me to program the correct reference bits in the co processor so it uses AVCC that is tied to VCC and the external capacitor is still connected to AREF. This is not what I was taught originally so I will have to verify this over at the avrfreaks forum.

    EDIT>>> I think I ansered my own question. What will happen if you connect VCC to AREF? I think it is fine unless you were to use a reference less than 1.1V, the internal reference would then bias the voltage to 1.1v. Typically the only difference would be setting the internal voltage off but I will get it changed around with a few more commands to select any of the modes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 5/26/2007 6:13:33 PM GMT
    652 x 611 - 16K
    520 x 587 - 14K
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-05-29 21:51
    Thank you. By adding a 300 uS delay it is working now. It makes sense that I would need to wait for the AD conversion to complete.

    I read but did not properly understand the purpose of initializing the chip and setting the timeout interval. I will create a longer delay to give myself more time to read the data.

    The ADC seems to be working fine now while still being wired as you first indicated. However, I will likely be making the changes you recommended.

    Thank you for your help!

    - Sparks
  • boeboyboeboy Posts: 301
    edited 2007-06-01 21:41
    I just got my chip i am going to start trying it out tonight.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My computer, http://forums.parallax.com/showthread.php?p=630466
  • bambinobambino Posts: 789
    edited 2007-06-06 14:54
    Metron9,
    Dev Time has been hard to find these last few days, but I have managed to get it set up on a board with the propeller.
    I will pick up a mosfett today for a level translator and hopefully have some initial results soon.
    I did not see until today what you had done with the servo controller, Pretty good idea.

    I have a servo collecting dust at the moment, I'll try to dig it out this weekend.
  • metron9metron9 Posts: 1,100
    edited 2007-06-06 15:08
    Hi bambino, I have been posting every day on other threads. I did see your PM you sent from the library but you did not ask a question so I did not reply.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • boeboyboeboy Posts: 301
    edited 2007-06-07 02:48
    OK I am now just using it in a small circuit for blinking LED's what I would like to do is to is use a pot and some LEDs so that if the pot is in a certain position it will light up a certain led.

    PS sorry that it took me so long to post feed back.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My computer, http://forums.parallax.com/showthread.php?p=630466
  • metron9metron9 Posts: 1,100
    edited 2007-06-07 04:09
    The ADC has a reference voltage of 1.1V if you connect a .1UF capacitor to the AREF pin and the other side to ground.

    Connect a 3.5K resistor to +5V the other side of the resistor to the wiper of a 1K pot and one of the other terminals on the POT to ground.

    This will give you ADC readings that will span from just above 0 to 255. Divide 256 by the number of LEDS you want to light.

    Say it is 4 LEDS. 256/4=64.

    Using the stamp. Read the adc using the shiftout and shiftin commands and then use an if then structure to turn on or off the leds.

    This will get you started. Just add code to turn on and off the LEDS and the shiftout and shiftin commands to read the ADC.

    This code as it stands will help you find the low and high values of your resistor network.

    I like to code in small sections and test each segment. Notice there are only three tests for less than values and the program execution falls through the last test if the number is greater or equal to the last if then test. Notice also I did not test the upper and lower numbers as the code exits the if then structure on a match. Some would code something like "if x>0 and x<64 then". Lots of ways of doing this.

    Have fun.



    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM2}
    END
    
    adcval VAR Byte
    
    main:
    adcval=adcval+1        'this line used FOR testing
    IF adcval<64 THEN led1
    IF adcval<127 THEN led2
    IF adcval<192 THEN led3
    
    led4:
    DEBUG "adcval>191 ",DEC adcval,CR
    GOTO main
    
    led1:
    DEBUG "adcval<64 ",DEC adcval,CR
    GOTO main
    led2:
    DEBUG "adcval<127 ",DEC adcval,CR
    GOTO main
    led3:
    DEBUG "adcval<192 ",DEC adcval,CR
    
    GOTO main
    
    




    I thought I would add a subroutine formatted structured program as well.
    Note the goto ledexit. That way there is only one return in the subroutine and any clean up code can be put there. Typical of subroutines in assembler as registers are typically pushed on the stack at the entry and popped back on exit, it reduces code size and redundant code.

    For example the led turn and off could be at this exit point. Using a variable and setting the bit that corresponds to to the pin to 1, the exit code can and the pin register with this variable to turn on one led and turn the other ones off for example.

    Try making a program that turns on all the leds when the POT is full on and 1/2 of them at the 1/2 way point. (be sure you use big enough resistors when turning on lots of leds from the pins, you don't want to power too many at 20ma each. I like 1K resistors when testing.


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' {$PORT COM2}
    
    
    adcval VAR Byte
    
    main:
    adcval=adcval+1        'this line used FOR testing
    GOSUB lightled
    GOTO main
    END
    
    
    
    'Subroutines
    
    lightled:
    IF adcval<64 THEN led1
    IF adcval<127 THEN led2
    IF adcval<192 THEN led3
    
    led4:
    DEBUG "adcval>191 ",DEC adcval,CR
    GOTO ledexit
    led1:
    DEBUG "adcval<64 ",DEC adcval,CR
    GOTO ledexit
    led2:
    DEBUG "adcval<127 ",DEC adcval,CR
    GOTO ledexit
    led3:
    DEBUG "adcval<192 ",DEC adcval,CR
    ledexit:
    RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 6/7/2007 4:25:43 AM GMT
  • bambinobambino Posts: 789
    edited 2007-06-07 17:17
    Metron9,
    Yes the PM was just FYI. I got to look at your files and noticed the spi was using pull downs instead of pull ups, so I didn't use the Mosfett like I said. I wired in a 1K current limiter on the data line and wa-laa. I didn't have but an Hour so I tried the ADC out.

    I used the BS2.Functions object in the Propeller to imitate a shiftout/in sequence. I did not get what you would expect for a reading, but by reading in 12 bits and shifting the result right 1 bit, I was able to read a pot perfectly. I have not hooked a scope up to it yet, however, a straight 12 bit reading was giving me $1FC or $1FE for a result at Vcc. Just reading 8 bits on the shiftin command got me $1F every time at Vcc. I am using MSBPOST for a mode setting.
    It works great though. It did not take any time at all to get up and running.

    ps. I may not get back online again until next week.
  • metron9metron9 Posts: 1,100
    edited 2007-06-07 17:46
    Since you are using a prop, I think the problem is you need to wait about 300 uS before the shiftin command. That is why i think 12 bits is working, the first two are just creating the time delay and the input routine is not even seeing the clock input because the interrupt is turned off during the ADC read, actually the chip is in sleep mode while the ADC reads the pin.

    So make a 300uS delay between the shiftin and shiftout commands and it will work fine.

    See page one of this thread, I have scope shots and comments to sparksarefun about the same thing he did on the SX chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!

    Post Edited (metron9) : 6/7/2007 5:52:09 PM GMT
  • phil kennyphil kenny Posts: 233
    edited 2007-06-09 21:42
    Metron9

    I've been searching for the Atmel data sheet for your Co-Pro Mega48
    but the closest I've come is this one:

    http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf

    I suspect that it isn't the right one since it mentions a 10 bit ADC more
    flash memory, more RAM, etc.

    Do you have a link for the device sent to beta testers? I want to see
    the current ratings for each pin.

    phil
  • phil kennyphil kenny Posts: 233
    edited 2007-06-09 22:06
    Metron9,

    Maybe I did have the right data sheet after all and your Co-Pro Mega48
    does indeed have a 10-bit ADC, even though you only give access to the
    upper 8 bits.

    Is there an easy way for you to give the user the ability to get at the
    full 10-bit result in future versions?

    I would like to supply an external Vref of 4.096 volts. Together with the
    10 bit output, this gives a 'nice' conversion factor of 4 mv/bit.

    phil
Sign In or Register to comment.