Tag: pic

I got me a bunch of 7seg LED boards from sureelectronics and I expected them to have some “smarts” on them even as they are fairly cheap. Now, the nasty buggers come without any documentation so it took me a bit to figure out how they are connected and how to drive them.

The modules take 12V and 3 inputs, data, clock and something called DIMM. After bit of checking out the schematic it looks like this:

DE-DP22811 2.3" Two Digits 7-Segment LED Information Board MTO schematic

DE-DP22811 2.3" Two Digits 7-Segment LED Information Board MTO schematic

So, the data line goes directly into data input of the 74HC164 (it is one from NXP on the boards I have) shift register, clock for some reason goes trough a double NAND and finally the DIMM goes also trough double NAND and then controls the current trough modules. When DIMM line is high the 7segment led will be dimmed (almost off).

For some reason, who ever designed this board decided to go with 74HC164 instead with 74HC595 and to add DIMM instead of latch… donno what to say, I really like latch more then this dimm solution, but it works like this too..

Note that schematic is just something I drawn (at 6am so don’t be too rush on me, I know that according to this schematic dimm low would dimm the segments but it is really not important). What is not on the schematic is “irrelevant” for driving the bastard, the 7seg’s are not connected directly too 12V and to shift register but shift register drives the ULN2003 that then sinks the current for the 7segs, of course there are some current limiting resistors and also a 5V regulator for the onboard electronics. There is also some circuitry (4 transistors plus some extra passive components) that gets the dimm line high dimms the segments but it is too early/late and I really need sleep and is not important really “how” it works… important is “what it does” and how to control it.

Here is also a sample code (for pic16F690 – chosen this one as I had it on the table from some manual I made for a friend yesterday) :

#include <16F690.h>
#device adc=8
#case
#use fast_io(C)

#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOPROTECT
#FUSES NOBROWNOUT
#FUSES NOMCLR
#FUSES NOCPD
#FUSES NOPUT
#FUSES NOIESO
#FUSES NOFCMEN  

#use delay(clock=8000000)

//define data, clock and blank pin
#define DATAPIN PIN_C0
#define CLOCKPIN PIN_C1
#define BLANKPIN PIN_C2

//define clock delay routine. the display comes with
//NXP 74HC164 so minimal pulse width at 5V is 24ns
//a single nop takes much longer at 8MHz clock (500ns)
#define clkdelay() #asm ASIS nop #endasm

//   0
// 5   1
//   6
// 4   2
//   3    7

unsigned int8 digit[10] = {
  0x3F,
  0x06,
  0x5B,
  0x4F,
  0x66,
  0x6D,
  0x7D,
  0x07,
  0x7F,
  0x6F
};

void clean(){
  int8 i;
  output_low(DATAPIN);
  for(i=0;i<100;i++){
    output_high(CLOCKPIN);
    clkdelay();
    output_low(CLOCKPIN);
    clkdelay();
  }
}

void sendDigit(signed int8 d){
  int8 x;

  if (d<0){
    output_high(DATAPIN);
    d = -d;
  }else{
    output_low(DATAPIN);
  }
  if (d > 9) d=0;
  x = digit[d];

  //send DP
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x40){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x20){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x10){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x08){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x04){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x02){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);

  if (x & 0x01){
     output_high(DATAPIN);
  } else {
     output_low(DATAPIN);
  }
  output_high(CLOCKPIN);
  clkdelay();
  output_low(CLOCKPIN);
}

void main()
{
   int16 i;
   int8 a,b,c,d;

   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_oscillator(OSC_8MHZ);

   set_tris_c(0);
   clean();   

   while(1){

     //single module
     for (i=0;i<100;i++){
       output_high(BLANKPIN);
       sendDigit(i%10);
       sendDigit(i/10);
       output_low(BLANKPIN);
       delay_ms(100);
     }

     for (i=0;i<10000;i++){
       a = i%10;
       b = (i/10)%10;
       c = (i/100)%10;
       d = (i/1000)%10;
       output_high(BLANKPIN);
       sendDigit(a);
       sendDigit(b);
       sendDigit(c);
       sendDigit(d);
       output_low(BLANKPIN);
       delay_ms(100);
     }
   }
}

