Jump to content
Sign in to follow this  
maelli01

Ultimate gibberish machine from the Art of Electronics

Recommended Posts

In the Horowitz/Hill Art of Electronics, third edition, design practices with discrete 74HCxxx, FPGA and Microprocessor are compared and discussed.

As an example, the ultimate gibberish machine is described, a circuit that sends out a succession of pseudorandom bytes, as standard RS232 serial data, with 2 selectable speeds, 9600 / 1200 baud. 

 

Independent of the processor type, the implementation with a small micro and program it in C looks like the clear winner here, smallest engineering effort, lowest hardware effort (have to admit that I do not have the faintest idea about FPGA.)

 

The example in the book used some 8051ish device, so I was wondering on how this would look like on a MSP430/launchpad

 

See my code below, based on the 8051 C code from the book, but adapted to run as low power as possible (LPM3)

The power consuption of this thing is: 40uA at 9600baud, 6uA at 1200baud   :)

//MSP430G2553LP implementation of the ultimate gibberish machine
//from the art of electronics, third edition, Chapter 11.3.
//Produces a pseudorandom datastream at 9600/1200baud, 8n1

//P1.0 output, sync, processor busy
//P1.2 output, serial pseudorandom data
//P1.3 input,  data rate select (button,at start)
//32768Hz crystal is required

//2016-10-23 maelli01

#include <msp430.h>

unsigned char d,c,b,a=1;

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR = ~BIT3; P1REN=BIT3; P1OUT=BIT3;    // all output, except button
  P1SEL = BIT2; P1SEL2=BIT2;                // P1.2=TXD
  P2REN = 0x3F;				    // all unused pins resistor enable
  P3REN = 0xFF;			            // all unused pins resistor enable
  UCA0CTL1 |= UCSSEL_1;                     // CLK = ACLK
  if(P1IN&8){				    // button not pressed: 9600 baud
	  UCA0BR0 = 3;                      // 32768Hz/9600 = 3.41
 	  UCA0MCTL = UCBRS1 + UCBRS0;       // Modulation UCBRSx = 3
  }
  else{					    // button pressed: 1200 baud
	  UCA0BR0 = 27;                     // 32768Hz/1200 = 27.3
	  UCA0MCTL = UCBRS1;                // Modulation UCBRSx = 2
  }
  UCA0BR1 = 0x00;
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0TXIE;                          // Enable USCI_A0 TX interrupt
  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 w/ int
}

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void){
  P1OUT |=1;
  UCA0TXBUF=((d<<1)|(c>>7))^c;              // 32 bit pseudorandom generator
  d=c; c=b; b=a; a=UCA0TXBUF;
  P1OUT &=~1;
}

post-37272-0-78536700-1477237637_thumb.png

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...