libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
pwm_adc.bas File Reference

Example: generate PWM outputs and fetch them as ADC samples, draw graf. More...

#include "BBB/pruio.bi"
#include "BBB/pruio_pins.bi"
#include "fbgfx.bi"
Include dependency graph for pwm_adc.bas:

Go to the source code of this file.

Classes

class  PWM_PIN
 UDT to hold data for an output channel. More...
 

Functions

int main ()
 

Variables

VAR S_W = 0
 The screen width.
 
VAR S_H = 0
 The srceen hight.
 
VAR BPP = 0
 The bits per plain number.
 
VAR full = fb.GFX_FULLSCREEN
 Fullscreen or windowed mode.
 
VAR p = INSTR(COMMAND, "x")
 The position of the 'x' character (if any).
 
VAR w = VALINT(COMMAND)
 The required window width.
 
VAR h = VALINT(MID(COMMAND, p + 1))
 The required window hight.
 
UInt32 col [...]
 The colors for the lines (= channels). More...
 
UInt32 last [...]
 The previous data of the channels. More...
 
PWM_PIN ch [...]
 The structures for the output pins. More...
 
VAR io = NEW PruIo
 Create a PruIo structure, wakeup subsystems.
 
VAR scale = S_H / 65520
 The factor to scale values.
 
VAR x = 0
 The start x position.
 
VAR gap = 1
 The gap between x values.
 
VAR xmax = S_W - gap - 1
 The maximal x position.
 
VAR m = 0
 The mask for in-active channels.
 
VAR n = 2
 The active channel number.
 
VAR fg = RGB(0, 0, 0)
 The foreground color.
 
VAR bg = RGB(250, 250, 250)
 The background color.
 
VAR k = ASC(INKEY())
 The key code.
 
VAR neu = S_H - CUINT(.Adc->Value[i + 1] * scale)
 The new value.
 

Detailed Description

Example: generate PWM outputs and fetch them as ADC samples, draw graf.

This file contains an example on how to use libpruio to generate Pulse Width Modulated (PWM) output. Here the two channels (A + B) of an eHRPWM module and an eCAP module (in PWM) mode generate the PWM signals. The output gets measured by the ADC subsystem at channels AIN-0 to AIN-2, and shown as a line graf in a graphics windows. Find a functional description in section pwm_adc.

Licence: GPLv3, Copyright 2014-2023 by Thomas{ doT ]Freiherr[ At ]gmx[ DoT }net

Compile by: fbc -w all pwm_adc.bas

Since
0.0

Definition in file pwm_adc.bas.

Function Documentation

◆ main()

int main ( )

The main function.

Definition at line 175 of file pwm_adc.bas.

Here is the call graph for this function:

Variable Documentation

◆ ch

PWM_PIN ch[...]
Initial value:
= {
TYPE<PWM_PIN>(P9_14, 2.5, .5, @"P9_14 (A)")
, TYPE<PWM_PIN>(P9_16, 2.5, .2, @"P9_16 (B)")
, TYPE<PWM_PIN>(P9_42, 2.5, .8, @"P9_42 (C)")
}
#define P9_14
CPU ball number for pin 14 on header 9.
Definition: pruio_pins.bi:109
#define P9_16
CPU ball number for pin 16 on header 9.
Definition: pruio_pins.bi:113
#define P9_42
CPU ball number for double pin 42 on header 9 (second ball is 104)
Definition: pruio_pins.bi:163

The structures for the output pins.

Definition at line 81 of file pwm_adc.bas.

◆ col

UInt32 col[...]
Initial value:
= {
, RGBA( 0, 255, 0, 255)
, RGBA( 0, 0, 255, 255)
}

The colors for the lines (= channels).

Definition at line 50 of file pwm_adc.bas.

◆ last

UInt32 last[...]
Initial value:
= {
0
, 0
, 0
, 0
, 0
, 0
, 0
, 0
}

The previous data of the channels.

Definition at line 58 of file pwm_adc.bas.