Documentation for “Zerocat Chipflasher” as of Sat, 29 Mar 2025 14:42:00 +0100
Repository:
Version: v2.1.6-0-c57b46eb4
Branch: master

../../firmware2/src/ADC.spin.flashrom.html

Propeller Spin/PASM Compiler 'OpenSpin' (c)2012-2016 Parallax Inc. DBA Parallax Semiconductor.
Version 1.00.78
Compiling...
../../firmware2/src/ADC.spin
Done.
Program size is 1172 bytes

______________________________________________________________________________
********************************************************* File starts here ***
Zerocat Chipflasher --- Flash free firmware, kick the Management Engine.

Copyright (C) 2020, 2021, 2022, 2025  Kai Mertens 

File ADC.spin --- Watch sigma-delta Analog to Digital Conversion.

This file is part of Zerocat Chipflasher.

See end of file for terms of use.

******************************************************************************


# Interface Description

Object "../../firmware2/src/ADC" Interface:

PUB  init
PUB  go(vboard, pin_crit, pin_alert, pin_good) : 
PUB  stop
PUB  get_range : 
PUB  get_result : 
PUB  get_voltage : 
PUB  set_voltage_min_peak
PUB  get_voltage_min_peak : 
PUB  get_flag_critical : 
PUB  get_flag_alert : 
PUB  get_flag_good : 
PUB  critical(ctrl)
PUB  alert(ctrl)
PUB  good(ctrl)
PUB  get_result_critical : 
PUB  get_result_alert : 
PUB  get_result_good : 

Program:  289 Longs
Variable: 14 Longs


# Loaded Objects



# Constants

## Monitor Settings for Vcc_SPI @ ADC_IN

* MV_VCC          --- Vcc value in Millivolts, set to 3300mV

    Nominal Voltage is needed for internal calculations.

* MV_GOOD         --- low limit in Millivolts for good, set to 3225mV

    Once SPI power is suspended,
    turn back and resume when a good level is established again.

* MV_ALERT        --- low limit in Millivolts for alert, set to 2700mV

    Driving an SPI chip should be done within specs,
    that is with 2.7 to 3.3 Volts.

* MV_CRITICAL     --- low limit in Millivolts for critical, set to 2400mV

    Critical threshold is set to 2400mV, because operating a
    full-range SPI would definitely be unreliable with lower voltages.
    Furthermore, stress of flasher voltage regulators is to be expected.
    However, emergency action of the firmware has not been tested well enough, yet.

* Bit definitions
* ADC Pins, Ranges, Timings

    - ADC_IN          --- counter input pin for sigma-delta ADC
    - ADC_CALIB       --- calibration pin, providing 0V and Vcc
    - ADC_OUT         --- counter feedback pin for sigma-delta ADC
    - ADC_STARTTIME   --- initial time over which to accumulate counts, power-of-two
    - ADC_RANGEINIT   --- initial range
    - ADC_CHARGETIME  --- allow caps to charge/discharge

* Job control
* Sizes


# Globals

* stack[]           --- provide shared memory


# Functions

_________
PUB  init

 Initialize memory.

_________________________________________________
PUB  go(vboard, pin_crit, pin_alert, pin_good) : 

 Launch PASM code into new cog: MonitorADC_PASM

 Pin pin_crit will be switched on if ADC result trips below limiting
 critical value. Set pin_crit to TRUE if no pin in use.

 Pin pin_alert will be switched on if ADC result trips below limiting
 alert value. Set pin_alert to TRUE if no pin in use.

 Pin pin_good will be switched off if ADC result trips below limiting
 good value. Set pin_good to TRUE if no pin in use.

 On startup, driving the pins is disabled.
 Drivers are to set explicitly via critical(), alert() and good()


_________
PUB  stop

 Stop service cog.

_________________
PUB  get_range : 

 Get range value.

__________________
PUB  get_result : 

 Get calibrated ADC result.

___________________
PUB  get_voltage : 

 Get calibrated ADC voltage im mV.

_________________________
PUB  set_voltage_min_peak

 Set peak minimal voltage to current voltage,
 then continue with monitor.

____________________________
PUB  get_voltage_min_peak : 

 Get calibrated ADC result, peak minimal.

_________________________
PUB  get_flag_critical : 

 Get value of flag_crit, TRUE or FALSE.
 TRUE requires immediate action!

______________________
PUB  get_flag_alert : 

 Get value of flag_alert, TRUE or FALSE.

_____________________
PUB  get_flag_good : 

 Get value of flag_good, TRUE or FALSE.

