PIC a/d puzzler

It's convenient when 8 bits of resolution is enough.

Try this one, you can shorten as necessary. It's for a 16F pic, but it should work with minor mods.

binX, binU, binH and binL are the 32 bit input field. temp is a temp field. The output fields are obvious.

; ; binary_to_bcd - convert 32bit unsigned binary value to 10 digits of BCD ;

binary_to_bcd

bcf STATUS, 0 ; clear the carry bit movlw .32 movwf count clrf billions_and_hundredmillions clrf tenmillions_and_millions clrf hundredthousands_and_tenthousands clrf thousands_and_hundreds clrf tens_and_ones loop32 rlf binL, F rlf binH, F rlf binU, F rlf binX, F rlf tens_and_ones, F rlf thousands_and_hundreds, F rlf hundredthousands_and_tenthousands, F rlf tenmillions_and_millions, F rlf billions_and_hundredmillions, F ; decfsz count, F goto adjDEC RETLW 0 ; adjDEC bcf STATUS, IRP

movlw tens_and_ones movwf FSR call adjBCD ; movlw thousands_and_hundreds movwf FSR call adjBCD ; movlw hundredthousands_and_tenthousands movwf FSR call adjBCD

movlw tenmillions_and_millions movwf FSR call adjBCD

movlw billions_and_hundredmillions movwf FSR call adjBCD ; goto loop32 ; adjBCD movlw 3 addwf INDF,W movwf temp btfsc temp,3 ; test if result > 7 movwf INDF movlw 0x30 addwf INDF,W movwf temp btfsc temp,7 ; test if result > 7 movwf INDF ; save as MSD RETLW 0

It may not cause this, but it can lead to other interesting "results".

Reply to
Anthony Fremont
Loading thread data ...

I don't use an external clock; timing accuracy and drift are not an issue. It just needs to run and take readings.

These are the clock-related settings (that I know of): config CPUDIV = OSC1_PLL2 config PLLDIV = 12 config PBADEN = ON config LPT1OSC = OFF config FOSC = INTOSCIO_EC

You might also be right; I'll have to check whether bank usage is coming into play.

[snip other good stuff]
Reply to
Randy Day

It turns out it was the conversion routine, as some of you suggested.

I was testing the status register twice in each loop, and overlooked the fact that the INCF in between them was changing bits.

Thanks to all who replied; there's *no way* I would have got it without your input.

So, John, are we still both confused about the clock configuration on this beast? I still don't know for sure what frequency I'm telling it to run at...

Randy

Reply to
Randy Day

I understand this last line to mean that the processor clock is derived from the internal 8 MHz clock generator, but the USB clock comes in through the OSC1 pin EC= external clock source for USB).

But you also have to select OSCON bite 6-4 to set the division ration between the 8 MHz oscillator and the processor clock. Have you configured this frequency division?

I am not sure (the clock system in this thing reminds me of constituency politics, not engineering), but I think that the PLL only affects the multiplication of the external clock input to produce the USB clock, not Fosc, the clock for the processor and periperals.

We may finally find out what your Taq is. ;-)

Reply to
John Popelish

You can always code a tight loop driving a digital output into alternating states and measure the output frequency, then work out how many clocks the program needs to produce a cycle. Multiply the output frequency times the clocks per cycle, and you get the clock frequency.

Reply to
John Popelish
[snip]

Holy crap! I read up on OSCCON, tried setting it, and now (I'm assuming) it's running too fast for my display!

I'll have to redo my timing stuff to see if that's it.

Reply to
Randy Day

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.