No secret, Malc ...
PWM freq too low.
( may be also a poor quality motor too ... but you can't choose which will be used.)
Alain
No secret, Malc ...
PWM freq too low.
( may be also a poor quality motor too ... but you can't choose which will be used.)
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
I've been trying to phathom out what I need to set ANSEL to or whats wrong with the code to get this to work 100%.
Referring to my post #74, I have three PWM outputs, but when I connect pot 4 to pin 10 and the corresponding output (pin 7 RC3) the loco just shoots off at full speed with no control - Here's the code
Here's hoping someone can point e in the right directionCode:@ __CONFIG _HS_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_OFF ;ANSEL = %00010111 - dt suggested value ANSEL=%00110001 ; original CMCON=7 TRISA=%11111111 'set PORTA as all input TRISC=%00000001 'set PORTC as all output apart from RC0 DEFINE OSC 20 CLEAR DEFINE ADC_BITS 8 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3) DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "SPWM_INT.bas" ; Software PWM module DEFINE SPWM_FREQ 190 ; SPWM Frequency DEFINE SPWM_RES 255 ; SPWM Resolution DutyVars VAR BYTE[3] ; DutyCycle Variables DutyVar1 VAR DutyVars[0] ; group them in an array for easy access DutyVar2 VAR DutyVars[1] ; with FOR loops etc. DutyVar3 VAR DutyVars[2] DutyVar4 VAR DutyVars[3] ASM SPWM_LIST macro ; Define Pin's to use for SPWM SPWM_PIN PORTC, 2, _DutyVar1 ; and the associated DutyCycle variables SPWM_PIN PORTC, 5, _DutyVar2 ; Notice the underscore before variables SPWM_PIN PORTC, 4, _DutyVar3 SPWM_PIN PORTC, 3, _DutyVar4 endm SPWM_INIT SPWM_LIST ; Initialize the Pins ENDASM ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler TMR1_INT, SPWMhandler, ASM, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts ;_____________________________________________________________________________ Main: ADCIN 0, DUTYVAR1 ADCIN 1, DUTYVAR2 ADCIN 2, DUTYVAR3 ADCIN 4, DUTYVAR4 GOTO Main
Ok I think I now understand the settings for ANSEL. Reading the datasheet again
So if I wanted all analogue I set ANSEL to 11111111 - all digital 00000000ANSEL — ANALOG SELECT REGISTER (ADRESS: 91h) (PIC16F676 ONLY)
ANS7 ANS6 ANS5 ANS4 ANS3 ANS2 ANS1 ANS0
bit 7 bit 0
bit 7-0: ANS<7:0>: Analog Select between analog or digital function on pins AN<7:0>, respectively.
1 = Analog input. Pin is assigned as analog input.(1)
0 = Digital I/O. Pin is assigned to port or special function.
Ergo to set AN0, AN1, AN2 and AN4 Ansel should = 00010111, which is exactly what Darrel suggested. However when compiled with this setting the 4th output still runs at full speed with no control.
Could it be that the issue is with the declaration of the array - as it has [3] and I would assume that there are 4 channels so maybe this should be [4] ??
Looked like that was teh cause - I now have 4 working channels... just need to resolve the issue of the PIC locking on at full throttle and I'm done !
Last edited by malc-c; - 16th February 2007 at 20:47.
Boy. Try to get some sleep, and people start talking to themselves.
Looks like the guy you were talking to, helped figure a couple things out though.
Good catch on the array size. Didn't see that.
Heard the video. That's just nasty sounding.
Is it any better yet after the changes?
I know you were told to change SPWM_RES to 255, but it really should be 256 for 8-bit resolution. Maybe the cause of the "PIC locking on at full throttle". I'll play with it here too and see.
<br>
DT
After further playing.
I can't make it "Lock".
Tried all 4 channels, tried 255/256 RES.
Incidently, 255 does work better. It's not the way I thought I wrote it. But...
That way 0 is always off, and 255 is always on.
<br>
DT
Darrel,
If using an LED its hard to make it lock. I think its either related to the power supply I'm using, or some other factor within the circuit as it does it on several loco's. I have a 0.1uf spread accros the power pins of the PIC, and power rails in a bid to decouple the supply. I've also tried changing the 1K base resistor between the NPn and PIC output as I though that the driver circuit may be drawing more than the 25ma the port can take, but that made no difference
Is the PWM outout a square wave, sawtooth or just spikes that are increased in frequency? I would like to stick with PWM as there is less heat to dissapate in the circuit and it provides far better slow starts than varible voltage type controllers. Maybe I should look at using a PIC with hardware PWM, like the 16F690 ??
Bookmarks