PDA

View Full Version : HPWM at very low frequency



lerameur
- 23rd December 2010, 01:49
Hi,
The very short program works but the frequency output is extremely variable from 500Hz to 2Khz. The program should max at 512Hz..
Also the output is very noisy, any recommendation on the output ? extra capacitor ?


'//////////////////////////////////////////////////////////////////////////////////
'// 555 simulator using PIC16F88
'// Variable frequency, fixed Dutycycle
'//////////////////////////////////////////////////////////////////////////////////


'/////////////////////////
'// Define section //
'/////////////////////////


INCLUDE "modedefs.bas"
OSCCON = %01110000 '8 Mhz
DEFINE OSC 8
ANSEL = 0
CMCON = 7

DEFINE CCP1_REG PORTB 'Define output port of pulses out
DEFINE CCP1_BIT 0 'Define output port of pulses out

Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uSec

TRISA = %11111111 ' Set PORTA to all input
TRISB = %00000000 ' Set PORTB to all output

voltage_check var word
Frequency var word

Mainloop:

ADCON0.2 = 1 'Start Conversion max 1024
ADCIN 3, voltage_check 'analog pin 1 get the 10 bit result Check the battery voltage on pin PORTA.3
Frequency = voltage_check /2 'max 512Hz

HPWM 1,126,Frequency

goto Mainloop
END

mackrackit
- 23rd December 2010, 09:02
This has the ADC turned off.
ANSEL = 0
Try
ANSEL = %00001000

Acetronics2
- 23rd December 2010, 09:13
Hi, Dave

did you notice the generator will only output 489 to 512 Hz ???

... RTFM ??? :D

Yes Ken, you should read your manual, HPWM section ( or the Pic Datasheet ! )

Alain

mackrackit
- 23rd December 2010, 09:24
did you notice the generator will only output 489 to 512 Hz ???

Yup, and the OP said it was going from 500 to... So that part sounds about right. Does he want something slower?

lerameur
- 23rd December 2010, 12:24
Argrr, ya, I read the text but I skipped the table, But I need lower frequency then 489Hz, Actually I need between 10 to 300Hz, I think I am better off with what I am using now, a 555 timer.

K

Acetronics2
- 23rd December 2010, 12:41
Argrr, ya, I read the text but I skipped the table, But I need lower frequency then 489Hz, Actually I need between 10 to 300Hz, I think I am better off with what I am using now, a 555 timer.

K

you can use a PIC, but with " soft " PWM generation ... :rolleyes:

Also have a look to what the CCP module can do for you ... more than generating PWM.

in Compare mode, for example ... you easily can reach 2Hz ...;)

a Timer1 Overflow interrupt also will work fine ...

Alain

lerameur
- 9th May 2013, 08:41
HI,
I read page 83 concerning compare mode... still have no idea how you could get 2hz .
The manual says even in PWM mode we cant get lower then 5ms long witch is about 200hz...

K