Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-src
Diff: main.cpp
- Revision:
- 1:fad61b6e660b
- Parent:
- 0:9826a0b36948
- Child:
- 2:7ca8b2154664
--- a/main.cpp Sat Aug 01 18:32:09 2015 +0000
+++ b/main.cpp Tue Aug 04 21:22:56 2015 +0000
@@ -1,52 +1,94 @@
#include "mbed.h"
-// CT16B0 --> MOTORA
-// CT32B0 --> MOTORB
-
-int init_drive(void) {
- // Enable match outputs of CT16B0 and CT32B0
- LPC_IOCON->PIO0_8 |= 0x2; //CT16B0_MAT0
- LPC_IOCON->PIO0_9 |= 0x2; //CT16B0_MAT1
- LPC_IOCON->PIO0_18 |= 0x2; //CT32B0_MAT0
- LPC_IOCON->PIO0_19 |= 0x2; //CT32B0_MAT1
- // Enable clock for CT16B0 (7) and CT32B0 (9)
- LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7)||(1<<9);
- // Reset on match (MAT3), MR3 will determine the PWM cycle length
- LPC_CT16B0->MCR |= (1<<10);
- LPC_CT32B0->MCR |= (1<<10);
- // Enable PWM mode for CT16B0 and CT32B0
- //LPC_CT16B0->PWMC |= (1<<0)||(1<<1); // MAT0, MAT1
- //LPC_CT32B0->PWMC |= (1<<0)||(1<<1); // MAT0, MAT1
- LPC_CT16B0->EMR |= (0x3<<4);
- // Set PWM cycle length to 100 counts
- LPC_CT16B0->MR3 = 100;
- LPC_CT32B0->MR3 = 100;
- // Set prescale register
- LPC_CT16B0->PR = 20;
- LPC_CT32B0->PR = 20;
-
- // Enable CT16B0 and CT32B0
- LPC_CT16B0->TCR |= (1<<0);
- LPC_CT32B0->TCR |= (1<<0);
+/*
+MOTOR A
+ENA - p21
+IN1 - p5 --> OUT1 - MOTORA+
+IN2 - p6 --> OUT2 - MOTORA-
+MOTOR B
+ENB - p22
+IN3 - p26 --> OUT3 - MOTORB+
+IN4 - p25 --> OUT4 - MOTORB-
+*/
+
+PwmOut in1(p5);
+PwmOut in2(p6);
+
+PwmOut in3(p26);
+PwmOut in4(p25);
+
+DigitalOut en_a(p21);
+DigitalOut en_b(p22);
+
+DigitalOut LED(LED1);
+
+Serial bluetooth(p9, p10);
+//Serial pc(USBTX, USBRX);
+
+
+/* Initialize timers for the H-bridge*/
+int init_drive()
+{
+// Set PWM frequency to 10 kHz
+ in1.period_us(100);
+ in2.period_us(100);
+ in3.period_us(100);
+ in4.period_us(100);
+ /* Set enable pin high. NEVER set this pins low during driving.
+ There are no protection diodes and with EN low, H-bridge is in Hi-Z mode.
+ This can generate a high voltage that breaks the H-bridge.*/
+ en_a.write(1);
+ en_b.write(1);
+
+ return 1;
+}
+
+/*Handler for Bluetooth messages*/
+void rxCallback()
+{
+ char a;
+ a = bluetooth.getc();
+ if(a == 'g') {
+ LED = 1;
+ }
+}
+
+/* Initialize the bluetooth module*/
+int init_bluetooth()
+{
+ bluetooth.baud(9600);
+ //wait(0.2);
+ //bluetooth.printf("AT+NAMETHOR1\r\n");
+ bluetooth.attach(&rxCallback, Serial::RxIrq);
return 1;
-
+}
+
+/* Initialize ADC ports*/
+int init_ADC()
+{
+ return 1;
+}
+
+
+/* Initialize GPIO's*/
+int init_GPIO()
+{
+ return 1;
}
-DigitalOut myled(LED1);
+int main()
+{
-int main() {
init_drive();
+ init_bluetooth();
- LPC_CT16B0->MR0 = 50;
- LPC_CT16B0->MR1 = 50;
- LPC_CT32B0->MR0 = 50;
- LPC_CT32B0->MR1 = 50;
-
- // Program ends
while(1) {
- myled = 1;
- wait(0.2);
- myled = 0;
- wait(0.2);
+/* if(pc.readable()) {
+ bluetooth.putc(pc.getc());
+ }
+ if(bluetooth.readable()) {
+ pc.putc(bluetooth.getc());
+ }*/
}
-}
+
+}
\ No newline at end of file