I hope you use it well :)

Another interesting thing is the power consumption. The two modules take up to 750mA when powered from 12V. The brightness is great but so is the power consumption. Depending on how many segments are shown (600mA exactly with 12 source and 8584 on display)  the consumption goes down (for e.g. for 1413 on display the usage is 360mA). What I found is that when I power it from 9V the brightness is still great (almost as strong as with 12V) but the power consumption almost drops 50% so the same settings only 9V the power draw when 8584 is on display is 330mA (when 1413 is on display the power usage is 200mA). As you are “dimming” the display while updating it it the current draw drops a bit but so does the brightness. After some testing I believe 9V is perfect psu for this board.

Tags: , ,

Open Source CDC USB Stack for PIC

Community gathered around Dangerous Prototypes site decided that it is time we have a decent USB stack for Microchip PIC micro controllers that has usable open source licence. The USB stack provided by Microchip as part of the MAL is great, works perfectly but has a huge flaw, and that is, it does not allow you to properly use it with open source projects. When you have your open source project that uses MAL you share your project on some public CVS/SVN/BZR/GIT.. repository but you have to remove all MAL files and add a readme to explain to users how to download mal, how to install it, where to put it etc … and it all makes a huge mess and is very unreliable. The worse part is that Microchip from time to time decides to make incompatible changes in the MAL so that your old code don’t work with new version of MAL. Of course Microchip don’t keep archive of old MAL releases so if you find open source project that is not using up to date version of MAL you can only cry as there’s no way you can get the same MAL developer of the project uses….

This brings us to the new open source stack being developed by the Dangerous Prototype community, namely Honken and JTR with help from everyone else. You can follow the progress on the Dangerous Prototype forum.

At the moment USB stack support only CDC, but hopefully soon we will have HID and some other profiles too. The latest version of CDC stack in form of simple echo application is available on the forum. I modified it a bit to work with 18F2550 and hid bootloader (this one is microchip’s) and you can find hid bootloader in my previous post where you can find bot HEX of the bootloader and the source for linux app to use it. The modified project for MPLAB.X that creates simple USB CDC device that echo back what you send it can be downloaded from here.

The example showing 18F2550 enumerate:

Mar 15 06:45:15 luckey kernel: [ 6694.873125] usb 5-2: new full speed USB device using uhci_hcd and address 8
Mar 15 06:45:15 luckey kernel: [ 6695.053649] usb 5-2: New USB device found, idVendor=04d8, idProduct=000a
Mar 15 06:45:15 luckey kernel: [ 6695.053653] usb 5-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar 15 06:45:15 luckey kernel: [ 6695.053655] usb 5-2: Product: CDC Test
Mar 15 06:45:15 luckey kernel: [ 6695.053657] usb 5-2: Manufacturer: Dangerous Prototypes
Mar 15 06:45:15 luckey kernel: [ 6695.053659] usb 5-2: SerialNumber: 00000001
Mar 15 06:45:15 luckey kernel: [ 6695.055690] cdc_acm 5-2:1.0: This device cannot do calls on its own. It is not a modem.
Mar 15 06:45:15 luckey kernel: [ 6695.055706] cdc_acm 5-2:1.0: ttyACM0: USB ACM device

Tags: , , ,

Microchip Application Libraries include pretty good HID Bootloader made by Microchip developers. It is fairly small and works even on small devices like 18F2550. Microchip also (inside the MAL) provides the application to upload HEX files to the microcontroller using bootloader. This is all nice and all works good, except that if you don’t have windows there is not much you can do with the hid bootloader as there is no linux version.

