Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Analog configuration
25-07-2011, 03:15 AM,
Analog configuration
Hi everybody, this is my first post here and I'd like to point to some things about the analog.c file of pinguino IDE.

The first one is related to the configuration of the ADC. I think that the ADC is configured wrong wrong in the analog_init() function. In the section 21.3 of the PIC 18F2550 datasheet you can read:

Quote:For correct A/D conversions, the A/D conversion clock (TAD) must be as short as possible but greater than the minimum TAD.

For PICs 18F the minimum TAD is equal to 0.8us and the maximum TAD is equal to 25us. Pinguino is using a 20MHz oscillator feeding the PLL, the system clock is taken from PLL/2, so we get that Fosc=48MHz. You can refer to Table 21-1 to check that for this frequency it should use 64*Tosc; actually pinguino is using 16*Tosc.

Using this value, we get a TAD=1.33us. The PIC needs 2.45us for the acquisition time in normal conditions (Equation 21-3 of the datasheet), so it should configure the acquisition time to be 2*TAD at least. If larger value is used the conversion will take longer to finish, and then lower sampling rate could be achieved. Actually 20*TAD is the value used by the init function.

All this could be fixed just changing line 16 and 20 (on line 30 I don't know why it's configuring this register again, it's redundant) of analog.c for this one:


Also, I think it could be a good idea to add a new definition, function or whatever to select the number of ADC channels. For example, if you only want to use 2 ADC channels, you can use something like #define ADC_CHANNELS 2 and then, in the analog.c file use something like this for 18F2550 (similar to 18F4550):


This way you can use only the first N analog channels and use the rest as normal digital I/O.

I hope this helps.
06-03-2019, 10:17 AM,
RE: Analog configuration
Configuration of the analogue is put forward for the success of the participants. The advancement of the analogue element and best essay marked for the satisfaction of the students. Struggle is moved for the full use of the items for the humans.

Forum Jump:

Users browsing this thread: 1 Guest(s)