Documentation for “Zerocat Chipflasher” as of Wed, 01 Jan 2025 22:07:31 +0100
Repository:
Version: v2.1.0-0-850cd7bce
Branch: master

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

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

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

Copyright (C) 2020, 2021, 2022  Kai Mertens 

File ADC-monitor.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-monitor" Interface:

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

Program:  280 Longs
Variable: 11 Longs


# Loaded Objects

* Load pin configuration object.


# Constants

* Monitor Settings for Vcc_SPI @ ADC_IN

  Nominal Voltage is needed for internal calculations.
  MV_VCC          --- Vcc value in Millivolts

  Once SPI bus power is suspended,
  turn back and resume when a good level is established again.
  MV_GOOD         --- low limit in Millivolts for good

  Driving an SPI chip should be done within specs,
  that is with 2.7 to 3.3 Volts.
  MV_ALERT        --- low limit in Millivolts for alert

  Flashing a ThinkPad T60/MX still works fine around 2350mV.
  Let us set this voltage as critical limit.
  Update: Readout without Vcc_SPI suspend fails on T60/MX25L1605D,
  letM-bM-^@M-^?s rise critical threshold to err out after a while.
  MV_CRITICAL     --- low limit in Millivolts for critical

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



# Globals

* stack[]           --- provide shared memory


# Functions

______________________________________________
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  get_range : 

 Get range value.

__________________
PUB  get_result : 

 Get calibrated ADC result.

_____________________
PUB  get_flag_good : 

 Get value of flag_good, TRUE or FALSE.

______________________
PUB  get_flag_alert : 

 Get value of flag_alert, TRUE or FALSE.

_________________________
PUB  get_flag_critical : 

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

___________________
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[10] --- calculated, limiting ADC value for good
  * stack[9]  --- calculated, limiting ADC value for alert
  * stack[8]  --- calculated, limiting ADC value for critical
  * stack[7]  --- calculated range value
  * stack[6]  --- value of flags, TRUE or FALSE
  * stack[5]  --- control pin_good, direction register value
  * stack[4]  --- control pin_alert, direction register value
  * stack[3]  --- control pin_crit, direction register value
  * stack[2]  --- pin_good
  * stack[1]  --- pin_alert
  * stack[0]  --- pin_crit / calibrated result


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

 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


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

  Named registers, reserved space, not initialized

  p_stack           --- stack base address
  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[2], direction value for critical pin
  p_pinctrl_alert   --- pointer into stack, will point to stack[3], direction value for alert pin
  p_pinctrl_good    --- pointer into stack, will point to stack[4], direction value for good pin
  p_flags           --- pointer into stack, will point to stack[5]
  p_range           --- pointer into stack, will point to stack[6]
  p_result_crit     --- pointer into stack, will point to stack[7]
  p_result_alert    --- pointer into stack, will point to stack[8]
  p_result_good     --- pointer into stack, will point to stack[9]
  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 ***