Sunday, July 20, 2014

Hackaday Prize and MIDI2VC+ update

Hackaday Prize

I submitted the MIDI2VC project to the Hackaday Prize contest. I know that the MIDI2VC doesn't really qualify for the connected criteria. Connected meaning connected to the Internet. My interpretation of connectedness in this case is the connection between new and old, between digital and analogue. I have no aspiration of going to the moon, but a t-shirt or some electronics swag would be nice :)

MIDI2VC+ update

I received the MCU's for the MIDI2VC+ a while ago. I don't remember if I wrote about it, but it was hard sourcing the MCU for the project (PIC24FJ64GB004), so I ended up ordering a couple of samples from Microchip. A while after the samples arrived, I realised that I had ordered the wrong chips... I had ordered PIC24FJ64GA004! Those chips are almost pin compatible, but don't have the USB host capabilities I need. I've tried getting the right chips again, but still difficult. I ordered a couple from ebay, but they are not being shipped and no explanation from the seller (a chip shortage there as well?). So, I ended up ordering samples again. This time the right ones along with a couple of PIC24FJ64GB002, which can act as USB host, but has fewer pins (I thought the first chip was the one with lowest pin count, I guess I didn't do my homework). I might use those in the next version of the board. There will, by the way, be another board version. I realised I need to use an external crystal since to internal oscillator isn't precise enough for the USB standard.

Buggy Pickit 3

I tested out the MIDI2VC+ board with the chips I got from Microchip. I managed to put together a small hello world program that flashes the four LEDs nigthrider style! The program uses maximum clock speed, with internal oscillator, and interrupts.

I tried using the Pickit 3 for the MIDI2VC, but it seems to be so buggy that I ended up going back to the Pickit 2. It would probably had taken me half the time developing the knightrider program if I had used the Pickit 2 from the beginning. However, I can't use the Pickit 2 for debugging, so I may have to use 3 once in a while anyway. Pickit 3 bugs include:
  • Sometimes, not being able to identify the target device
  • Sometimes, not being able to program target  device
  • Not being able to power device two or more times in a row
  • Same code giving totally different results on different build and programming occasions
Hello knightrider code:
 /*@ignore@*/  
 #include <xc.h>  
 /*@end@*/  
 #ifdef __PIC24FJ256GB110__     //Defined by MPLAB when using 24FJ256GB110 device  
 _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)  
 _CONFIG2(IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_ON)  
 _CONFIG3(WPCFG_WPCFGDIS & WPDIS_WPDIS) //Disable erase/write protect of all memory regions.  
 #elif __PIC24FJ256GA110__     //Defined by MPLAB when using 24FJ256GA110 device  
 _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)  
 _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI & IOL1WAY_ON)  
 _CONFIG3(WPCFG_WPCFGDIS & WPDIS_WPDIS) //Disable erase/write protect of all memory regions.  
 #elif __PIC24FJ64GA004__     //Defined by MPLAB when using 24FJ64GA004 device  
 _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx1)  
 _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_NONE & FNOSC_FRCPLL & I2C1SEL_SEC & IOL1WAY_ON)  
 #else     //Default to the PIC24FJ128GA010  
 // JTAG/Code Protect/Write Protect/Clip-on Emulation mode  
 // Watchdog Timer/ICD pins select  
 _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)  
 // Disable CLK switch and CLK monitor, OSCO or Fosc/2, HS oscillator,  
 // Primary oscillator  
 _CONFIG2(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_XT & FNOSC_PRI)  
 #endif  
 int volatile LEDS_backward;  
 int volatile LEDS_index;  
 void __attribute__((__interrupt__, __auto_psv__)) _T1Interrupt(void) {  
   extern volatile int LEDS_backward;  
   extern volatile int LEDS_index;  
   LEDS_index = ((LEDS_index + 1) % 3);  
   LATC &= 0xFFF4;  
   LATB &= 0xFFFB;  
   if (LEDS_backward == 0) {  
     switch (LEDS_index) {  
       case (0):  
         LATB |= (1 << 2);  
         break;  
       case (1):  
         LATC |= (1 << 0);  
         break;  
       case (2):  
         LATC |= (1 << 1);  
         LEDS_backward = 1;  
         break;  
     }  
   }  
     else if (LEDS_backward == 1) {  
     switch (LEDS_index) {  
       case (0):  
         LATC |= (1 << 3);  
         break;  
       case (1):  
         LATC |= (1 << 1);  
         break;  
       case (2):  
         LATC |= (1 << 0);  
         LEDS_backward = 0;  
         break;  
     }  
   }  
   IFS0 = 0x0000;  
   return;  
 }  
 int main() {  
   extern volatile int LEDS_backward;  
   extern volatile int LEDS_index;  
   LEDS_backward = 0;  
   LEDS_index = 0;  
   TRISB = 0x00;  
   PORTB = 0x00;  
   TRISC = 0x00;  
   PORTC = 0xff;  
   IFS0 = 0x0000;  
   IEC0 = 0x0008;  
   T1CON = 0x8010;  
   TMR1 = 0x0000;  
   while (1) {  
   }  
   return 0;  
 }