Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADC present on custom board but can't be used. #45

Closed
KevWal opened this issue Jul 31, 2022 · 5 comments
Closed

ADC present on custom board but can't be used. #45

KevWal opened this issue Jul 31, 2022 · 5 comments

Comments

@KevWal
Copy link
Contributor

KevWal commented Jul 31, 2022

Currently the code only enables the ADC if the BoardType is designed to have the ADC and Config.DisableADC is False.

This gives no option to enable the ADC for boards that by default don't have it, but it has been added.

Editing misc.c to read:

        // Battery voltage and current, if available
        if (((Config.BoardType == 3) || (Config.BoardType == 4) || (Config.DisableADC)) & (!Config.EnableADCVolt))
        {
                        // Pi Zero - no ADC on the PITS Zero, or manually disabled ADC
        }
        else if ((Config.BoardType == 0) || (Config.EnableADCVolt))
        {
                // Pi A or B.  Only Battery Voltage on the PITS

                sprintf(ExtraFields1, ",%.3f", GPS->BatteryVoltage);
                if (ShowFields) printf(",Volts");
        }
        else
        {
                // Pi A+ or B+ (V1 or V2 or V3).  Full ADC for voltage and current

                sprintf(ExtraFields1, ",%.1f,%.3f", GPS->BatteryVoltage, GPS->BoardCurrent);
                if (ShowFields) printf(",Volts,Current");
        }

and tracker.c to create the thread:

        // DisableADC is used to disable the ADC on boards that should have an ADC (but dont)
        // EnableADCVolt is used to enable the ADC on boards that should not have an ADC (but do)
        if (((Config.BoardType != 3) && (Config.BoardType != 4) && (!Config.DisableADC)) || (Config.EnableADCVolt))
        {
                // Not a zero, so should have ADC on it
                if (I2CADCExists())
                {
                        printf ("V2.4 or later board with I2C ADC\n");

                        if (pthread_create(&ADCThread, NULL, I2CADCLoop, &GPS))
                        {
                                fprintf(stderr, "Error creating ADC thread\n");
                                return 1;
                        }
                }
                else
                {
                        printf ("Older board with SPI ADC\n");

                        if (Config.LoRaDevices[0].InUse)
                        {
                                printf ("Disabling SPI ADC code as LoRa CE0 is enabled!!\n");
                                Config.DisableADC = 1;
                        }
                        else
                        {
                                if (pthread_create(&ADCThread, NULL, ADCLoop, &GPS))
                                {
                                        fprintf(stderr, "Error creating ADC thread\n");
                                        return 1;
                                }
                        }
                }
        }

and tracker.c to read the config:

        // DisableADC is used to disable the ADC on boards that should have an ADC (but dont)
        // EnableADCVolt is used to enable the ADC on boards that should not have an ADC (but do)
        ReadBoolean(fp, "Disable_ADC", -1, 0, &(Config->DisableADC));
        ReadBoolean(fp, "Enable_ADC_Volt", -1, 0, &(Config->EnableADCVolt));

and finally misc.h:

        int DisableADC;
        int EnableADCVolt;

Allows the ADC to be used to read voltage on a board that does not usually have the ADC present.

Happy to sort this as a pull request if easier.

Thanks very much
Kevin

@daveake
Copy link
Collaborator

daveake commented Jul 31, 2022 via email

@KevWal
Copy link
Contributor Author

KevWal commented Aug 4, 2022

Hi, Pull request created - #46 - any issues do let me know, no rush of course.

@KevWal
Copy link
Contributor Author

KevWal commented Aug 20, 2022

Apologises Dave, I messed up the pull request and included the whole of my develop branch. Could you undo urgently, and I will redo the pull request. Sorry :(

@PiInTheSky
Copy link
Owner

Reverted.

@KevWal
Copy link
Contributor Author

KevWal commented Aug 21, 2022

Thanks Dave, I know what I did wrong, I made a branch with just the correct commits, submitted the pull request, but then carried on making commits on the same branch!

I will make a feature branch dedicated to the changes and resubmit 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants