1 (2011-09-13 00:22:20 отредактировано bod)

Тема: Как правильно считывать PWM?

Добрый день!

Требуется помощь! Не считываются показания цифрового компаса.

Имеется:

  • Arduino Uno SMD
    IO Expansion Shield For Arduino(V5)
    Цифровой компас CMPS-03

Компас может отдавать значения по интерфейсам l2c и PWM.

Пытаюсь считать значения PWM.

Из документации:

The PWM signal is a pulse width modulated signal with the positive width of the pulse representing the angle.
The pulse width varies from 1mS (0° ) to 36.99mS (359.9° ) – in other words 100uS/° with a +1mS offset. The
signal goes low for 65mS between pulses, so the cycle time is 65mS + the pulse width - ie. 66ms-102ms. The
pulse is generated by a 16 bit timer in the processor giving a 1uS resolution, however I would not recommend
measuring this to anything better than 0.1° (10uS). Make sure you connect the I2C pins, SCL and SDA, to the
5v supply if you are using the PWM, as there are no pull-up resistors on these pins.



Компас подлключен на цифровой порт 3.  Проблема в том , что на вход всегда идет "1".

Проверял следующим кодом:

const int pwm_pin = 3;
int pwm_val = 0;
int pwm_val_t = 0;

 

void setup() {
   Serial.begin(9600);
   pinMode(pwm_pin, INPUT);
}

 
void loop() {
   pwm_val=digitalRead(pwm_pin);
   //if (pwm_val=0) pwm_val_t= pulseIn(pwm_pin, HIGH ) ;
   if ( pwm_val=0) Serial.print(0); ;
   //Serial.println();
   //delay(200);
}

Что я не так делаю ?

2

Re: Как правильно считывать PWM?

bod пишет:

Добрый день!

Требуется помощь! Не считываются показания цифрового компаса.

Имеется:

  • Arduino Uno SMD
    IO Expansion Shield For Arduino(V5)
    Цифровой компас CMPS-03

Компас может отдавать значения по интерфейсам l2c и PWM.

Пытаюсь считать значения PWM.

Из документации:

The PWM signal is a pulse width modulated signal with the positive width of the pulse representing the angle.
The pulse width varies from 1mS (0° ) to 36.99mS (359.9° ) – in other words 100uS/° with a +1mS offset. The
signal goes low for 65mS between pulses, so the cycle time is 65mS + the pulse width - ie. 66ms-102ms. The
pulse is generated by a 16 bit timer in the processor giving a 1uS resolution, however I would not recommend
measuring this to anything better than 0.1° (10uS). Make sure you connect the I2C pins, SCL and SDA, to the
5v supply if you are using the PWM, as there are no pull-up resistors on these pins.



Компас подлключен на цифровой порт 3.  Проблема в том , что на вход всегда идет "1".

Проверял следующим кодом:

const int pwm_pin = 3;
int pwm_val = 0;
int pwm_val_t = 0;

 

void setup() {
   Serial.begin(9600);
   pinMode(pwm_pin, INPUT);
}

 
void loop() {
   pwm_val=digitalRead(pwm_pin);
   //if (pwm_val=0) pwm_val_t= pulseIn(pwm_pin, HIGH ) ;
   if ( pwm_val=0) Serial.print(0); ;
   //Serial.println();
   //delay(200);
}

Что я не так делаю ?

На соседнем форуме помогли разобраться с проблемой.
Выяснилось, что на стандартных разъемах от Inex, Signal и Vcc идут в другом порядке.
После того как сделал правильный порядок проводов все заработало.