Low Cost PCB's Low Cost Components

Author Topic: EEVblog #b10000000000 - 1K Micro Magic  (Read 1888 times)

0 Members and 1 Guest are viewing this topic.

Online EEVblog

  • Administrator
  • *****
  • Posts: 24378
  • Country: au
    • EEVblog
EEVblog #b10000000000 - 1K Micro Magic
« on: September 19, 2017, 09:32:09 AM »
What can you fit in 1K words of microcontroller program memory?
Dave takes a look at two old projects of his published in Electronics Australia magazine using a PIC 16F84 with 1K of program memory.
Will the assembly language code still compile first go in MPLABX after 18 years?

Assembler Code Download: http://www.eevblog.com/files/VCG-VTG-AssemblerCode.zip

 
The following users thanked this post: SeanB, alexanderbrevig, jonovid

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 521
  • Country: no
  • Musician, programmer and EE hobbyist
    • alexanderbrevig.com
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #1 on: September 19, 2017, 10:00:51 AM »
Nice!

Offline wilfred

  • Super Contributor
  • ***
  • Posts: 4413
  • Country: au
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #2 on: September 19, 2017, 10:18:53 AM »
"Literally everyone unsubscribed. " I can confirm I did. That was so sad. If it was a horse it would be like using the second cartridge.

I still want to see an interview with JR.
 

Offline Tek_TDS220

  • Regular Contributor
  • *
  • Posts: 58
  • Country: 00
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #3 on: September 19, 2017, 11:32:39 AM »
Very entertaining.  Yes, Microchip supports their parts for a long time.  MPLAB X is huge and takes a long time to startup, but it is extremely capable.  There are people who complain on the Microchip forums, but I like MPLAB X a lot.  It's the main reason I use their parts.  By the way, you can turn off the specific 'bank' warnings if you want.

I've written several complete projects in less than 1k words in assembler, but it was a long time ago.  I did a 50 MHz frequency counter, for example.  The toughest part of that project was building a stable, high-gain, broadband preamp with input protection.  The code was easy. I still do some assembler, but only for time-sensitive loops.  Programs written in high level languages are much easier to decipher after 10 years.
 

Online jaromir

  • Regular Contributor
  • *
  • Posts: 95
  • Country: sk
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #4 on: September 19, 2017, 05:37:20 PM »
Few months ago I completed project to fit into 1kB of code (not 1023 words, but 1023 bytes) and entered it into 1kB challenge ran by Hackaday
https://hackaday.io/project/18445-brainfcktor
it has very spartan user interface, but you can actually enter and run program written in Brainfuck, as well as observe its results. The most challenging part was cramming bitmaps for letters/numbers/symbols into the 1k, so I had to make some awkward bit shuffling here and there https://hackaday.io/project/18445-brainfcktor/log/50032-new-start-character-generator-tables-in-144-bytes but at the end I managed to cram everything few bytes under 1024 limit.

This project won grand prize in the project https://hackaday.com/2017/01/13/1-kb-challenge-and-the-winners-are/
My hobby projects: https://hackaday.io/jaromir ----------- http://jaromir.xf.cz/
 

Offline HwAoRrDk

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: gb
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #5 on: September 19, 2017, 05:42:01 PM »
Did a project a few months ago (nothing exciting) with an ATtiny13A where I used 1018 bytes of the 1KB flash memory. Wasn't expecting to cut it so close, but, you know... self-inflicted feature creep. :)

Happened to find a bug in the program a few weeks later, and had to add another line of code - 1020 bytes! Hopefully no more will be found...
« Last Edit: September 19, 2017, 05:43:44 PM by HwAoRrDk »
 

Online Halcyon

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: au
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #6 on: September 19, 2017, 06:14:25 PM »
Ahh the good old Ozemail member's webpages. For those wondering what Dave's webpage (silk-screened onto the PCB looked like): www.ozemail.com.au/~dljones
 
The following users thanked this post: alexanderbrevig

Offline JTR

  • Regular Contributor
  • *
  • Posts: 100
  • Country: au
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #7 on: September 19, 2017, 06:20:22 PM »
"Literally everyone unsubscribed. " I can confirm I did. That was so sad. If it was a horse it would be like using the second cartridge.

I still want to see an interview with JR.

Oh, that nearly made me cry. Hopefully I'll be back.  ;D
 

Offline ggchab

  • Regular Contributor
  • *
  • Posts: 74
  • Country: be
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #8 on: September 19, 2017, 06:41:09 PM »
Nice video  :)
I made a metronome with a PIC16F84, 3 seven segments displays, 3 keys and a speaker. It still works. Only 12 words of program memory and 2 bytes of RAM left ! It has 64 bytes of data EEPROM where working values are saved.
Really wondering if this could have been written in C.
 

Online EEVblog

  • Administrator
  • *****
  • Posts: 24378
  • Country: au
    • EEVblog
 

