• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Re-visiting the PIC

    Blog entry posted in 'Uncategorised', July 19, 2012.

    So, I started to look again at the binary to bcd conversion routine, had a go at writing my own from scratch (or as near scratch as I could, considering I've included one in my first program), and studied the one given to me by Mike, K8LH, which is infinitely better.

    My original approach, to clock the output from the ADC directly into the bcd conversion routine, actually won't work, because the ADC's output needs to be scaled. Well, it will work, but the reading will be wrong. Rather than try to do floating point arithmetic, I opted to multiply by (15625 + 262144) then divide by 524288. This way I use left shifts and addition for the multiply, then right shifts to divide. The 262144 is to offset the error caused by throwing away the floating part of the calculation. This actually resolves a count of 10 on the ADC. Using a multiplier of (156250 + 262144) gives a resolution of 1 count.

    So the reading will have to be counted into some registers, scaled, then converted to bcd.

    I discovered that there isn't much need for the microcontroller to know what function is selected - it affects the position of the d.p. and not much else. I suspect I'll find more use for it as time goes on.

    After going through the pins needed for the display a few times and looking at exactly what they are supposed to do, I realised I can encode the sign and other special characters into the serial bcd stream and gate them off, have an "always on" sign and just blank it for positive readings, saving some i/o. But after some more scribbling I realised I've actually got enough pins to output 7 segments from the microcontroller anyway.

    So, time to start re-writing.

    Still can't get my head around mplabx. Don't get all this C headers and crap. What's that all about then? Don't understand. Don't like things I don't understand. Grrrrrrrr.

    Comments
 

EE World Online Articles

Loading

 
Top