As I use Linux only (64bit Fedora Linux – currently v10 and v14 are used in my home) I decided to rewrite the bootloader code to work on Linux. I managed to get it working inside few hours. It is just a small shell application that you run passing it single parameter (your hex file), it will erase mcu and upload hex. It uses libusb-1.0 library and the project is using CMAKE (kdevelop4 is used as IDE).

You can download source code (and linux 64bit binary) of desktop application to upload firmware using hid bootloader here

[arhimed@luckey build]$ ./hid_bootloader ../cdc.hex
nasao
Family: PIC18
ERASED
PROGRAMMED
[arhimed@luckey build]$

If you use PIC18F2550 here you can download HEX file with the boot loader firmware. Note that I changed default behaviour of the boot loader so now you enter boot loader if PGC and PGD are connected instead by tying B4 to the Vss. I did this because all my boards have ICSP connector on them so it is easier to add a jumper over PGC/PGD then to waste a B4 pin to boot loader.

Tags: , , ,

IR Pločica

IR Pločica

IR Pločica

IR Pločica

IR pločice nam trebaju dve kako bi mogli da komuniciramo između dve glavne pločice. Sastoji se od IR prijemnika (R1, R2, C1 i prijemnoj IR demodulatora), i IR predajnika (Q1, R3, R4, R5,C2, IR1, i IR2). Ako želite jednosmernu komunikaciju možete napraviti jednu pločicu sa prijemnikom i jednu sa predajnikom.

Prijemni demodulator demodulise 38KHz signal (ovaj na Nigelovoj šemi, postoje i demodulatori za 40KHz i na 36KHz mada je 38KHz standard), R2 i C1 su tu za dekapling / stabilizaciju, i R1 je pull-up otpornik posto je izlaz open-collector.

Predajnik je obican digitalni tranzistorski prekidač, kada RB1 ode na 1 to otvori tranzistor i pusti struju kroz IR ledare. R5 limitira struju kroz IR ledare. Struja kroz ledare je prilicno velika tako da je bitno da se IR ledare pulsiraju i da se ne ostave “upaljene” posto bi ih konstantna struja ove magnitute spržila. C2 služi da isporuči potrebne pikove u zahtevima za strujom bez da to utiče na glavni 5V napon.

IR plocica - gotova - gore

IR plocica - gotova - gore

IR plocica - gotova - dole

IR plocica - gotova - dole

Tags: , , , , , ,

Joystick Pločica

Joystick Pločica

Joystick Pločica

Joystick Pločica

Joystick pločica se koristi da konektujete standardni PC joystick. Koristi 4 pina jednog porta i koristi jednostavni princip punjenja kondenzatora da pročita analognu vrenost otpora ose joystick-a. Šema je jednostavna, R1 i R2 su pull-up otpornici za dva tastera joystick-a (koji spajaju ili pin 2 ili pin 7 15 pinskog D konektora na GND). Analogni ulazi idu su na pinovima 3 i 6, i čine ih 100K potenciometri do pina 1 (5V). Analogne kontrole idu kroz R3 ili R4, i oni služe da setuju minimalni otpor (2.2K) kada je joystick kontrola na minimumu. Struja kroz ove otpornike puni C2 ili C1 i vreme pražnjenja zavisi od potenciomentra (položaja) u joystick-u + R3 (ili R4). Da bi pročitali vrednosti mi ispraznimo kondenzator, resetujemo pin na ulaz i cekamo da se kondenzator napuni dovoljno da na ulazu imamo 1; dok to čekamo merimo vreme 16bitnim brojačem koji nam daje vrednost baziranu na poziciji joystick-a.

Joystick plocica - gotova - gore

Joystick plocica - gotova - gore

Joystick plocica - gotova - dole

Joystick plocica - gotova - dole

Tags: , , , , , ,

Pločica sa tasterima

Pločica sa tasterima

Plocica sa tasterima

Plocica sa tasterima

Ova pločica se sastoji od 4 tastera konektovana na gornja 4 pina jednog porta i 4 LEDare konektovane na donja 4 pina istog porta. Tasteri su spojeni na gornja 4 pina posto RA5 može da bude samo input a RA4 je open-collector izlaz. Ostali pinovi su “standardni IO pinovi