Offline jonovid

  • Frequent Contributor
  • **
  • Posts: 494
  • Country: au
    • JONOVID
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #10 on: September 19, 2017, 11:04:59 PM »
Video genlock was the holy grail of DIY video in the 80s IMO. its the electronics genius that got his old C64  :-// but most-likly Amiga to put text on to his VHS home video  :-+  we all had a go, at it,  |O at one time or another  :-/O in the 80s.

"Literally everyone unsubscribed. " I can confirm I did. That was so sad. If it was a horse it would be like using the second cartridge.

I still want to see an interview with JR.
sad day when EA lost it! -so now I get to know why EA disappeared. :'(
Hobby of evil genius      basic knowledge of electronics
 

Offline Barny

  • Regular Contributor
  • *
  • Posts: 219
  • Country: at
  • I'm from Austria, not Australia ;)
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #11 on: September 19, 2017, 11:16:32 PM »
The funny thing is, that I am listening to TheAmpHour episode 236, where Dave is mentioning the voice recognition chip video he did.
And this chip is a 1K microcontroller.

The funny hing is, that in this episode Dave says that he want to run a 1K contest.

(I'm a bad programmer, but it would be fun to see the projects)
 

Offline NivagSwerdna

  • Frequent Contributor
  • **
  • Posts: 933
  • Country: gb
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #12 on: September 19, 2017, 11:27:01 PM »
Very nice project. 

It's really simple STV5730A and a small PIC but the project execution is nice....  nice PCB with informative silk screen, nice box, documented to the level of a published article.

Most of my projects never quite get finished, certainly not to that level of detail  :)
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 3342
  • Country: de
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #13 on: September 19, 2017, 11:39:47 PM »
For ASM code 1 K words is already a relatively long program. I guess all my ASM programs were below 1 K, though there is one (a frequency counter) where I reached the 1 K HW limit before all planed feature were complete - so RS232 HW but no SW.
 

Offline HwAoRrDk

  • Frequent Contributor
  • **
  • Posts: 315
  • Country: gb
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #14 on: September 20, 2017, 12:00:01 AM »
I wonder if the reason why that ST video character chip got discontinued was because the early '00s was when sales of VCRs and other analogue consumer video equipment started to decline. Products with OSDs like cable and satellite boxes were going all-digital, with more sophisticated hardware, so there was no demand for such relatively simple chips any more.
 

Offline ryanmoore

  • Contributor
  • Posts: 20
  • Country: gb
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #15 on: September 20, 2017, 04:28:40 AM »
By the mid-late 90s most TVs were using all-in-one microcontrollers to control everything - weird niche parts that did everything from decode teletext to handle the IR remote control, including generating the OSD, so there wasn't the need for a separate chip any more.

If you go back 5 years then it was all separate chips - a microcontroller, a teletext decoder, a video switch matrix, an OSD chip, etc...
 

Offline rgunee

  • Newbie
  • Posts: 1
  • Country: se
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #16 on: September 20, 2017, 07:08:01 AM »
Hi Dave
Love that you celibrate episode 400h more than 3E8h!

I always enjoy watching your videos but this episode really hit a nostalgic bit for me as the PIC16C84 really got me started in combining electronics and SW back in the days, especially since I too did a bunch of video projects, like my video games PIC-Pong and PIC-Tetris (published on my homepage and also the "PIC-List" back in 1998) which both generated a video signal in software only using two resistors and of course most of the 1k memory in the PIC  :).

Tetris in action:


Schematic for the game system:


Keep up the good work.
« Last Edit: September 20, 2017, 07:23:04 AM by rgunee »
 
The following users thanked this post: oakkar7

Offline thm_w

  • Frequent Contributor
  • **
  • Posts: 409
  • Country: ca
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #17 on: September 20, 2017, 08:35:15 AM »
I'm sure Dave is just trying to be funny and fit with the theme of the episode, but, an 800MB download for an IDE that supports 20 year old parts is completely reasonable.
Thats less than 5 minutes to download, even on an Australian connection.

Visual studio is over 8GB for the pro edition, Xilinx latest tools are over 20GB and probably don't even support the older devices.
 

Offline niclas@hedhman.org

  • Newbie
  • Posts: 1
  • Country: my
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #18 on: September 20, 2017, 02:57:35 PM »
Gosh, this episode is lighting up memory lane like Las Vegas. See below; PIC processors had a hardware bug in design 1997 and earlier.

This doesn't qualify for 1K project, but I can't wait another 1024 episodes for the 2K opportunity.

In 1997, I built a remote I/O device (two 0-10V analog in, two 0-10V analog out, 8 DS1820 temp sensors, a few digital I/O) around the PIC16C73, which was a monster compared to the very popular PIC16F84. 2kWord and 192 bytes memory, ADC, PWM and even an UART.

