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

ALPHA testing thread for Co-Pro Mega48

2»

Comments

  • boeboyboeboy Posts: 301
    edited 2007-06-10 00:16
    How abought makeing it so that it can do PMW and drive servos.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My computer, http://forums.parallax.com/showthread.php?p=630466
  • metron9metron9 Posts: 1,100
    edited 2007-06-10 04:18
    Phil, Yes the mega48 is the correct data sheet, it is 10 bits and the lowest 2 bits are dropped. Yes it can be made to give you a 10 bit result. I just did not see the need for higher resolution for the typical application. A few lines of code is all the change necessary. There are so many ways to set up an ADC I just picked one.

    The code is easily ported to the mega88 and 168 as well, Ihave both for testing. All that needs to be done is change the minimum memory address pointers to allow more memory to be used. I buy the mega48 in 100 qty so I just used that.

    boeboy, I made a servo chip from a tiiny11. Again , there are so many ways to set up a servo PWM chip, total number of servos and resolution of the pulse width. The servo chip I made has 11 us resolution plus or minus but for my testing I did not see any jitter. I can program anything that can be programmed so these two example chips are pretty much just an example of what can be done.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • phil kennyphil kenny Posts: 233
    edited 2007-06-10 05:15
    metron9 said...
    Phil, Yes the mega48 is the correct data sheet,
    it is 10 bits and the lowest 2 bits are dropped. Yes it can be made
    to give you a 10 bit result. I just did not see the need for higher
    resolution for the typical application. A few lines of code is all the
    change necessary. There are so many ways to set up an ADC I
    just picked one.

    Metron,

    I agree that for most applications, an 8-bit ADC value will suffice.
    It just seemed that it would be desireable for the atypical user to
    have an option for accessing the full 10-bit ADC conversion.

    Perhaps this could be implemented via a mode selection bit, with
    8-bits being the default mode.

    phil
  • metron9metron9 Posts: 1,100
    edited 2007-06-10 14:52
    "Perhaps this could be implemented via a mode selection bit, with
    8-bits being the default mode."

    Ahh but there are three different references one can use as well.

    1 use internal 1.1 reference
    2 use AVCC
    3 use External AREF

    Then add the 8 or 16 bit output of two modes

    we now have six modes.

    A new mode command $A6 with a second byte as the mode 1..6

    One byte return value (left shifted 8 bit value)
    1 use internal 1.1 reference
    2 use AVCC
    3 use External AREF

    Two byte return value High/Low
    4 use internal 1.1 reference
    5 use AVCC
    6 use External AREF

    Not sure yet if shiftin can use just a 2 bit variable, I know you can specify 2 bits to read into an 8 bit bariable but I am not sure when you use the variable in your calculations if it makes any difference. You cant just add or subtract in assembler a two bit register because there isn't one, you have to use a full byte so Pbasic under the hood uses a temporary 8 bit value anyway. The SX and Prop can use a temporary high byte for input and store the two bits if it is running low on registers. Same for Pbasic, read in the high byte in temporary 8 bit variable and store the result in 2 bits if it needs more space. So as you can see, there are a lot of ways to go. Perhaps you have some input on the 2 high bits to shift in, use an 8 bit variable or a 2 bit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • bambinobambino Posts: 789
    edited 2007-06-11 15:52
    Metron9,
    Ok, I,ve got the delay in and it is reading better. My last problem with the ADC before retiring yesterday was in reading a pot.
    While turning slowly as I got near the end of the turn it would read the opposite, for a small voltage change, then get right again.
    I suspected my pot and turned it around and got the same thing. I want to try out some of the other functions for a while and then I'll come back to this with another pot.

    Ps, See my other post in the servo thread.
  • FranklinFranklin Posts: 4,747
    edited 2007-06-16 03:19
    OK, Here's another. I don't see the codes for all the commands on your document list. For instance what is the command code for _ADCVCCx? How about _STIME?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • metron9metron9 Posts: 1,100
    edited 2007-06-16 23:07
    Sorry about the confusion there Franklin. I did not actually code the additional ADC commands yet. I wrote the cover page for the commands first and then coded the subroutines. After coding the initial ADC routines that use the 1.1 reference I skipped to the memory routines because those were the ones I wanted to do at the time. I will add the various modes in the future. For now use a capacitor on the AREF pin to ground and the ADC read commands will read the internal 1.1V reference.

    I see I also neglected to put the set time command in the list. I will just repost here the pbasic code I was using to test various functions.

    I wish I had someone to do the documentation and wrap up all the loose ends with this kind of stuff because I am one of those people that only likes to work on things I find interesting at the time, I think I have ADD I can do very complex programming but the simple stuff of documenting things and dotting my I's and T's is something I have a very hard time with. That's why I have a secretary that takes care of all that for me in my real job.

    Anyway I think all the code for all the commands are in this code, if something specific is missing or doesn't work let me know.

    A note on the ADC if you wish to read VCC instead of the 1.1 internal reference.

    I have tested the ADC by putting VCC on the AREF pin and even though internally I use the internal 1.1 voltage reference I think the AREF connected this way will override the 1.1 internal voltage supply and allow you to measure up to 5V or whatever you are powering the chip with.

    ' {$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
    _DAYS           CON   $C8 'Read Days
    _TIME           CON   $C9 '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
    
    
    page      VAR   Byte
    TEMP      VAR   Word
    BUFFER    VAR   Byte
    Seconds   VAR   Byte
    Minutes   VAR   Byte
    Hours     VAR   Byte
    days      VAR   Byte
    Address   VAR   Byte
    
    
    
    PAUSE 1000
    DEBUG "CO-PRO-M48 Command Test Program",CR
    
    
    'Initialize Coprocessor
    
    SHIFTOUT 0,1,1,[noparse][[/noparse]_INIT\16]
    
    adc:
    SHIFTOUT 0,1,1,[noparse][[/noparse]_ADC0]
    SHIFTIN 0,1,0,[noparse][[/noparse]buffer]
    DEBUG "ADC0 Value = ",DEC buffer,CR
    
    END
    
    
    
    'settime seconds,minutes,hours,days
    SHIFTOUT 0,1,1,[noparse][[/noparse]_SETTIME,58,59,23,255]
    
    'Test High and Low of all 18 pins
    FOR temp=0 TO 17
     SHIFTOUT 0,1,1,[noparse][[/noparse]_HIGH,temp]  :  DEBUG "Pin 1 is HIGH",CR :PAUSE 100
    'Set a PIN LOW
    SHIFTOUT 0,1,1,[noparse][[/noparse]_LOW,temp]   :  DEBUG "Pin 1 is LOW",CR  :PAUSE 100
    NEXT
    
    
    'Test timer get time variables
    SHIFTOUT 0,1,1,[noparse][[/noparse]_TIME]
    SHIFTIN 0,1,0,[noparse][[/noparse]Seconds,Minutes,Hours,days]
    DEBUG "Days ", DEC days, " Hrs ", DEC Hours," MIN ",DEC Minutes," Sec ",DEC Seconds,CR
    
    'Get seconds,minutes,hours,days with seperate commands
    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]
    SHIFTOUT 0,1,1,[noparse][[/noparse]_DAYS]
    SHIFTIN 0,1,0,[noparse][[/noparse]DAYS]
    DEBUG "Days ", DEC days, " Hrs ", DEC Hours," MIN ",DEC Minutes," Sec ",DEC Seconds,CR
    
    
    
    'Test EEPROM Write and READ (_ewrite,Address,Byte to write)
    TEMP=127
    Address=1
    SHIFTOUT 0,1,1,[noparse][[/noparse]_EWRITE,Address,TEMP]
    PAUSE 1
    SHIFTOUT 0,1,1,[noparse][[/noparse]_EREAD,Address]
    SHIFTIN 0,1,0, [noparse][[/noparse]buffer]
    DEBUG "The eeprom address ",DEC Address," = ",DEC buffer,CR
    
    'Test flash memory storage
    SHIFTOUT 0,1,1,[noparse][[/noparse]_zSTACK]
    
    DEBUG "Writing Sram location 0 with 127",CR
    SHIFTOUT 0,1,1,[noparse][[/noparse]_PUSH,127]
    
    DEBUG "Writing 256 byte buffer to page 1 of flash memory",CR
    page=1
    SHIFTOUT 0,1,1,[noparse][[/noparse]_WRITEFLASH,page]
    PAUSE 30
    
    
    
    testpins:
    
    '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 with a Pullup
    SHIFTOUT 0,1,1,[noparse][[/noparse]_INPUTP,1] :  DEBUG  "Pin 1 is INPUT with Pullup",CR :PAUSE 1000
    'Set a PIN TO INPUT
    SHIFTOUT 0,1,1,[noparse][[/noparse]_INPUT,1] :  DEBUG  "Pin 1 is INPUT",CR :PAUSE 1000
    
    
    
    
    '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 HEX buffer,CR
    
    
    
    '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!
  • bambinobambino Posts: 789
    edited 2007-06-18 15:35
    Before I could ask for it.
    Thanks!
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-06-19 19:41
    bambino said...
    My last problem with the ADC before retiring yesterday was in reading a pot. While turning slowly as I got near the end of the turn it would read the opposite, for a small voltage change, then get right again. I suspected my pot and turned it around and got the same thing. I want to try out some of the other functions for a while and then I'll come back to this with another pot.
    I have a well-worn pot that behaves like this! A voltmeter confirmed it was the pot that was causing the anomaly in the reading.

    - Sparks
  • boeboyboeboy Posts: 301
    edited 2007-06-19 23:26
    OK here is what I am planing to do with it. I am going to use its onboard ADC's and its I/O pins along with a Microsoft steering wheel with petals*to steer and control the throttle on a remote control boat like this one http://www.amazon.com/Remote-Control-Speed-Century-Boat/dp/B000KVDKOC/ref=sr_1_4/104-7743806-7133552?ie=UTF8&s=toys-and-games&qid=1182295615&sr=1-4

    *for PC gaming

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My computer, http://forums.parallax.com/showthread.php?p=630466
  • bambinobambino Posts: 789
    edited 2007-06-20 16:28
    Sparks,
    Indeed, the pot was suspected. I have since replaced it and still get the same results. I did check it with a meter and found I was reading 254
    @ just over three volts.(AREF tied to VCC). I changed the connection to use a cap to gnd from AREF and this cured the problem.
    Honestly, It was acting like I was recieving the 8LSB of a 10 bit reading rather than the 8MSB, except that when it rolled over a small adjustment to the
    pot would bring it back in line.

    Metron9,
    I have finished everything but the Flash commands. So far so good!
  • metron9metron9 Posts: 1,100
    edited 2007-06-20 16:37
    Future coprocessors will have mode selection for reference voltages. Good to hear it is working as it should with the 1.1V ref and cap to ground.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • FranklinFranklin Posts: 4,747
    edited 2007-06-23 22:13
    OK, so I'm slow. I haven't had much time to work with this so today I set it up and tried to read a voltage. NOTHING.. I was using ADC0 and had my voltage on pin0 (since there is no documentation or a reference to reading the data sheet for the mega48 chip from Atmel) After trying for a while I figured out ADC0 reads pin23 (pin12 on Metron9's chip) DUH!
    Got it going now and will keep testing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • metron9metron9 Posts: 1,100
    edited 2007-06-24 05:55
    If I could find someone who wanted to work with me and take care of documenting and perhaps selling the chips I can make, that would be a step in the right direction. Here is an updated how to hook up the chip picture.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
    1161 x 809 - 64K
  • bambinobambino Posts: 789
    edited 2007-06-26 16:06
    Would love to help, but Time is so scarce right now that there is no way I could take on another project.
    It seems most of all the documentation is here though, it just needs to be compiled into a pdf or something!
    Here is an idea for you though: how about putting the servo app in the Co-Pro Mege 48 as an enable/disable feature.
Sign In or Register to comment.