Menu

mcp23017 demos

Help
2019-09-14
2019-09-16
  • stan cartwright

    stan cartwright - 2019-09-14

    Sorry to be a pain but I'm checking out a bot with stepper motors using include mcp23017.h.
    There was some discusion about it in the forum and which syntax was correct.
    I've checked git hub under anobium demos but can't find the demos I have on one pc...it's not my code.

    #chip mega328p,16
    #include <MCP23017.h>
    #option Explicit
       #define I2C_MODE Master
       #define I2C_DATA PORTC.4
       #define I2C_CLOCK PORTC.5
       #define I2C_DISABLE_INTERRUPTS ON
       'Optionally, you can reduce the I2C timings.
       #define I2C_BIT_DELAY 0 us
       #define I2C_CLOCK_DELAY 1 us
       #define I2C_END_DELAY 0 us
    
    dir portc.0 out
    T
    #define MCP23017_addr 78
    ;#define MCP23017_IODIRA 0; make porta output
    ;MCP23017_sendbyte (MCP23017_addr,MCP23017_IODIRA,0) ;set port a to out
    MCP23017_sendbyte(MCP23017_addr,MCP23017_GPIOA,0)
    dim lmotforward,lmotor,rmotforward,rmotor,lmotval,rmotval as byte
    lmotforward=255:lmotor=1:rmotforward=1:rmotor=1
    
    ;interrupt drives motor 100 Hz
        On Interrupt Timer0Match1 Call motors
    
        Dim OCR0  AS byte alias OCR0A
        Dim TCCR0 AS  byte alias TCCR0B
        WGM01 = 1                'Timer in CTC mode - required
    
        OCR0 = 19
        TCCR0 = 0x28
        TCCR0 = TCCR0 or 0x05
    
    ';interrupt drives motors
    '    On Interrupt Timer1Overflow Call motors
    '    ' Initialise the timer - this is required
    '    ' Set prescaler to 1 and then start the timer
    '    InitTimer1 Osc, PS_1_1
    '    ' Start the timer - this is required
    '    StartTimer 1
    '    'Set here to initialise but you need to set in the Interrupt routine handler
    '    ' Use the Timer Calc' application that is part of Mister E PIC Mutl-calc tookset to calculate the value.
    '    ' Ensure you set the Prescaler in the InitTimer1 shown above
    '    SetTimer 1, 25538
    ;
    
    ;
    do
    ;your code
    loop
    ;----- end
    'This will be called when the Timer overflows
    Sub motors
      ' Set the register to 6 to give us the 10ms Interrupt.
      ' Use the Timer Calc' application that is part of Mister E PIC Mutl-calc tookset to calculate the value.
      ' Ensure you set the Prescaler in the InitTimer1 shown above
    ;  SetTimer 1, 25538 ;reset timer
    ;left stepper motor
      if lmotforward=1 Then
        lmotor++
        if lmotor=9 then lmotor=1
      else
        lmotor---
        if lmotor=0 then lmotor=8
      end if
    ;
      select case lmotor
        case 1
        lmotval=128
        case 2
        lmotval=192
        case 3
        lmotval=64
        case 4
        lmotval=96
        case 5
        lmotval=32
        case 6
        lmotval=48
        case 7
        lmotval=16
        case 8
        lmotval=144
      End Select
    
    ;right stepper motor
      if rmotforward=1 Then
        rmotor++
        if rmotor=9 then rmotor=1
      else
        rmotor---
        if rmotor=0 then rmotor=8
      end if
    ;
      select case rmotor
        case 1
        rmotval=1
        case 2
        rmotval=3
        case 3
        rmotval=2
        case 4
        rmotval=6
        case 5
        rmotval=4
        case 6
        rmotval=12
        case 7
        rmotval=8
        case 8
        rmotval=9
      End Select
    
    MCP23017_sendbyte (MCP23017_addr,MCP23017_GPIOA,lmotval+rmotval) ;sets porta to lmotval+rmotval
    portc.0=!portc.0
    End Sub
    

    where are the mcp23017 demos please? I have looked but only found myself talking rubbish in the forum.

     
  • Anobium

    Anobium - 2019-09-15

    No demo for these parts. I have them in extensive use with real solutions.

    The only demo is here post by some fella called Stan. :-)

     
  • stan cartwright

    stan cartwright - 2019-09-15

    I found this https://sourceforge.net/p/gcbasic/discussion/629990/thread/d82cd72e/?limit=25#9d3a
    it seems so unfamiliar after a short time.
    really handy chip for running stepper motors via uln 2803.
    16 io pins is handy but not sure how fast it is. driving a glcd comes to mind. they need lots of pins sometimes.
    Any way,now to convert motor pulses to degrees using cheap 28BYJ-48 Stepper Motor.

     

    Last edit: stan cartwright 2019-09-15
  • Anobium

    Anobium - 2019-09-16

    When you get familiar .... a few demos would be good to put in the demo folder, and, some documentation.

     
  • stan cartwright

    stan cartwright - 2019-09-16

    It seems to be coming back..a bit.
    The idea of running from interrupts is nice but speed could be adjusted by other ways than intrrupt speed.
    I don't understand 4 pole stepper motors as far as do you send 4 bits or 8.
    some files I found

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.