On the UART, I had something called EXOline (similar to Modbus) protocol over RS-485, which had up to 240+ bytes packets, so those had to be decoded in-flight (none of that buffering rubbish).
Then the 1-wire protocol, which held the individual 8 device addresses in memory (64bytes). Oh, and I2C (EEPROM with calibration data) and SPI (don't remember for what) interfaces of course, bit banged.
I had to optimize all this quite significantly for, a) not enough stack levels, b) to get under the 2kWord boundary, and c) the 192 bytes available. I recall I had 1 bit free RAM (of course marked "future use") and something like 50 words of program memory left.

But the kicker on that was that I found a hardware bug, and I could point them to exactly what happened and a software work around for chips already in the field. MicroChip engineering was extremely grateful and granted me "volume price for life" and a batch of 100pc 16C73 as a token of appreciation. They let me know later that the bug was fixed and rolled out during 1998.
I also find it remarkable that I and my team found exactly the same problem (UART and Timer interrupt on same clock cycle) in the early 8031 (of (C)1980 design, fixed in (C)1982). The difference was that Intel insisted on that the problem didn't exist and it never existed, even when presented with proof. Just a coincidence that one of us noticed the (C)1980 on the SDK evaluation board and went to exchange it with a (C)1982 and problem gone.
MicroChip clearly wins over Intel in terms of servicing their engineering customers.

What was the bug? If there were two interrupts (I think it was Timer and UART) on the same clock cycle, only one return address would be pushed on the stack, but both interrupt routines would be called.

Software workaround? I don't recall the details of that, but it ended up consuming one stack level (big deal, since we only have 7 stack entries, for both ISR and CALL).
 

Offline Rolo

  • Regular Contributor
  • *
  • Posts: 98
  • Country: nl
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #19 on: September 20, 2017, 04:15:48 PM »
Great video. I also started with pic's. My first project that really went in "production" was a controller for a duct valve in my house. It was triggered by an action in the kitchen (opening the cooker hood), it also knew if the valve had made a full turn by reading a optocoupler.
Great times. It was based on a 16C84 and worked from 2001 until 2009. 
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 5345
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #20 on: September 20, 2017, 04:29:01 PM »
@Niclas,

Huh?

The standard midrange PIC architecture used in the PIC16C73 and PIC16F84, doesn't have vectored interrupts.  If two interrupt sources trigger in the same cycle both interrupt flags should be set.  If any interrupt flag is set, and not masked by the corresponding interrupt enable bit, or the peripheral interrupt enable bit or the global interrupt enable bit (GIE), GIE is cleared to mask further interrupts and the code at the interrupt vector (0x004) is called as if a CALL instruction had been inserted before the next instruction.  The return address stacked is the next instruction.  Execution transfers to the ISR and the application code must poll the interrupt flags to determine which interrupt(s) to service.  Because GIE is cleared the ISR cant be interrupted, (unless the programmer is an idiot and sets GIE in the ISR).  The ISR is then exited by a RETFIE instruction which does the same as a normal RETURN + sets GIE.   If any interrupts are still pending, the next main program instruction address is stacked and the ISR reentered before the next main program instruction is executed, so an unserviced but enabled interrupt will hang the main program (unlike AVRs).

There is no way the bug could be as you describe.  Perhaps 20 years later your memory is a little fuzzy.

There was a well known bug with clearing GIE to disable interrupts. If an interrupt was triggered in the instruction that cleared GIE, the ISR would be entered, and the RETFIE would set GIE again, which meant you had to use the code:
Code: [Select]
di:     bcf   INTCON, GIE ; Disable interrupts
        btfsc INTCON,GIE  ; Did it work?
        goto  di          ; NO, so try again
to actually disable them successfully.

To set everyone's mind at rest, Microchip fixed the GIE bug before the midrange FLASH memory parts so the above code isn't needed for any PIC10/12/16 part with a F in the part number.
 
The following users thanked this post: wilfred

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 9999
  • Country: gb
    • Mike's Electric Stuff
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #21 on: September 20, 2017, 07:25:12 PM »
For ASM code 1 K words is already a relatively long program. I guess all my ASM programs were below 1 K, though there is one (a frequency counter) where I reached the 1 K HW limit before all planed feature were complete - so RS232 HW but no SW.
Many years ago I did a project on a 16C77  which used pretty much all 8K of ROM and all the RAM  (plus a couple  of registers in unused peripherals) , all in assembler, in a PLCC package that you had to unsolder to update the firmware. That was fun.....

Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 273
  • Country: gb
Re: EEVblog #b10000000000 - 1K Micro Magic
« Reply #22 on: September 20, 2017, 07:52:43 PM »
Thumbs up Dave, Back in the day (2000's ) My .asm was not as well constructed , but it worked... I even had a PIC16F84  Greenhouse watering timer project published in EPE mag here in the old country. still occasionally do .asm  but i am well into PIC24 and MPLABX now . (well past my 3 score years and ten !)   
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf