summaryrefslogtreecommitdiffhomepage
path: root/digital/beacon
diff options
context:
space:
mode:
authorFlorent Duchon2012-05-16 17:04:00 +0200
committerFlorent Duchon2012-05-16 17:43:08 +0200
commit640ae537ae3536361b7401de740e3c2be94a8a37 (patch)
tree7b44f7cf131faaa3e62eefa8cb767e9cdf049ede /digital/beacon
parentdba137dc4ec11f695f853d643fd8621500b7d9b0 (diff)
digital/beacon: control motor via PWM with TIMER0
Diffstat (limited to 'digital/beacon')
-rw-r--r--digital/beacon/src/motor.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/digital/beacon/src/motor.c b/digital/beacon/src/motor.c
index c487c22a..56682b48 100644
--- a/digital/beacon/src/motor.c
+++ b/digital/beacon/src/motor.c
@@ -28,24 +28,41 @@
/* This function initializes the motor control output */
void motor_init(void)
{
- DDRB |= (1<<PB7);
+ /* Select ouptut */
+ DDRB |= (1<<PB7);
+
+ OCR0A = 0;
+
+ /* Fast PWM 10bits with TOP=0x03FF */
+ TCCR0A |= (1<<WGM01)|(1<<WGM00);
+
+ /* Prescaler = 1 */
+ TCCR0B |= (1<<CS01);
+
+ /* Postive Logic */
+ TCCR0A |= (1<<COM0A1);
+
+ /* Enable Interrupts */
+ sei();
}
/* This function starts the motor rotation */
void motor_start(void)
{
- PORTB |= (1<<PORTB7);
+ OCR0A = 115;
+
}
/* This function stops the motor rotation */
void motor_stop(void)
{
- PORTB &= ~(1<<PORTB7);
+ OCR0A = 0;
}
+/* This function returns the motor state */
TMotor_state motor_get_state(void)
{
- if(PORTB&(1<<PORTB7))
+ if(OCR0A != 0)
return MOTOR_IN_ROTATION;
else
return MOTOR_STOPPED;
@@ -54,9 +71,13 @@ TMotor_state motor_get_state(void)
/* This function starts or stops the motor according to the current state */
void motor_start_stop_control(void)
{
-
if(motor_get_state() == MOTOR_IN_ROTATION)
motor_stop();
else
motor_start();
}
+
+
+ISR(TIMER0_COMPA_vect)
+{
+} \ No newline at end of file