<<Previous

Next>>

HIGH

HIGH Pin

Make the specified Pin high. Pin is automatically made an output. Pin may be a constant, 0-15, or a variable that contains a number 0-15 (e.g. B0) or a pin name (e.g. PORTA.0).

	HIGH 0			' Make Pin0 an output and set it high (~5 volts)
	HIGH PORTA.0		' Make PORTA, pin 0 an output and set it high (~5 volts)

led	var	PORTB.0		' Define LED pin
	HIGH led		' Make LED pin an output and set it high (~5 volts)	

Alternatively, if the pin is already an output, a much quicker and shorter way (from a generated code standpoint) to set it high would be:

	PORTB.0 = 1		' Set PORTB pin 0 high

HPWM

HPWM Channel,Dutycycle,Frequency

Outputs a pulse width modulated pulse train using PWM hardware available on some PICmicro MCUs. It can run continuously in the background while the program is executing other instructions.

Channel specifies which hardware PWM channel to use. Some devices have 1, 2 or 3 PWM channels. On devices with 2 channels, the Frequency must be the same on both channels.

Channel specifies which hardware PWM channel to use. Some devices have 1, 2 or 3 PWM Channels. The Microchip data sheet for the particular device shows the fixed hardware pin for each Channel. For example, for a PIC16F877, Channel 1 is CCP1 which is pin PORTC.2. Channel 2 is CCP2 which is pin PORTC.1.

Some devices, such as the PIC18C452, have alternate pins that may be used for HPWM. The following DEFINEs allow using these pins:

DEFINE CCP1_REG PORTC ‘ Hpwm 1 pin port
DEFINE CCP1_BIT 2     ‘ Hpwm 1 pin bit
DEFINE CCP2_REG PORTC ‘ Hpwm 2 pin port
DEFINE CCP2_BIT 1     ‘ Hpwm 2 pin bit

Dutycycle specifies the on/off (high/low) ratio of the signal. It ranges from 0 to 255, where 0 is off (low all the time) and 255 is on (high) all the time. A value of 127 gives a 50% duty cycle (square wave).

Frequency is the desired frequency of the PWM signal. Not all frequencies are available at all oscillator settings. The highest frequency at any oscillator speed is 32767Hz. The lowest usable HPWM Frequency at each oscillator setting is shown in the following table:

OSC 14-bit core and 18Cxxx 17Cxxx
4MHz 245Hz 3907Hz
8MHz 489Hz 7813Hz
10MHz 611Hz 9766Hz
12MHz 733Hz 11719Hz
16MHz 977Hz 15625Hz
20MHz 1221Hz 19531Hz
24MHz 1465Hz 23438Hz
33MHz 2015Hz 32227Hz
40MHz 2442Hz na

The following DEFINEs specify which timer, 1 or 2, to use with PWM channel 2 and PWM channel 3 for the PIC17C7xx devices. The default is timer 1 if no DEFINE is specified.

DEFINE HPWM2_TIMER 1 	'Hpwm 2 timer select
DEFINE HPWM3_TIMER 1 	'Hpwm 3 timer select

HPWM 1,127,1000 	' Send a 50% duty cycle PWM signal at 1kHz

HPWM 1,64,2000 		' Send a 25% duty cycle PWM signal at 2kHz
<<Previous

Next>>