Read PWM signal from CMPS03 Compass Sensor Module

The CMPS03 compass module has been specifically designed for use in robots as an aid to navigation. A PWM signal is available on pin 4. 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 - i.e. 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. 

This program will read PWM signal from CPMS03 Compass Module and convert it to an angle. The PWM signal from pin 4 of compass module fed to port C pin 2 of ATmega8535 microcontroller. Note that we use 11.0592MHz clock frequency.
This program uses timer0 to measure the positive width of PWM pulse. At the positive-going-transition of PWM signal, timer0 goes on; and at the negative-going-transition of PWM signal, timer0 goes off. With prescaler=8, the timer will need 0.72338us per step counting. The timer will count 1382.4 (0x567) if the positive width of the pulse is 1ms. This value will be represented as 0 degree. And the timer will count 51148.8 (0xc7cc) if the positive width of the pulse is 37ms. This value will be represented as 360 degree.
The angle in 16-bit hexadecimal format can be read at the address of Compass_raw_loc of SRAM. This varies from 0 (0x0000) to 360 (0x0168). And the angle in 3-characters ASCII format can be read at the address of Compass_loc of SRAM. This varies from ‘000’ to ‘360’.

Download Program

What’s next? You can send the data to PC like data logger....

click here for more information 

Drive an ESC with PWM from AVR Microcontroller

A brushless DC motor (BLDC) is an AC synchronous electric motor that from a modeling perspective looks very similar to a DC motor. Sometimes the difference is explained as an electronically controlled commutation system, instead of a mechanical commutation system, although this is misleading, as physically the two motors are completely different…
Brushless DC motor controllers are much more complicated than brushed motor controllers. They have to convert the DC from the battery into phased AC (usually three phase) in order to produce the changing magnetic field.
DC ESCs in the broader sense are PWM controllers for electric motors. An electronic speed control or ESC is an electronic circuit with the purpose to vary an electric motor's speed, its direction and possibly also to act as a dynamic brake. The ESC generally accepts a nominal 50 Hz PWM servo input signal whose pulse width varies from 1ms to 2ms. When supplied with a 1 ms width pulse at 50Hz, the ESC responds by turning off the DC motor attached to its output. A 1.5ms pulse-width input signal results in a 50% duty cycle output signal that drives the motor at approximately half-speed. When presented with 2.0ms input signal, the motor runs at full speed due to the 100% duty cycle (on constantly) output.
The correct phase varies with the motor rotation, which is to be taken into account by the ESC: Usually, back EMF from the motor is used to detect this rotation, but variations exist that use magnetic or optical detectors. Computer-programmable speed controls generally have user-specified options which allows setting low voltage cut-off limits, timing, acceleration, braking and direction of rotation. Reversing the motor's direction may also be accomplished by switching any two of the three leads from the ESC to the motor.

Why use an AVR microcontroller?
In the AVR, the timer/counter 1 is used to generate PWM signals. This signal emitted from OC1A pin of ATmega8535 microcontroller and fed to an ESC to drive two brushless DC motors. The width of the PWM pulse was defined by the value of OCR1A. The maximum value of this register will set the motor at low voltage cut-off limits. This value was defined by OCR1_HIGH. And the minimum value of this register will set the motor run at highest speed. This value was defined by OCR1_LOW.
To speed up motor, you can use a command or make port C pin 2 high; and to slow down motor, you can use a command or make port C pin 3 high.

The development of this application to specific purpose application is become new really enabled and has been done.