Garrett 712120 VNT Hella 6NW 008 412 actuator.
Garrett 712120 VNT Hella 6NW 008 412 actuator.
(10-29-2009, 02:12 PM)Tymbrymi Unfortunately, it DOES care about the frequency. Not sure what its range is, but I remember it didn't work at just any old frequency. I don't think it'll work on an analog voltage either.
You could always get a better PIC That definitely sucks though. It's annoying to have to bit-bang stuff when you have a hardware peripheral that should be able to do it.
Yep! But they're on my old phone, which I won't be able to get to till tonight. I'll try and post them if I get the chance.
#include <p18cxxx.h>
#include "enc28j60.h"
#include "typedefs.h"
void init(void);
void pwm_init(void);
void isr_high(void);
void isr_low(void);
volatile BYTE pwm_duty_cycle = 128;
#define PWM_HIGH_STATE 0
#define PWM_LOW_STATE 1
/**************** INTERRUPTS ****************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void) {
_asm GOTO isr_high _endasm
}
#pragma code
#pragma code low_vector=0x18
void interrupt_at_low_vector(void) {
_asm GOTO isr_low _endasm
}
#pragma code
#pragma interrupt isr_high
void isr_high(void) {
/**High Priority ISR**/
/**Timer0 Overflow**/
//TMR0L = 32;
static BYTE pwm_num_ovrflw = 0;
TMR0L = 40;
if (pwm_num_ovrflw == pwm_duty_cycle) {
// PWM Pin Low
PORTCbits.RC5 = PWM_LOW_STATE;
}else if (pwm_num_ovrflw == 0xFF) {
pwm_num_ovrflw = 0;
// PWM Pin High
PORTCbits.RC5 = PWM_HIGH_STATE;
}
pwm_num_ovrflw++;
//Clear Interrupt Flag
INTCONbits.TMR0IF = 0;
}
#pragma interruptlow isr_low
void isr_low(void) {
/**Low Priority ISR**/
}
/************** END INTERRUPTS **************/
void main (void) {
init();
while (1) {
_asm NOP _endasm
}
}
void init (void) {
//Set Oscillator to 64MHz
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
//Set Pin 12 Output High (Pin 12 is the power source for the level shifter)
TRISBbits.TRISB5 = 0;
PORTBbits.RB5 = 1;
//Enable Interrupt Priority
RCONbits.IPEN = 1;
//Disable All Individual Interrupts
INTCON = 0;
INTCON3 = 0;
//Set All Peripherial Interrupts = Disabled & Low Priority
PIE1 = 0;
IPR1 = 0;
PIE2 = 0;
IPR2 = 0;
//Global High/Low Priority Interrupt Enable
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
// Initialize the Ethernet Module
//enc_init();
// Start PWM Output
pwm_init();
}
void pwm_init (void) {
/*
Timer0 PWM Setup
Increment at 8MHz (0.125us)
Overflow every 27.9017858us (35840Hz) (for 256 step PWM)
= Increment 223.214286x Before Overflow
-> Start Timer at 255-223 = 32
*/
// Pin 5 as Output
TRISCbits.TRISC5 = 0;
// PWM Low
PORTCbits.RC5 = PWM_LOW_STATE;
//Disable Timer0
T0CONbits.TMR0ON = 0;
// 8-Bit Timer
T0CONbits.T08BIT = 1;
// Use Instruction Clock
T0CONbits.T0CS = 0;
// 1:2 Prescaler, 8MHz
T0CONbits.PSA = 0;
T0CONbits.T0PS0 = 0;
T0CONbits.T0PS1 = 0;
T0CONbits.T0PS2 = 0;
// Enable Timer0 Overflow Interrupt
INTCONbits.TMR0IF = 0;
INTCONbits.TMR0IE = 1;
//Enable Timer
T0CONbits.TMR0ON = 1;
}
(10-29-2009, 02:12 PM)Tymbrymi Unfortunately, it DOES care about the frequency. Not sure what its range is, but I remember it didn't work at just any old frequency. I don't think it'll work on an analog voltage either.
You could always get a better PIC That definitely sucks though. It's annoying to have to bit-bang stuff when you have a hardware peripheral that should be able to do it.
Yep! But they're on my old phone, which I won't be able to get to till tonight. I'll try and post them if I get the chance.
#include <p18cxxx.h>
#include "enc28j60.h"
#include "typedefs.h"
void init(void);
void pwm_init(void);
void isr_high(void);
void isr_low(void);
volatile BYTE pwm_duty_cycle = 128;
#define PWM_HIGH_STATE 0
#define PWM_LOW_STATE 1
/**************** INTERRUPTS ****************/
#pragma code high_vector=0x08
void interrupt_at_high_vector(void) {
_asm GOTO isr_high _endasm
}
#pragma code
#pragma code low_vector=0x18
void interrupt_at_low_vector(void) {
_asm GOTO isr_low _endasm
}
#pragma code
#pragma interrupt isr_high
void isr_high(void) {
/**High Priority ISR**/
/**Timer0 Overflow**/
//TMR0L = 32;
static BYTE pwm_num_ovrflw = 0;
TMR0L = 40;
if (pwm_num_ovrflw == pwm_duty_cycle) {
// PWM Pin Low
PORTCbits.RC5 = PWM_LOW_STATE;
}else if (pwm_num_ovrflw == 0xFF) {
pwm_num_ovrflw = 0;
// PWM Pin High
PORTCbits.RC5 = PWM_HIGH_STATE;
}
pwm_num_ovrflw++;
//Clear Interrupt Flag
INTCONbits.TMR0IF = 0;
}
#pragma interruptlow isr_low
void isr_low(void) {
/**Low Priority ISR**/
}
/************** END INTERRUPTS **************/
void main (void) {
init();
while (1) {
_asm NOP _endasm
}
}
void init (void) {
//Set Oscillator to 64MHz
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
//Set Pin 12 Output High (Pin 12 is the power source for the level shifter)
TRISBbits.TRISB5 = 0;
PORTBbits.RB5 = 1;
//Enable Interrupt Priority
RCONbits.IPEN = 1;
//Disable All Individual Interrupts
INTCON = 0;
INTCON3 = 0;
//Set All Peripherial Interrupts = Disabled & Low Priority
PIE1 = 0;
IPR1 = 0;
PIE2 = 0;
IPR2 = 0;
//Global High/Low Priority Interrupt Enable
INTCONbits.GIEH = 1;
INTCONbits.GIEL = 1;
// Initialize the Ethernet Module
//enc_init();
// Start PWM Output
pwm_init();
}
void pwm_init (void) {
/*
Timer0 PWM Setup
Increment at 8MHz (0.125us)
Overflow every 27.9017858us (35840Hz) (for 256 step PWM)
= Increment 223.214286x Before Overflow
-> Start Timer at 255-223 = 32
*/
// Pin 5 as Output
TRISCbits.TRISC5 = 0;
// PWM Low
PORTCbits.RC5 = PWM_LOW_STATE;
//Disable Timer0
T0CONbits.TMR0ON = 0;
// 8-Bit Timer
T0CONbits.T08BIT = 1;
// Use Instruction Clock
T0CONbits.T0CS = 0;
// 1:2 Prescaler, 8MHz
T0CONbits.PSA = 0;
T0CONbits.T0PS0 = 0;
T0CONbits.T0PS1 = 0;
T0CONbits.T0PS2 = 0;
// Enable Timer0 Overflow Interrupt
INTCONbits.TMR0IF = 0;
INTCONbits.TMR0IE = 1;
//Enable Timer
T0CONbits.TMR0ON = 1;
}