0

I want to drive a BLDC motor, i use ATMEGA32 as CPU of controller , i have a problem in reading hall effect sensor from BLDC motor

this is my code :

DDRB=(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5);
DDRD=(0<<0)|(0<<1)|(0<<2)|(0<<3);
PORTD=(1<<0)|(1<<1)|(1<<2)|(1<<3);

PORTB as OUTPUT and PORTD as INPUT this is main program :

       if (~(PORTD &(1<<0)) && PORTD &(1<<1) && ~(PORTD &(1<<2))) /// 0   1   0
        {
            PORTB=(1<<0)|(0<<1)|(0<<2)|(1<<3)|(0<<4)|(0<<5);
        }
        else if (~(PORTD &(1<<0)) && PORTD &(1<<1) && PORTD &(1<<2)) /// 0   1   1
        {
            PORTB=(0<<0)|(0<<1)|(0<<2)|(1<<3)|(0<<4)|(1<<5);
        }
        ...........

my answer is this program cannot read logic zero (0) from hall effect sensor so BLDC cannot run well, how to read multiple input in AVR ATMEGA32 ? i use Codeblock and winavr....

Thank you very much

Lukis triya
  • 1
  • 1
  • 3

1 Answers1

0

I don't really understand what you want to do, but if you want to read from Port D in the atmega 32, you do not deal with the 'PORTD' register, there is another Register called 'PIND', this is the one you read digital signals from. Also there nothing as ">DDRD=(0<<0)|(0<<1)|(0<<2)|(0<<3);" If you want to clear a bit (set the bit to logic zero), you just use the bitwise not with the shifted one (e.g. DDRD = ~(1<<bitnumber)