Plocica sa tasterima - gotova - gore

Plocica sa tasterima - gotova - gore

Plocica sa tasterima - gotova - dole

Plocica sa tasterima - gotova - dole

Tags: , , , , ,

LED pločica

LED Ploca

LED Ploca

Ovo je LED Ploča, čini je jednostavno 8 LEDara okacenih na 8 pinova jednog porta. Ova ploča je odlična za proveru stanja porta, za jednostavne vežbe setovanja stanja porta, za prikazivanje vrednosti na portu i slično. Može biti okačena na bilo koji port glavne ploče.

LED ploca

LED ploca - gotova - gore

LED ploca - gotova - dole

LED ploca - gotova - dole

Tags: , , , ,

Glavna ploča 3

Glavna Ploca 3

Glavna Ploca 3

Ovo je šema treće (i za sada poslednje) glavne ploče potrebne za tutorijale, sastoji se od PIC16F877 mikrokontrolera, 7805 regulatora napona, 20MHz kristala, 6 kondenzatora, pet desetpinskih konektora. Svaki od pet desetpinskih konektora je spojen identično kao i na prethodne dve ploče sa GND levo i 5V desno.

U osnovi slična ploči sa 16F628 tutorial board, ali sa dodacima – kako PIC16F877 nema interni oscilator, morali smo dodati kristal. Nigel je odabrao kristal od 20MHz

Glavna Ploca 3 - gotova - gore

Glavna Ploca 3 - gotova - gore

Glavna Ploca 3 - gotova - dole

Glavna Ploca 3 - gotova - dole

Tags: , , , ,

Glavna ploča 2

Glavna Ploca 2

Glavna Ploca 2

Ovo je šema kola druge glavne ploče potrebne za tutorijale. Sastoji se od PIC16F876 mikrokontrolera, 7805 regulatora napona, 20MHz kristalal, 5 kondenzatora, tri desetopinska konektora. Svaki od tri desetopinska konektora se vezuje isto kao i na glavnoj ploci1 sa GND sa leve i 5V sa desne strane ostavljajuci mogućnost kačenja dodatnih pločica na različite konektore.

Ova ploča je vrlo slična glavnoj ploči1 samo sa dodatnim “stvarima”. Pošto 16F876 nema interni oscilator morali smo na ovu ploču da stavimo kristal.

Glavna Ploca 2 - gotova - gore

Glavna Ploca 2 - gotova - gore

Glavna Ploca 2 - gotova - dole

Glavna Ploca 2 - gotova - dole

Tags: , , , ,

Glavna ploča

Glavna Ploca

Glavna Ploca

Ovo je šema glavne ploče za rad sa tutorijalima. Sastoji se od PIC16F628 mikrokontrolera, 7805 regulatora napona, 3 kondenzatora, 3 desetopinska konektora i 2 test konektora ka GND-u. Opciono moze da ima LED, otpornik i 2 džampera. Svaki od tri desetopinskih konektora se vezuje identinčno, GND levo, 5V desno – na ovaj način mozemo spajati istu eksternu ploču na različite portove i da pratimo razlike. Kondenzatori C1 i C2 služe da bi 7805 radio stabilno (posto 7805 ima tendenciju da osciluje bez njih) a C3 je dekapling kondenzator potreban mikrokontroleru. Džamperi J1 i J2 omogućavaju LED da bude konektovana na 5V kao “indikator napona” ili na RB7 te da se može kontrolisati sa mikrokontrolera što daje mogućnost da već sa ovom pločom možemo napisati prvi program. Ni pod kojim uslovima ne vezujte i J1 i J2 u isto vreme posto to daje mogućnost da spržite mikro kontroler.

Sastavljena plocica

Sastavljena plocica

Sastavljena plocica - donja strana

Sastavljena plocica - donja strana

Tags: , , , ,
« Previous posts Back to top