___________________
PUB  critical(ctrl)

 Enable (TRUE) or disable (FALSE) pin_crit driver.
 FALSE will set the pin tristate.

________________
PUB  alert(ctrl)

 Enable (TRUE) or disable (FALSE) pin_alert driver.
 FALSE will set the pin tristate.

_______________
PUB  good(ctrl)

 Enable (TRUE) or disable (FALSE) pin_good driver.
 FALSE will set the pin tristate.

___________________________
PUB  get_result_critical : 

 Get value of limiting ADC value for critical action.

________________________
PUB  get_result_alert : 

 Get limiting ADC value for alert action.

_______________________
PUB  get_result_good : 

 Get limiting ADC value for good action.


# Data

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

  MonitorADC_PASM --- PASM code entry

  This code is inspired by Parallax Manuals and Application Notes:

  * AN001-P8X32ACounters-v2.0.pdf: figure 14
  * AN008-SigmaDeltaADC-v1.0.pdf: figure 6, listing2
  * P8X32A-Web-PropellerManual-v1.2.pdf: Math Samples

  Parameter:

  * stack[12] --- calculated minimal value, peak
  * stack[11] --- calculated, limiting ADC value for good
  * stack[10]  --- calculated, limiting ADC value for alert
  * stack[9]  --- calculated, limiting ADC value for critical
  * stack[8]  --- calculated range value
  * stack[7]  --- value of flags, TRUE or FALSE
  * stack[6]  --- control pin_good, direction register value
  * stack[5]  --- control pin_alert, direction register value
  * stack[4]  --- control pin_crit, direction register value
  * stack[3]  --- pin_good
  * stack[2]  --- pin_alert
  * stack[1]  --- pin_crit / calibrated result
  * stack[0]  --- job flag


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 _get_range --- calibrate

 * result is stored in range
 * and in shared array

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 _set_limits

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 adc --- get raw ADC value


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 caps --- Wait for t_charge to pass, allow capacitors to charge/discharge


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 crit_enable --- update output latch, enable direction register


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 crit_disable --- clear direction register, set pin tristate


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 alert_enable --- update output latch, enable direction register


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 alert_disable --- clear direction register, set pin tristate


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 good_enable --- update output latch, enable direction register


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 good_disable --- clear direction register, set pin tristate


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Multiply

 * multiplies x[15..0] by y[15..0]
 * y[31..16] must be zero
 * returns product in y[31..0]


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

 Divide

 * divides x[31..0] by y[15..0]
 * y[16] must be zero
 * returns quotient in x[15..0]
 * returns remainder in x[31..16]


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

  Named registers, initialized

  mask_ADC_OUT
  mask_ADC_CALIB
  mask_quot
  range             --- intended ADC range, will be trimmed during calibration
  t_start           --- initial acquisition time, power-of-two
  t_charge
  val_VCC
  val_mv_crit
  val_mv_alert
  val_mv_good
  val_true
  val_false
  result_min_peak


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

  Named registers, reserved space, not initialized

  _job              --- Job flag
  p                 --- pointer into stack
  p_result          --- will point to stack[0], calibrated ADC result
  p_pin_crit        --- will point to stack[0], critical pin
  p_pin_alert       --- will point to stack[1], alert pin
  p_pin_good        --- will point to stack[2], good pin
  p_pinctrl_crit    --- pointer into stack, will point to stack[3], direction value for critical pin
  p_pinctrl_alert   --- pointer into stack, will point to stack[4], direction value for alert pin
  p_pinctrl_good    --- pointer into stack, will point to stack[5], direction value for good pin
  p_flags           --- pointer into stack, will point to stack[6]
  p_range           --- pointer into stack, will point to stack[7]
  p_result_crit     --- pointer into stack, will point to stack[8]
  p_result_alert    --- pointer into stack, will point to stack[9]
  p_result_good     --- pointer into stack, will point to stack[10]
  p_result_min_peak --- pointer into stack, will point to stack[11]
  t_next            --- time variable, used for waitcnt
  t_delta           --- delta acquisition time, used during calibration
  t_acquisition     --- acquisition time, trimmed during calibration
  acc               --- general-purpose register
  lowpoint          --- ADC raw value for low endpoint
  result_crit       --- trigger value for critical flag
  result_alert      --- trigger value for alert pin
  result_good       --- trigger value for alert pin
  x                 --- used by math operations / general-purpose register
  y                 --- used by math operations
  bits              --- used by math operations




******************************************************************************
Terms of Use:

Zerocat Chipflasher is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

Zerocat Chipflasher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License along
with Zerocat Chipflasher.  If not, see <http://www.gnu.org/licenses/>.

************************************************************** End of File ***