2 This is a sample application for openMSP430 softcore MCU with external HW UART
3 periphery <git@rtime.felk.cvut.cz:fpga/uart> and quadcount and pwm periphery.
5 First of all "Hello world" is printed and then application works like echo and
6 also prints quadrature count whenever its value is changed.
8 AB error of quadrature counter periphery is handled by irq routine which prints
9 message "IRQ: QCounter AB error!".
11 In endless main loop, when nothing else is doing, triangle singnal is being
12 generated by the PWM periphery.
14 Baudrate is set to 115200.
26 inline uint32_t qcount() {
30 result |= ((uint32_t)QCNTH << 16);
36 Handling of QuadCounter IRQ
38 interrupt(QCNT_VECTOR) qcount_isr() {
39 puts("IRQ: QCounter AB error!");
45 Print bits of byte in format b'xxxxxxxx'
47 void print_byte_flags(char flags) {
53 for (i = 8; i != 0; i--) {
54 if ((flags & 0x80) != 0) {
71 void delay(unsigned long int a, unsigned long int b) {
85 Main function with init and an endless loop.
88 uint32_t qcnt = qcount();
93 //UBAUD = 0x04E1; //24.00MHz - 9600 baud
94 UBAUD = 0x0067; //24.00MHz - 115200 baud
96 eint(); //enable interrupts
99 puts("Hello world\n");
102 while (!isRxEmpty()) {
107 if (qcnt != qcnt_new) {
108 printf("[QCount = 0x%08lX]\n", qcnt_new);
113 if (++PWM == 0xFFFF) sign = 0;
115 if (--PWM == 0x0000) sign = 1;