CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how do i simulate an 8 bit adder

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
johnmarti42



Joined: 21 Jan 2018
Posts: 3

View user's profile Send private message

how do i simulate an 8 bit adder
PostPosted: Sun Jan 21, 2018 11:31 pm     Reply with quote

I was asked to develop an 8 bit adder with 2 inputs and 1 output applying the carry number. I am using the pic 18f4550.
Ttelmah



Joined: 11 Mar 2010
Posts: 19559

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 1:48 am     Reply with quote

Just add.....

On that chip, it is slightly 'awkward', since you don't have three full 8bit ports available (you need two a full 8 bit port for the inputs, one for 8 bits of output, and one extra bit for the carry , and potentially a clock to say 'do the operation'). It is possible to do it with mixes of bits, but adds latency either on the input or output. Any of the similar sized 'non USB' PIC's would be better since then you would have port C. On the USB chip you lose the C3 line for Vusb, and C4/C5 are input only.

Sequence is simply wait looping for the clock line. Then immediately read the first 8 bit input into the low byte of a 16bit variable (with the top byte already clear), then just add the byte from the other input. Since you have the first byte in a 16bit variable, you use 16bit maths and get a 16bit result On this chip I'd read the inputs on Port D & Port B, and output the result on Port A (6 bits) and Port E (3 bits). So E2 would be the 'carry'. Use perhaps C0 as the trigger input.
However it does seem a daft thing to be doing. A pair of CD74CD283 chips costs less than 1/5 the price of the PIC, and will draw less power, and do the whole thing perhaps 50* faster......
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 4:54 am     Reply with quote

Ttelmah wrote:
However it does seem a daft thing to be doing.


Well yes, from a practical, "useful" point of view its daft, and a total waste of resources. From a learning/training point of view it's probably not so daft.

So, on the assumption this is an exercise, and I suspect it's what your tutor/teacher/whoever asked you to do it is looking for, I suggest doing it the old-fashioned way as a serial adder. Note that I'm not providing any code; that's for you to do; I'm just describing what need to be done. To do this you need look up what a single bit full adder does, make simple code for it (and it is very simple), then put it in a loop that repeats it eight times. If you let the loop run continuously then you don't need an external clock (the loop is the clock).

All you then need to do is sort out the conections/io pins as Ttelmah suggests. This will, roughly, simulate how most early valve-based computers did it, and shows how relatively complex functions can be built up from much simpler ones. The code is trivial, getting the inputs and outputs on the right pins probably being the most complicated bit.


Last edited by RF_Developer on Mon Jan 22, 2018 5:07 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19559

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 5:04 am     Reply with quote

Not just valve based computers.
I build serial adders up using discrete transistors, back before the 74 series existed....

What does seem particularly daft to me is the number of people using the 4550 PIC, when for general use, other chips are far better....
temtronic



Joined: 01 Jul 2010
Posts: 9249
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 22, 2018 6:59 am     Reply with quote

The 4550 was one of the first to have builtin USB and on the surface that sounds good...after all PCs don't have 25 pin comports any more, sigh.
Yes, I bought a tube of them,still have most collecting dust.
Once you see the resources disappear (USB driver takes 1/4-1/3 codespace, USB pins are dedicated) then buy USB connector and a few other parts it isn't the 'Great PIC' we thought it would be. While in high volume, production runs, a PIC with USB might be cheaper, a simple TTL<>USB module for $1 works better, overall. No USB driver needed,any 2 pins can be 'USB' and well you need the connector and parts anyway. Any PIC can have USB.
I'm pretty sure a lot of profs migrated from the venerable 16F877 to the 4550 hoping their course and code could be used with minimal hassle.
I consider the 4550 a 'transitional' PIC. These days I'm 'stuck in a rut' with the 18F46K22. I'm sure there's newer PICs, bigger, better, but at almost 65 I'm comfortable with it.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group