h-bridge question....

Hi all!

Hope you are all well!

I’m playing with the Pololu MD01B H-Bridge with my Sam7x256 (using crossworks) and I seem to be getting stuck! I had this working with my Ardino just fine, but lost my machine (ie. all my code etc) and cannot seem to make it work again using the ARM7 this time…

All I want to do it make the motor spin…

Here is my sample code…I’m sure I am doing something stupid!

Any pointers would be greatly appreciated!

~Kam (^8*

// at91sam7x256 using Crossworks on a Olimex SAM7-EX256 board

// hbridge
//#define hb_INa          (1<<27)                     // PB27
//#define hb_ENa          (1<<28)                     // PB28
//#define hb_PWM          (1<<29)                     // PB29
//#define hb_INb          (1<<30)                     // PB30
//#define hb_ENb          (1<<23)                     // PB23

// test for Pololu MDO1B h-bridge
void testMotor()
{
    // configure port B
    pPIOB->PIO_PER = hb_INa | hb_INb | hb_ENa | hb_ENb | hb_PWM; 
    pPIOB->PIO_OER = hb_INa | hb_INb | hb_ENa | hb_ENb | hb_PWM;
    pPMC->PMC_PCER = 1 << AT91C_ID_PIOB; // enable the clock of the PIO
    
    // what I now want to do is set it up as
    // 
    // INa=high
    // INb=low
    // ENa=high
    // ENb=high
    // PWM=high (but we toggle) 
     
    // turn on INa, ENa, ENb, PWM (make high)
    pPIOB->PIO_SODR=hb_INa | hb_ENa | hb_ENb | hb_PWM;

    // turn off INb (make low)
    pPIOB->PIO_CODR=hb_INb;

    while(1)
    {
        // delay for some time 
        for(int x=0; x<500000; x++)
        {
            x=x+1;
            x=x-1;
        }

        // toggle PWM bit
        if((pPIOB->PIO_ODSR & hb_PWM) == hb_PWM)
        {
            pPIOB->PIO_CODR=hb_PWM;
        }
        else
        {
            pPIOB->PIO_SODR=hb_PWM;
        }
    }
}

Hi all,

Okay I have a working example. just posting it here to close the loop… :stuck_out_tongue:

// registers
volatile AT91PS_ADC pADC = AT91C_BASE_ADC;
volatile AT91PS_PDC pPDC = AT91C_BASE_PDC_SPI0;
volatile AT91PS_PIO pPIOA = AT91C_BASE_PIOA;
volatile AT91PS_PIO pPIOB = AT91C_BASE_PIOB;
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
volatile AT91PS_SPI pSPI = AT91C_BASE_SPI0;
volatile AT91PS_PWMC_CH pPWM_CH0 = AT91C_BASE_PWMC_CH0;
volatile AT91PS_PWMC pPWM = AT91C_BASE_PWMC;

//// hbridge pins
//#define hb_INa          (1<<28)             // PB28        
//#define hb_INb          (1<<29)             // PB29        
//#define hb_PWM          (1<<30)             // PB30
//#define hb_MASK         (hb_INa | hb_INb | hb_PWM)

// test for Pololu MDO1B h-bridge
void testMotor()
{
    // configure port B
    pPIOB->PIO_PER = hb_MASK;           
    pPIOB->PIO_OER = hb_MASK;
    pPIOB->PIO_SODR= hb_MASK;
    pPMC->PMC_PCER = 1 << AT91C_ID_PIOB; // enable the clock of the PIO
    
    // what I now want to do is set it up as
    // 
    // INa=high
    // INb=low
    // PWM=high (but we toggle) 
     
    pPIOB->PIO_SODR=hb_INa;
    pPIOB->PIO_CODR=hb_INb;

    while(1)
    {                        
        for(int x=0; x<1000; x++)
        {
        }

        // toggle PWM bit
        if((pPIOB->PIO_ODSR & hb_PWM) == hb_PWM)
        {
            pPIOB->PIO_CODR=hb_PWM;
        }
        else
        {
            pPIOB->PIO_SODR=hb_PWM;
        }
    }
}