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

Fast ADC for 16F PIC needed

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



Joined: 24 Sep 2006
Posts: 265

View user's profile Send private message AIM Address

Fast ADC for 16F PIC needed
PostPosted: Mon Feb 24, 2025 11:10 am     Reply with quote

Can someone suggest a PIC (with pins, no surface mount) that has a fast ADC conversion time in the order of 10 uSec. I would prefer 16Fxxx.
Surface mount is not out of the question but more difficult for me.

I might do better to connect an external ADC. Any suggestions.

The project is a display for a Heathkit Curve Tracer that uses variable line voltage (the same as the old Tektronix Curve Tracers do) for the DUT. I only need the first quadrant (4.17 mSec for 60 Hz). The power transformer introduces slight distortion at the peak as the capacitors are charged. This signal is the X drive and the device current is the Y drive of an X-Y display.

To get 512 points the ADC conversion time must be less than 0.004/512 = 7.8 uS. I don't need the flat part of the sine wave.

Switching between two ADC channels on the same PIC seems like an impossible task for this kind of speed. Since one of the signals I need to digitize is 60 Hz line I was thinking of just generating the data points mathematically and avoiding the need for two ADCs. I would need to know the peak voltage which could be from 1v to 200 volts and I think I could live with 10 bits resolution. This only needs one measurement at the start of the curve acquisition. I have tapped into other points of the Heathkit to sense switch settings. Any comments or suggestions?

I will be using the PIC as a front end and sending the data to a Raspberry Pi via I2C for display. I'm learning Python and need to get the I2C working on the Pi. I'm making progress and have parts of the Python programming working with some graphic displays.

Anyone interested in this project is welcome to join. Email off line.
rovtech



Joined: 24 Sep 2006
Posts: 265

View user's profile Send private message AIM Address

PostPosted: Mon Feb 24, 2025 3:21 pm     Reply with quote

The 16F1938 data sheet says to use fosc/16 for a 16 MHz clock but the .h file has ADC_CLOCK_DIV_16
I assume these are the same thing and refer to the PIC clock and not the ADC clock.
Is it OK to keep calling read_adc() without adc_done() or a delay?
Code:
for(i=0;i<114;i++)            // 114 points
     sweep[i]=read_adc();

I assume the reference defaults to 5v, the clock defaults to fosc, and I don't have to set them?
The above loop takes about 35 uSec per pass which will only give me about 114 points in 4 mSec.
I am going to run short on RAM with this PIC, especially if I try to use 10 bits.
temtronic



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

View user's profile Send private message

PostPosted: Mon Feb 24, 2025 4:06 pm     Reply with quote

Saw this earlier and been pondering it while carving channels for the snowmelt to go AWAY from my house....

1) do you really need 10 bits ? If not 8 is a "TAD' faster and less RAM needed. Also faster to access and do 'something' with the data.

2) Pick a PIC with lots of memories..... better to have more than 'arrrrrgh 22 bytes short'......

3) HEATHKIT ? man I still have HAM stuff here... and an EICO 'component ' tester with a working 'magic eye'.

4) thanks NOW I feel real old.......
rovtech



Joined: 24 Sep 2006
Posts: 265

View user's profile Send private message AIM Address

PostPosted: Mon Feb 24, 2025 5:55 pm     Reply with quote

I think I need the 10 bits to read the peak voltage (rectifier and capacitor off the "Collector voltage" supply). Then a divider to 5v maximum for 200v.
I might be reading 1 volt or 200 volts so I need enough resolution to get accuracy.
Yes, 8 bits might be enough for the collector current.
I want to get something working first.

The 16F1938 PIC and software takes 35 uS per reading.
Dividing 35 uS into 4 mS for the first quadrant of a sine wave gives 114 samples.
This is not the resolution I would like but just to get something working I tried calculating the Y values for each point.
First I am not going to 90 degrees.
The 90 degree point for 60 Hz is (1/60)/4 or 4.17 mS

We are only going to 4 mS which is 4/4.17 * 90 or 86.4 degrees

Dividing this by 114 gives 0.76 degrees per reading

The peak voltage, Vp, is read first. It is typically between 1 and 200 volts.

The device current at each point is read in a loop, the voltage can be calculated from y=sin x:



Code:
 for(i=0; i<114; i++)          // 114 points, i=0 to 113, increment
          {
              current_x [ i ] = read_adc();  // read the current into Xposition(i)
              voltage_y [ i ] = sin (i * 0.76) * Vp  // store calculated voltage
          }



The calculation for voltage_y can be done later and merged with the x array for plotting on the Raspberry Pi. Vp and imax will have to be sent to the Raspberry Pi first which is not a problem.
Any suggestions for a better PIC?
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